Skip to content

Commit

Permalink
Add a routine to make a hash of a dict to compare it to earlier versi…
Browse files Browse the repository at this point in the history
…ons of that dict. See #452
  • Loading branch information
breyten committed Jan 17, 2024
1 parent 5c39d68 commit c8a0a2c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ocd_backend/extractors/ibabs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import base64
import re
import json
from collections import OrderedDict
from hashlib import sha1

from zeep.client import Client, Settings
from zeep.exceptions import Error
Expand Down Expand Up @@ -49,6 +51,16 @@ def __init__(self, *args, **kwargs):
except Error as e:
log.error(f'Unable to instantiate iBabs client: {str(e)}')

def _make_hash(self, report_dict):
"""
Make a hash value for a dict. This can be usedc to compare dicts to an
earlier stored hash vlue to see if things changed.
"""
ordered_report_dict = OrderedDict(report_dict.items())
h = sha1()
h.update(json_encoder.encode(ordered_report_dict).encode('ascii'))
return h.hexdigest()


class IBabsCommitteesExtractor(IBabsBaseExtractor):
"""
Expand Down Expand Up @@ -298,6 +310,7 @@ def run(self):
# Skip report if date is outside date interval
continue

log.info(self._make_hash(report_dict))
# identifier = item['id'][0]
yield 'application/json', json_encoder.encode(report_dict), None, 'ibabs/' + cached_path
yield_count += 1
Expand Down

0 comments on commit c8a0a2c

Please sign in to comment.