Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

there was an error in timezone detection #1792

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 23 additions & 27 deletions server/planning/feed_parsers/onclusive.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,33 +51,29 @@ def can_parse(self, content):
return False

def parse(self, content, provider=None):
try:
all_events = []
for event in content:
guid = "urn:onclusive:{}".format(event["itemId"])

item = {
GUID_FIELD: guid,
ITEM_TYPE: CONTENT_TYPE.EVENT,
"state": CONTENT_STATE.INGESTED,
}

try:
self.set_occur_status(item)
self.parse_item_meta(event, item)
self.parse_location(event, item)
self.parse_event_details(event, item)
self.parse_category(event, item)
self.parse_contact_info(event, item)
all_events.append(item)
except EmbargoedException:
logger.info("Ignoring embargoed event %s", event["itemId"])
except (KeyError, IndexError, TypeError) as error:
logger.exception("error %s when ingesting event", error, extra=dict(event=event))
return all_events
all_events = []
for event in content:
guid = "urn:onclusive:{}".format(event["itemId"])

item = {
GUID_FIELD: guid,
ITEM_TYPE: CONTENT_TYPE.EVENT,
"state": CONTENT_STATE.INGESTED,
}

except Exception as ex:
raise ParserError.parseMessageError(ex, provider)
try:
self.set_occur_status(item)
self.parse_item_meta(event, item)
self.parse_location(event, item)
self.parse_event_details(event, item)
self.parse_category(event, item)
self.parse_contact_info(event, item)
all_events.append(item)
except EmbargoedException:
logger.info("Ignoring embargoed event %s", event["itemId"])
except Exception as error:
logger.exception("error %s when parsing event %s", error, event["itemId"], extra=dict(event=event))
return all_events

def set_occur_status(self, item):
eocstat_map = get_resource_service("vocabularies").find_one(req=None, _id="eventoccurstatus")
Expand Down Expand Up @@ -146,7 +142,7 @@ def parse_timezone(self, start_date, event):
logger.error("Unknown Timezone %s", tzname)
continue
abbr = date.strftime("%Z")
offset = tz.utcoffset(start_date.replace(tzinfo=None)).total_seconds() / 3600
offset = date.utcoffset().total_seconds() / 3600
if abbr == event["timezone"]["timezoneAbbreviation"] and offset == event["timezone"]["timezoneOffset"]:
return tzname
else:
Expand Down
19 changes: 19 additions & 0 deletions server/planning/feed_parsers/onclusive_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,22 @@ def test_embargoed(self):
utcnow_mock.return_value = datetime.datetime.fromisoformat("2022-12-07T18:00:00+00:00")
parsed = OnclusiveFeedParser().parse([data])
self.assertEqual(1, len(parsed))

def test_timezone_ambigous_time_error(self):
data = self.data.copy()
data.update(
{
"startDate": "2023-10-27T00:00:00.0000000",
"time": "08:30",
"timezone": {
"timezoneID": 27,
"timezoneAbbreviation": "JST",
"timezoneName": "(JST) Japan Standard Time : Tokyo",
"timezoneOffset": 9.00,
"timezoneIdentity": None,
},
}
)

item = OnclusiveFeedParser().parse([data])[0]
assert item["dates"]["tz"] == "Asia/Tokyo"
2 changes: 2 additions & 0 deletions server/planning/feeding_services/onclusive_api_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ def _update(self, provider, update):
second=0
) # next time start from here, onclusive api does not use seconds
if update["tokens"].get("import_finished"):
# populate it for cases when import was done before we introduced the field
update["tokens"].setdefault("next_start", update["tokens"]["import_finished"] - timedelta(hours=8))
url = urljoin(URL, "/api/v2/events/latest")
start = update["tokens"]["next_start"] - timedelta(
hours=3, # add a buffer, also not sure about timezone there
Expand Down