Permalink
Browse files

parse_future_committee_meetings: use Israel timezone

icalendar files are by default in UTC. This causes the current scraped
files, that were implicitly in Isr timezone, to be 2 hours in the
future. There are two ways to fix this:
 1. create the icalendar files assuming the db is in Israel timezone.
 2. change the db to be in UTC timezone.

To allow easier cooperation with external data the later approach is
taken. This patch fixes the scraping code for future committees. Similar
patches need to be applied to the whole tree, for any model instance
creation or change of a datetime or time field. Additionally data
migration will be written to change an existing database and move all
times back, based on the date (since some will be in daylight savings
and some not).

After talking to Ofri I agree it is best to do that only when we
actually need it, i.e. not right now.
  • Loading branch information...
1 parent 60b6b45 commit 02d92d3b00472243bb1670761d7b199e6fdeefea Alon Levy committed Jan 9, 2012
Showing with 13 additions and 2 deletions.
  1. +13 −2 src/knesset/simple/management/commands/parse_future_committee_meetings.py
@@ -8,11 +8,16 @@
import datetime
from django.core.management.base import BaseCommand
from django.contrib.contenttypes.models import ContentType
+from dateutil import zoneinfo
from knesset.mks.models import Member
from knesset.committees.models import Committee
from knesset.events.models import Event
+# NB: All dates scraped from the knesset site are assumed to be in timezone Israel.
+isr_tz = zoneinfo.gettz('Israel')
+utc_tz = zoneinfo.gettz('UTC')
+
logger = logging.getLogger("open-knesset.parse_future_committee_meetings")
spamWriter = csv.writer(open('eggs.csv', 'wb'))
@@ -95,8 +100,14 @@ def update_future_committee_meetings_db(self, r):
for p in r:
try:
committee = Committee.objects.get(name=p.name)
- ev, created = Event.objects.get_or_create( when = datetime.datetime( year=p.year, month=p.month, day=p.day, hour=p.hour, minute=p.minute, second=0 ),
- when_over = datetime.datetime( year=p.year, month=p.month, day=p.day, hour=p.end_hour, minute=p.end_minute, second=0),
+ when_over = datetime.datetime(
+ year=p.year, month=p.month, day=p.day, hour=p.end_hour,
+ minute=p.end_minute, second=0, tzinfo=isr_tz).astimezone(utc_tz)
+ when = datetime.datetime(
+ year=p.year, month=p.month, day=p.day, hour=p.hour,
+ minute=p.minute, second=0, tzinfo=isr_tz).astimezone(utc_tz)
+ ev, created = Event.objects.get_or_create( when = when,
+ when_over = when_over,
when_over_guessed = p.end_guessed,
where = unicode(committee),
what = p.title,

0 comments on commit 02d92d3

Please sign in to comment.