]> git.sthu.org Git - dvrdb.git/commitdiff
Make date field of purposes of DATE type
authorStefan Huber <shuber@sthu.org>
Sun, 19 Jan 2014 14:24:30 +0000 (15:24 +0100)
committerStefan Huber <shuber@sthu.org>
Sun, 19 Jan 2014 15:00:25 +0000 (16:00 +0100)
dvr-managedb

index f8684eabe32d7217e39f571183d599663f645fcf..71bab84cdc6aef7913dfd8cd87b628e05904b112 100755 (executable)
@@ -12,6 +12,7 @@ import urllib.error
 import json
 import gzip
 import time
+import datetime
 
 
 class GoogleGeolocation:
@@ -143,7 +144,7 @@ class Database:
                      dvrid INTEGER REFERENCES dvrtable(id) ON DELETE CASCADE, \
                      num INTEGER NOT NULL, \
                      purpose TEXT NOT NULL, \
-                     date TEXT NOT NULL, \
+                     date DATE, \
                      status TEXT NOT NULL \
                      )")
 
@@ -489,7 +490,12 @@ def parseAndInsert(db, htmldata):
             cols = row.find_all('td')
             num = int(cols[1].text.split('/')[1])
             purpose = cols[2].text
-            date = cols[3].text
+            try:
+                date = datetime.datetime.strptime(cols[3].text, "%d.%m.%Y")
+            except ValueError:
+                strdate = cols[3].text
+                print("  Cannot convert date '%s'." % strdate, file=sys.stderr)
+                date = None
             status = cols[4].text
 
             db.add_purpose(id, num, purpose, date, status)