[Collab-qa-commits] r1604 - udd/udd

Lucas Nussbaum lucas at alioth.debian.org
Mon Oct 19 20:34:06 UTC 2009


Author: lucas
Date: 2009-10-19 20:34:05 +0000 (Mon, 19 Oct 2009)
New Revision: 1604

Modified:
   udd/udd/wannabuild_gatherer.py
Log:
[w-b] when parsing dates in english fails, try german, french and finnish.

Modified: udd/udd/wannabuild_gatherer.py
===================================================================
--- udd/udd/wannabuild_gatherer.py	2009-10-19 20:03:16 UTC (rev 1603)
+++ udd/udd/wannabuild_gatherer.py	2009-10-19 20:34:05 UTC (rev 1604)
@@ -9,6 +9,7 @@
 import re
 import psycopg2
 import time
+import locale
 
 def get_gatherer(connection, config, source):
   return wannabuild_gatherer(connection, config, source)
@@ -40,11 +41,26 @@
         for row in wbcur.fetchall():
             row = list(row)
             if row[6] != None:
+                t = None
                 try:
                     t = time.strptime(row[6], "%Y %b %d %H:%M:%S")
-                    row[6] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", t)
                 except ValueError:
+                    # we couldn't parse the date in english. But since Debian is
+                    # the universal operating system, let's try a few other
+                    # popular languages in Debian ;)
+                    for lang in [ 'de_DE.UTF-8', 'fr_FR.UTF-8', 'fi_FI.UTF-8']:
+                        try:
+                            locale.setlocale(locale.LC_TIME, lang)
+                            t = time.strptime(row[6], "%Y %b %d %H:%M:%S")
+                            locale.resetlocale()
+                            continue
+                        except ValueError:
+                            locale.resetlocale()
+                if t == None:
+                    print "Parsing failed in all lang: %s %s - %s"%(row[0], row[1], row[6])
                     row[6] = None
+                else:
+                    row[6] = time.strftime("%a, %d %b %Y %H:%M:%S +0000", t)
             entries.append([arch] + row)
         cur.executemany("EXECUTE wb_insert (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", entries)
         entries = []




More information about the Collab-qa-commits mailing list