]> git.decadent.org.uk Git - dak.git/blobdiff - queue_rss.py
use different pubDate if going in or out
[dak.git] / queue_rss.py
index 9ca66abbe435ad9654c64a37477bc029bdf10f2e..c99bd6cc506e609a4a84b161f4195876cb83faee 100755 (executable)
@@ -12,9 +12,12 @@ import sys
 import encodings.ascii
 from email.Parser import HeaderParser
 from optparse import OptionParser
+from datetime import datetime
 
 import PyRSS2Gen
 
+from debian_bundle.deb822 import Changes
+
 inrss_filename = "changes_in.rss"
 outrss_filename = "changes_out.rss"
 db_filename = "status.db"
@@ -48,7 +51,7 @@ class Status:
 def utf2ascii(src):
     """ Return an ASCII encoded copy of the input UTF-8 string """
     try:
-        res = unicode(src, 'utf-8').encode('ascii', 'replace') 
+        res = unicode(src, 'utf-8').encode('ascii', 'replace')
     except UnicodeDecodeError:
         res = None
     return res
@@ -57,7 +60,7 @@ def purge_old_items(feed, max):
     """ Purge RSSItem from feed, no more than max. """
     if feed.items is None or len(feed.items) == 0:
         return False
-    
+
     feed.items = feed.items[:max]
     return True
 
@@ -66,12 +69,7 @@ def parse_changes(fname):
 
     Return {fname: parsed} """
 
-    p = HeaderParser()
-
-    try:
-        m = p.parse(open(fname), True)
-    except IOError:
-        sys.stderr.write("Unable to parse %s\n" % fname)
+    m = Changes(open(fname))
 
     wanted_fields = set(['Source', 'Version', 'Architecture', 'Distribution',
                          'Date', 'Maintainer', 'Description', 'Changes'])
@@ -104,9 +102,11 @@ def add_rss_item(status, msg, direction):
     if direction == "in":
         feed = status.feed_in
         title = "%s %s entered NEW" % (msg['Source'], msg['Version'])
+        pubdate = msg['Date']
     elif direction == "out":
         feed = status.feed_out
         title = "%s %s left NEW" % (msg['Source'], msg['Version'])
+        pubdate = datetime.utcnow()
     else:
         return False
 
@@ -115,9 +115,8 @@ def add_rss_item(status, msg, direction):
 
     feed.items.insert(0,
         PyRSS2Gen.RSSItem(
-            title, 
-            pubDate = msg['Date'],
-#            pubDate = now(),
+            title,
+            pubDate = pubdate,
             description = description,
             author = utf2ascii(msg['Maintainer']),
             link = "http://ftp-master.debian.org/new/%s_%s.html" % \