-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstore.py
72 lines (66 loc) · 2.03 KB
/
store.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from storm.locals import *
class Channel(object):
"Feed channel"
__storm_table__ = "Channel"
id = Int(primary=True)
title = Unicode()
link = Unicode()
description = Unicode()
# lang
# copyright
# date
# ttl
# image
def __init__(self, link, title, description):
self.title = title
self.link = link
self.description = description
class Item(object):
"Feed item"
__storm_table__ = "Item"
guid = Unicode(primary=True)
title = Unicode()
link = Unicode()
description = Unicode()
date = Int()
enclosure = Unicode()
category = Unicode()
author = Unicode()
channelId = Int()
channel = Reference(channelId, Channel.id)
def __init__(self, channel, guid, title, link, description, date,
enclosure, category, author):
self.channel = channel
self.guid = guid
self.title = title
self.link = link
self.description = description
self.date = date
self.enclosure = enclosure
self.category = category
self.author = author
def __str__(self):
return '<Item><g>%s</g>\n <t>%s</t>\n <l>%s</l>\n <d>%s</>\n <c>%s</c>\n <a>%s</a>\n</Item>' % (self.guid, self.title, self.link, self.description, self.category, self.author)
def StoreCreate(file):
db = create_database("sqlite:"+file)
# db = create_database("mysql://root:posso@localhost/newsflow")
store = Store(db)
store.execute("""CREATE TABLE IF NOT EXISTS Channel(
id INTEGER PRIMARY KEY,
link VARCHAR UNIQUE ON CONFLICT REPLACE,
title VARCHAR,
description VARCHAR
)""")
store.execute("""CREATE TABLE IF NOT EXISTS Item(
guid VARCHAR PRIMARY KEY,
title VARCHAR,
link VARCHAR,
description VARCHAR,
date INTEGER,
enclosure VARCHAR,
category VARCHAR,
author VARCHAR,
channelId INTEGER
)""")
store.execute("""CREATE INDEX IF NOT EXISTS date_idx ON Item(date)""")
return store