[Debconf-video-commits] r139 - package/trunk/src

benh at alioth.debian.org benh at alioth.debian.org
Mon Aug 4 00:10:22 UTC 2008


Author: benh
Date: 2008-08-04 00:10:20 +0000 (Mon, 04 Aug 2008)
New Revision: 139

Added:
   package/trunk/src/dc-make-rss
Log:
Added script to generate an RSS feed of published videos.


Added: package/trunk/src/dc-make-rss
===================================================================
--- package/trunk/src/dc-make-rss	                        (rev 0)
+++ package/trunk/src/dc-make-rss	2008-08-04 00:10:20 UTC (rev 139)
@@ -0,0 +1,122 @@
+#!/usr/bin/python
+
+import mx.DateTime
+import os
+import os.path
+import pgdb
+import re
+import sys
+
+# metadata
+author = 'DebConf video team'
+licence = 'DebConf video licence; http://meetings-archive.debian.net/pub/debian-meetings/LICENCE'
+
+format_abbr = 'low' # format to link to
+#video_base_url = 'http://meetings-archive.debian.net/pub/debian-meetings/2007/debconf7/'
+#info_url_format = 'https://penta.debconf.org/~joerg/events/%(event_id)d.en.html'
+video_base_url = 'http://meetings-archive.debian.net/pub/debian-meetings/2008/debconf8/'
+info_url_format = 'https://penta.debconf.org/dc8_schedule/events/%(event_id)d.en.html'
+
+time_format = '%a, %d %b %Y %H:%M:%S GMT'
+
+def esc_content(s):
+    return s.replace('&', '&amp;').replace('<', '&lt;')
+
+def esc_attr(s):
+    return s.replace('&', '&amp;').replace('>', '&gt;').replace("'", '&quot;')
+
+def timestamp(s):
+    return mx.DateTime.strptime(s, '%Y-%m-%d %H:%M:%S')
+
+def interval(s):
+    return mx.DateTime.TimeDelta(*[float(part) for part in s.split(':')])
+
+def main():
+    conn = pgdb.connect(dsn=config['DATABASE_DSN'],
+                        user=config.get('DATABASE_USER'),
+                        password=config.get('DATABASE_PASSWORD'))
+    cur = conn.cursor()
+
+    conference_title = config['CONFERENCE_NAME']
+    cur.execute('SELECT conference_id, homepage, timezone FROM conference'
+                ' WHERE title = %(title)s',
+                {'title': conference_title})
+    conference_id, homepage, timezone = cur.fetchone()
+    os.environ['TZ'] = timezone
+
+    cur.execute("SELECT id, filename_extension FROM video_target_format"
+                " WHERE target_format_abbr = %(format_abbr)s",
+                {'format_abbr': format_abbr})
+    format_id, format_ext = cur.fetchone()
+
+    print "<?xml version='1.0'?>"
+    print "<rss version='2.0' xmlns:media='http://search.yahoo.com/mrss/'>"
+    print "<channel>"
+
+    print "<title>%s</title>" % esc_content(conference_title)
+    print "<link>%s</link>" % esc_content(homepage)
+    print "<description>%s</description>" % esc_content(conference_title)
+    print "<language>en</language>"
+    print "<copyright>Copyright %s. Licence: %s</copyright>" % (esc_content(author), esc_content(licence))
+    print "<generator>dc-make-rss</generator>"
+
+    cur.execute("""
+SELECT published_time, video_event_recording.start_time,
+       video_event_recording.end_time, event_recording_base_name,
+       event.event_id, title, description
+FROM
+((((video_target_file JOIN video_event_recording
+    ON video_target_file.event_recording_id = video_event_recording.id)
+   JOIN event
+   ON video_event_recording.event_id = event.event_id)
+  JOIN video_recording
+  ON video_event_recording.recording_id = video_recording.id)
+ JOIN video_file_status
+ ON video_target_file.file_status_id = video_file_status.id)
+WHERE video_target_file.target_format_id = %(format_id)d
+      AND published_time IS NOT NULL
+ORDER BY published_time DESC
+""",
+                {'format_id': format_id})
+    for (published_time, start_time, end_time, base_name,
+         event_id, title, event_desc) in cur.fetchall():
+        # Convert string date-times back to proper types
+        published_time = timestamp(published_time)
+        start_time = interval(start_time)
+        end_time = interval(end_time)
+
+        info_url = info_url_format % {'conference_id': conference_id,
+                                      'event_id': event_id}
+        video_url = (video_base_url + format_abbr + '/'
+                     + base_name + format_ext)
+        if event_desc:
+            description = ("<p>%s</p>"
+                           % esc_content(event_desc).replace('\n', '<br/>'))
+        else:
+            description = ''
+        description += ("<p><a href='%s'>Full event details</a></p>"
+                        % esc_attr(info_url))
+
+        print """\
+<item>
+        <title>%s</title>
+        <link>%s</link>
+        <description>%s</description>
+        <pubDate>%s</pubDate>
+	<media:content url='%s' medium='video' isDefault='true' duration='%d'/>
+        <guid>%s</guid>
+</item>""" % (esc_content(title),
+              esc_content(video_url),
+              esc_content(description),
+              published_time.strftime(time_format),
+              esc_attr(video_url), (end_time - start_time).seconds,
+              esc_content(video_url))
+
+    print "</channel>"
+    print "</rss>"
+
+if __name__ == '__main__':
+    sys.path.insert(0, '/usr/share/debconf-video-store')
+    import shellconfig
+    config = shellconfig.read_file('/etc/default/debconf-video')
+    main()


Property changes on: package/trunk/src/dc-make-rss
___________________________________________________________________
Name: svn:executable
   + *




More information about the Debconf-video-commits mailing list