[Debconf-video-commits] r330 - in package/branches/pycon09: debian src

benh at alioth.debian.org benh at alioth.debian.org
Tue Mar 17 03:07:37 UTC 2009


Author: benh
Date: 2009-03-17 03:07:37 +0000 (Tue, 17 Mar 2009)
New Revision: 330

Modified:
   package/branches/pycon09/debian/control
   package/branches/pycon09/src/pycon-import-talks
Log:
Finish talk importer.
Add python-tz dependency for time conversion.


Modified: package/branches/pycon09/debian/control
===================================================================
--- package/branches/pycon09/debian/control	2009-03-17 02:47:39 UTC (rev 329)
+++ package/branches/pycon09/debian/control	2009-03-17 03:07:37 UTC (rev 330)
@@ -23,5 +23,5 @@
 
 Package: debconf-video-store
 Architecture: all
-Depends: dvsink, python2.4, python2.4-pygresql, python-vobject, debconf-video-common
+Depends: dvsink, python2.4, python2.4-pygresql, python-tz, python-vobject, debconf-video-common
 Description: DebConf video storage scripts

Modified: package/branches/pycon09/src/pycon-import-talks
===================================================================
--- package/branches/pycon09/src/pycon-import-talks	2009-03-17 02:47:39 UTC (rev 329)
+++ package/branches/pycon09/src/pycon-import-talks	2009-03-17 03:07:37 UTC (rev 330)
@@ -2,12 +2,24 @@
 
 # Import talks from public schedule in ICS format
 
+import os
 import pgdb
+import pytz
 import re
 import sys
 import urllib2
 import vobject
 
+_connection = None
+
+def get_cursor():
+    global _connection
+    if not _connection:
+        _connection = pgdb.connect(dsn=config['DATABASE_DSN'],
+                                   user=config.get('DATABASE_USER'),
+                                   password=config.get('DATABASE_PASSWORD'))
+    return _connection.cursor()
+
 def get_events(url):
     data = urllib2.urlopen(url).read()
     for node in vobject.readOne(data).getChildren():
@@ -15,9 +27,13 @@
             yield dict((attr.name, attr.value) for attr in node.getChildren())
 
 def main(pretend=False):
+    local_tz = pytz.timezone('America/Chicago')
+
     for event in get_events('http://us.pycon.org/2009/conference/schedule/ical/'):
+        values = {'conference_id': 1}
+
         # Drop id number found in some summaries.
-        title = re.sub(r' \(#\d+\)$', '', event['SUMMARY'])
+        values['title'] = re.sub(r' \(#\d+\)$', '', event['SUMMARY'])
 
         # Drop metadata at top of description, but hold onto the room name.
         # Drop events which don't have this metadata, as they are such
@@ -29,19 +45,56 @@
                          r'(.*)',
                          event['DESCRIPTION'])
         if not match:
-            print 'INFO: Ignoring', title
+            print 'INFO: Ignoring', values['title']
             continue
-        room_name, description = match.group(1, 2)
+        values['conference_room'] = match.group(1)
+        values['description'] = match.group(2)
 
         match = re.match(r'event_E(\d+)@pycon\.org$', event['UID'])
-        event_id = int(match.group(1))
-        start_time = event['DTSTART']
-        duration = event['DTEND'] - start_time
+        values['event_id'] = int(match.group(1))
 
-        # TODO: Insert room in conference_room table if not present
-        # TODO: Insert/update event ine vent table
-        print event_id, title, description[:20], room_name, start_time, duration
+        values['start_time'] = event['DTSTART'].astimezone(local_tz).isoformat(' ')
+        values['duration'] = '%d SECONDS' % (event['DTEND'] - event['DTSTART']).seconds
 
+        cur = get_cursor()
+        cur.execute('BEGIN')
+
+        # Insert room if necessary
+        cur.execute('SELECT COUNT(*) FROM conference_room'
+                    ' WHERE conference_room=%(conference_room)s',
+                    values)
+        if not pretend and not cur.fetchone()[0]:
+            cur.execute('INSERT INTO conference_room(conference_id, conference_room)'
+                        ' VALUES (%(conference_id)d, %(conference_room)s)',
+                        values)
+
+        # Insert/update event
+        cur.execute('SELECT COUNT(*) FROM event WHERE event_id=%(event_id)d',
+                    values)
+        if pretend:
+            pass
+        elif cur.fetchone()[0]:
+            cur.execute('UPDATE event SET'
+                        ' conference_room=%(conference_room)s,'
+                        ' title=%(title)s,'
+                        ' description=%(description)s,'
+                        ' start_time=%(start_time)s,'
+                        ' duration=%(duration)s'
+                        ' WHERE event_id=%(event_id)d',
+                        values)
+        else:
+            cur.execute('INSERT INTO event(event_id, conference_id,'
+                        '                  conference_room, title, description,'
+                        '                  start_time, duration)'
+                        ' VALUES(%(event_id)d, %(conference_id)d,'
+                        '        %(conference_room)s, %(title)s,'
+                        '        %(description)s, '
+                        '        %(start_time)s,'
+                        '        %(duration)s)',
+                        values)
+
+        cur.execute('COMMIT')
+
 if __name__ == '__main__':
     try:
         sys.path.insert(0, '/usr/share/debconf-video-store')


Property changes on: package/branches/pycon09/src/pycon-import-talks
___________________________________________________________________
Name: svn:executable
   + *




More information about the Debconf-video-commits mailing list