From: Stefan Huber Date: Sun, 19 Jan 2014 14:24:30 +0000 (+0100) Subject: Make date field of purposes of DATE type X-Git-Url: https://git.sthu.org/?a=commitdiff_plain;h=24fb65924b63de5a355cd52a3d1e895b4e157357;p=dvrdb.git Make date field of purposes of DATE type --- diff --git a/dvr-managedb b/dvr-managedb index f8684ea..71bab84 100755 --- a/dvr-managedb +++ b/dvr-managedb @@ -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)