[Python-checkins] r42208 - sandbox/trunk/pycon/parse-sched.py

david.goodger python-checkins at python.org
Tue Jan 31 16:25:27 CET 2006


Author: david.goodger
Date: Tue Jan 31 16:25:23 2006
New Revision: 42208

Modified:
   sandbox/trunk/pycon/parse-sched.py
Log:
parameterized parse(); partially fixed plenary logic; added talk number to rendered title; whitespace

Modified: sandbox/trunk/pycon/parse-sched.py
==============================================================================
--- sandbox/trunk/pycon/parse-sched.py	(original)
+++ sandbox/trunk/pycon/parse-sched.py	Tue Jan 31 16:25:23 2006
@@ -3,7 +3,7 @@
 # Reads a page with a wiki-format table
 
 # Basic data structure of dictionary:
-#  {(year, month, day) -> [(time, duration, title)]
+#  {(year, month, day) -> [(room, time, duration, title)]
 
 import sys, optparse
 import re, string
@@ -16,18 +16,17 @@
 line_pat = re.compile('[|]{2}.*[|]{2}\s*$')
 talk_pat = re.compile('#(\d+)')
 
-def parse ():
-    lines = sys.stdin.readlines()
+def parse (lines):
     lines = map(string.strip, lines)
     d = {}
     date = None
-    
+
     for line in lines:
 	m = date_pat.match(line)
 	if m:
 	    date = [int(value) for value in m.group(1,2,3)]
             date = tuple(date)
-			
+
 	m = line_pat.match(line)
 	if m:
 	    if date is None:
@@ -71,7 +70,7 @@
     L[1] = '%02i:%02i' % (hour, min)
     L[2] = int(L[2])
     return tuple(L)
-    
+
 
 
 #
@@ -98,8 +97,8 @@
     if span == len(time_list):
         return 1
     return span+1
-    
-    
+
+
 def format_day (day, output):
     # Figure out unique rooms
     rooms = []
@@ -127,7 +126,7 @@
         print >>output,  '<th>%s</th>' % room,
     print >>output,  '</tr>'
     print >>output, "</thead>"
-    
+
     # Sort list
     time_dict = {}
     for room, time, duration, title in day:
@@ -145,7 +144,7 @@
             if end_time <= time:
                 del active[act_room]
         print >>output,  '<th>%s</th>' % time,
-        plenary = (len(room_dict) == 1)
+        plenary = (len(room_dict) == 1 and room_dict.keys()[0] == '---')
         if plenary:
             # Plenary session of some sort
             duration, title = room_dict.values()[0]
@@ -153,7 +152,7 @@
             print >>output,  '<td align="center" colspan=%i>%s</td>' % (colspan, title),
             print >>output,  '</tr>'
             continue
-        
+
         for room in rooms:
             # Room still occupied, so skip it
             if room in active:
@@ -174,13 +173,17 @@
                 if m is not None:
                     talk_num = int(m.group(1))
                     title = talks.get_title(talk_num)
+                    url = ('http://wiki.python.org/moin/PyCon2006/Talks#%s'
+                           % talk_num)
+                    title = '%s (<a href="%s">%s</a>)' % (cgi.escape(title),
+                                                          url, talk_num)
                 else:
                     title = cgi.escape(title)
-                
+
                 print >>output,  '<td rowspan="%i">' % rowspan,
                 print >>output,  title,
                 print >>output,  '</td>',
-        
+
         print >>output,  '</tr>'
 
     print '</tbody>'
@@ -195,7 +198,7 @@
         print >>output, date.strftime('<h3>%A, %B %d %Y</h3>')
         format_day(day_data, output)
 
-    
+
 def main ():
     parser = optparse.OptionParser(usage="usage: %prog [options] < final-schedule")
     parser.add_option('--format',
@@ -206,7 +209,7 @@
                       help = "Select output format")
     options, args = parser.parse_args()
 
-    d = parse()
+    d = parse(lines=sys.stdin.readlines())
     fmt = options.format
     if fmt == 'print':
         pprint.pprint(d)
@@ -221,12 +224,6 @@
     else:
         print >>sys.stderr, "Unknown format %r" % fmt
         sys.exit(1)
-        
+
 if __name__ == '__main__':
     main()
-    
-
-
-
-
-


More information about the Python-checkins mailing list