changeset 39:bb09db2afe6b

try to fix a few more niggling bugs
author Henry S. Thompson <ht@markup.co.uk>
date Thu, 29 Nov 2018 15:14:46 +0000
parents beae6309d4ec
children 4cf6bc21f683
files master/bin/fixDates.py
diffstat 1 files changed, 11 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/master/bin/fixDates.py	Thu Nov 29 13:52:07 2018 +0000
+++ b/master/bin/fixDates.py	Thu Nov 29 15:14:46 2018 +0000
@@ -32,16 +32,18 @@
     count=None
     try:
       # More alphas then numerics...
+      count=int(ff.group(4))
       try:
         month=months[ff.group(2)]
       except KeyError:
         month=int(ff.group(2))
       year=int(ff.group(3))
-      count=int(ff.group(4))
     except:
       # Unusual month or year field
       try:
-        d=parse("%s %s"%(ff.group(2),ff.group(3)))#,languages=['en'])
+        # day 1 is because w/o it the default is today's is used, which may
+        #  fail if it's e.g. 31 March today and the string is "April 2017"
+        d=parse("1 %s %s"%(ff.group(2),ff.group(3)))#,languages=['en'])
         if d is None or count is None:
           print(5,ff.group(1),ff.group(2),ff.group(3),ff.group(4),
                 file=sys.stderr)
@@ -57,7 +59,7 @@
           month=d.month
           year=d.year
       except Exception as e:
-        print(6,e,l,file=sys.stderr)
+        print(6,ff.group(1),e,l,file=sys.stderr)
         bogons+=1
         continue
   else:
@@ -76,7 +78,7 @@
       cols=cols[1:]
       count=int(cols.pop())
     except:
-      print(2,count,l,file=sys.stderr)
+      print(2,sn[scheme],count,l,file=sys.stderr)
       bogons+=1
       continue
     if cols==[]:
@@ -87,7 +89,7 @@
       try:
         d=parse(l)#,languages=['en']))
         if d is None:
-          print(3,d,l,count,file=sys.stderr)
+          print(3,sn[scheme],l,count,file=sys.stderr)
           bogons+=1
           continue
         elif d.year<1900 or d.year>2100:
@@ -98,7 +100,7 @@
           year=d.year
           month=d.month
       except Exception as e:
-        print(4,e,l,count,file=sys.stderr)
+        print(4,sn[scheme],e,l,count,file=sys.stderr)
         bogons+=1
         continue
   # log it
@@ -127,8 +129,9 @@
       for m in range(1,13):
         if mm[m]!=0:
           print(sn[s],mn[m],y+1900,mm[m],sep='\t')
-print(n,bogons,file=sys.stderr)
-print('#3 %s'%strftime('%Y-%m-%d %H:%M:%S'),file=sys.stderr)
+print('#3 %s %s %s'%(strftime('%Y-%m-%d %H:%M:%S'),
+                     n,bogons),
+                     file=sys.stderr)