Skip to content

Commit

Permalink
Fix some things. See #452
Browse files Browse the repository at this point in the history
  • Loading branch information
breyten committed Jan 24, 2024
1 parent 54df2c6 commit 8539b65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions ocd_backend/extractors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,23 @@ def _make_hash(self, report_dict):
h.update(json_encoder.encode(ordered_report_dict).encode('ascii'))
return h.hexdigest()

def check_if_most_recent(self, provider, site_name, id, report_dict):
def check_if_most_recent(self, provider, site_name, item_type, id, report_dict):
h = sha1()
hash_key = "%s|%s|%s" % (provider, site_name, id,)
hash_key = "%s|%s|%s|%s" % (provider, site_name, item_type, id,)
h.update(hash_key.encode('ascii'))
item_id = h.hexdigest()
new_hash = self._make_hash(report_dict)
old_item = self.session.query(ItemHash).filter(ItemHash.item_id == item_id).first()
old_item_hash = old_item.item_hash
if old_item:
old_item.item_hash = new_hash
new_item = ItemHash(item_id=item_id, item_hash=new_hash)
self.session.add(new_item)
else:
new_item = ItemHash(item_id=item_id, item_hash=new_hash)
self.session.add(new_item)
self.session.commit()
self.session.flush()
if old_item:
return (old_item.item_hash == new_hash)
return (old_item_hash == new_hash)
else:
return False

Expand Down
4 changes: 2 additions & 2 deletions ocd_backend/extractors/ibabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def run(self):
continue

meeting_dict['Meetingtype'] = meeting_types[meeting_dict['MeetingtypeId']]
if not self.check_if_most_recent('ibabs', self.source_definition['ibabs_sitename'], meeting['Id'], meeting_dict):
if not self.check_if_most_recent('ibabs', self.source_definition['ibabs_sitename'], 'meeting', meeting['Id'], meeting_dict):
yield 'application/json', \
json.dumps(meeting_dict), \
None, \
Expand Down Expand Up @@ -307,7 +307,7 @@ def run(self):

log.info(self._make_hash(report_dict))
is_newer = not self.check_if_most_recent(
'ibabs', self.source_definition['ibabs_sitename'], item['id'], report_dict)
'ibabs', self.source_definition['ibabs_sitename'], 'report', item['id'], report_dict)
# identifier = item['id'][0]
if is_newer:
yield 'application/json', json_encoder.encode(report_dict), None, 'ibabs/' + cached_path
Expand Down

0 comments on commit 8539b65

Please sign in to comment.