changeset 5:bfd47f55d85b

add the updated date of the feed
author Dirk Olmes <dirk@xanthippe.ping.de>
date Mon, 26 Apr 2010 20:46:37 +0200
parents e0199f383442
children 87317ba41816
files FeedEntry.py FeedUpdater.py Mapping.py feedupdate-main.py
diffstat 4 files changed, 20 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/FeedEntry.py	Mon Apr 26 19:33:07 2010 +0200
+++ b/FeedEntry.py	Mon Apr 26 20:46:37 2010 +0200
@@ -5,11 +5,8 @@
         result = session.query(FeedEntry).filter(FeedEntry.id == id)
         return result.first()
 
-    def __init__(self, id, url, title, summary):
-        self.id = id
-        self.url = url
-        self.title = title
-        self.summary = summary
+    def __init__(self):
+        pass
 
     def __repr__(self):
         return "<FeedEntry (%d) %s>" % (self.pk, self.link)
--- a/FeedUpdater.py	Mon Apr 26 19:33:07 2010 +0200
+++ b/FeedUpdater.py	Mon Apr 26 20:46:37 2010 +0200
@@ -1,4 +1,5 @@
 
+from datetime import datetime
 from Feed import Feed
 from FeedEntry import FeedEntry
 import feedparser
@@ -25,6 +26,11 @@
             self.createFeedEntry(entry)
             
     def createFeedEntry(self, entry):
-        newEntry = FeedEntry(id=entry.id, url=entry.link, title=entry.title, summary=entry.summary)
-        newEntry.feed = self.feed
-        self.session.add(newEntry)
+        new = FeedEntry()
+        new.id = entry.id
+        new.link = entry.link
+        new.title = entry.title
+        new.updated = datetime(*entry.updated_parsed[:6])
+        new.summary = entry.summary
+        new.feed = self.feed
+        self.session.add(new)
--- a/Mapping.py	Mon Apr 26 19:33:07 2010 +0200
+++ b/Mapping.py	Mon Apr 26 20:46:37 2010 +0200
@@ -2,6 +2,7 @@
 from Feed import Feed
 from FeedEntry import FeedEntry
 from sqlalchemy import Column
+from sqlalchemy import DateTime
 from sqlalchemy import ForeignKey
 from sqlalchemy import Integer
 from sqlalchemy import MetaData
@@ -22,9 +23,10 @@
     feedEntryTable = Table("feed_entry", metadata,
         Column("pk", Integer, primary_key=True),
         Column("id", String(255), nullable=False),
-        Column("url", String(255), nullable=False),
+        Column("link", String(255), nullable=False),
         Column("title", String, nullable=False),
         Column("summary", String, nullable=False),
+        Column("updated", DateTime),
         Column("feed_id", Integer, ForeignKey("feed.pk"))
     )
 
--- a/feedupdate-main.py	Mon Apr 26 19:33:07 2010 +0200
+++ b/feedupdate-main.py	Mon Apr 26 20:46:37 2010 +0200
@@ -17,9 +17,10 @@
     return parser.get("database", "url")
 
 def createFeed(session):
-    newFeed = Feed("Joel on Software", "http://www.joelonsoftware.com/rss.xml")
-    session.add(newFeed)
-    session.commit()
+    if len(session.query(Feed).all()) == 0:
+        newFeed = Feed("Joel on Software", "http://www.joelonsoftware.com/rss.xml")
+        session.add(newFeed)
+        session.commit()
 
 def listFeeds(session):
     allFeeds = session.query(Feed)
@@ -36,5 +37,5 @@
     session = SessionMaker()
     
     #createFeed(session)
-    updateAllFeeds(session)
-    #listFeeds(session)
+    #updateAllFeeds(session)
+    listFeeds(session)