[Debconf-video-commits] r334 - package/branches/pycon09/src
benh at alioth.debian.org
benh at alioth.debian.org
Thu Mar 19 00:23:14 UTC 2009
Author: benh
Date: 2009-03-19 00:23:14 +0000 (Thu, 19 Mar 2009)
New Revision: 334
Modified:
package/branches/pycon09/src/pycon-import-talks
Log:
Rename get_events to get_events_vobject.
Split munging out of main into a new get_events function.
Remove redundant initial BEGIN which triggers a warning.
Modified: package/branches/pycon09/src/pycon-import-talks
===================================================================
--- package/branches/pycon09/src/pycon-import-talks 2009-03-19 00:00:41 UTC (rev 333)
+++ package/branches/pycon09/src/pycon-import-talks 2009-03-19 00:23:14 UTC (rev 334)
@@ -22,20 +22,20 @@
password=config.get('DATABASE_PASSWORD'))
return _connection.cursor()
-def get_events(url):
+def get_events_vobject(url):
data = urllib2.urlopen(url).read()
for node in vobject.readOne(data).getChildren():
if node.name == 'VEVENT':
yield dict((attr.name, attr.value) for attr in node.getChildren())
-def main(pretend=False):
+def get_events():
local_tz = pytz.timezone('America/Chicago')
- for event in get_events(SOURCE_URL):
- values = {'conference_id': 1}
+ for vevent in get_events_vobject(SOURCE_URL):
+ event = {'conference_id': 1}
# Drop id number found in some summaries.
- values['title'] = re.sub(r' \(#\d+\)$', '', event['SUMMARY'])
+ event['title'] = re.sub(r' \(#\d+\)$', '', vevent['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
@@ -45,38 +45,41 @@
r'\d+min [^\n]*\n'
r'(?:categories: [^\n]*\n)?'
r'(.*)',
- event['DESCRIPTION'])
+ vevent['DESCRIPTION'])
if not match:
- print 'INFO: Ignoring', values['title']
+ print 'INFO: Ignoring', event['title']
continue
- values['conference_room'] = match.group(1)
- values['description'] = match.group(2)
+ event['conference_room'] = match.group(1)
+ event['description'] = match.group(2)
- values['source_url'] = SOURCE_URL + '#' + event['UID']
+ event['source_url'] = SOURCE_URL + '#' + vevent['UID']
- values['start_time'] = event['DTSTART'].astimezone(local_tz).isoformat(' ')
- values['duration'] = '%d SECONDS' % (event['DTEND'] - event['DTSTART']).seconds
+ event['start_time'] = vevent['DTSTART'].astimezone(local_tz).isoformat(' ')
+ event['duration'] = '%d SECONDS' % (vevent['DTEND'] - vevent['DTSTART']).seconds
- cur = get_cursor()
- cur.execute('BEGIN')
+ yield event
+def main(pretend=False):
+ cur = get_cursor()
+
+ for event in get_events():
# Insert room if necessary
cur.execute('SELECT COUNT(*) FROM conference_room'
' WHERE conference_room=%(conference_room)s',
- values)
+ event)
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)
+ event)
# Insert/update event
cur.execute('SELECT event_id FROM event WHERE source_url=%(source_url)s',
- values)
+ event)
if pretend:
pass
row = cur.fetchone()
if row:
- values['event_id'] = row[0]
+ event['event_id'] = row[0]
cur.execute('UPDATE event SET'
' source_url=%(source_url)s,'
' conference_room=%(conference_room)s,'
@@ -85,7 +88,7 @@
' start_time=%(start_time)s,'
' duration=%(duration)s'
' WHERE event_id=%(event_id)d',
- values)
+ event)
else:
cur.execute('INSERT INTO event(source_url, conference_id,'
' conference_room, title, description,'
@@ -95,9 +98,10 @@
' %(description)s, '
' %(start_time)s,'
' %(duration)s)',
- values)
+ event)
cur.execute('COMMIT')
+ cur.execute('BEGIN')
if __name__ == '__main__':
try:
More information about the Debconf-video-commits
mailing list