diff options
author | Petter Reinholdtsen <pere@hungry.com> | 2015-01-20 14:49:51 +0100 |
---|---|---|
committer | Petter Reinholdtsen <pere@hungry.com> | 2015-01-20 14:49:51 +0100 |
commit | 2169ce53a6dc197189f630617ec95aeb16975b88 (patch) | |
tree | 8b0e28c87472d0c41939b88911741bdfb1b293c7 | |
parent | 22d1a1a16f67a3401558f621e19ee5095a82bf6a (diff) |
Rewrite logic to select dates, to parse both forward and back in time.
-rw-r--r-- | scrapersources/postliste-bergen-kommune | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/scrapersources/postliste-bergen-kommune b/scrapersources/postliste-bergen-kommune index 98a9ef6..19ae79d 100644 --- a/scrapersources/postliste-bergen-kommune +++ b/scrapersources/postliste-bergen-kommune @@ -143,13 +143,30 @@ print "Fetching public journal!" parser = postlistelib.JournalParser(agency=agency) -parsedays = 48 +def gen_date_list(list, startdate, count, step): + d = dateutil.parser.parse(startdate, dayfirst=False) + for n in xrange(1, step*(count+1), step): + next = (d + relativedelta(days=n)).strftime("%02d.%02m.%04Y") + list.append(next) today = datetime.date.today() -i = 1 -while i <= parsedays: - i = i + 1 - dayparse = today - relativedelta(days=(parsedays - i)) - daystr = dayparse.strftime("%02d.%02m.%04Y") +try: + first = scraperwiki.sqlite.select("min(recorddate) as min from swdata")[0]['min'] + last = scraperwiki.sqlite.select("max(recorddate) as max from swdata")[0]['max'] +except: + last = (today + relativedelta(days=-14)).strftime("%Y-%m-%d") + first = None + +dates = [] + +# Parse some days back in time +if first is not None: + gen_date_list(dates, first, 14, -1) + +# Parse some days forward in time +if last is not None: + gen_date_list(dates, last, 7, 1) + +for daystr in dates: # print daystr fetch_date(parser, saver, daystr) |