Moved data handling to a separate class.
[piranha.git] / PiranhaData.py
blob992f6ce2850cc5e6cf231f1c39082610247c5d03
2 import feedparser, sqlite3
4 class PiranhaData:
5 def __init__( self, cursor ):
6 self.category = {}
7 self.feed = {}
8 self.entry = {}
9 self.tag = {}
11 for row in cursor.execute( "select * from category" ):
12 self.category[ row["id"] ] = { "id": row["id"], "name": row["name"], "parent": row["parent"], "feeds": [] }
14 for row in cursor.execute( "select * from tag" ):
15 self.tag[ row["id"] ] = { "id": row["id"], "name": row["name"], "entries": [] }
17 for row in cursor.execute( "select * from feed" ):
18 self.feed[ row["id"] ] = { "id": row["id"], "title": row["title"], "entries": [] }
19 self.category[ row["category"] ]["feeds"].append( row["id"] )
21 for row in cursor.execute( "select id, feed, sha1, status, stamp, title, author from entry" ):
22 self.entry[ row["id"] ] = { "id": row["id"], "status": row["status"], "stamp": row["stamp"], "title": row["title"], "author": row["author"], "content": "" }
23 self.feed[ row["feed"] ]["entries"].append( row["id"] )
25 for row in cursor.execute( "select * from tagged" ):
26 self.tag[ row["tag"] ]["entries"].append( row["entry"] )
27 #end __init__
29 #end PiranhaData