Skip to content

Commit

Permalink
Add a serializer. See #452
Browse files Browse the repository at this point in the history
  • Loading branch information
breyten committed Jan 24, 2024
1 parent 872743d commit 9c25261
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ocd_backend/extractors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

from ocd_backend.log import get_source_logger
from ocd_backend.models.model import PostgresDatabase
from ocd_backend.models.serializers import PostgresSerializer
from ocd_backend.models.postgres_models import ItemHash
from ocd_backend.utils.misc import json_encoder

log = get_source_logger('extractor')

Expand All @@ -23,7 +25,7 @@ def __init__(self, source_definition):
:type source_definition: dict.
"""
self.source_definition = source_definition
database = PostgresDatabase()
database = PostgresDatabase(serializer=PostgresSerializer)
self.session = database.Session()

def _make_hash(self, report_dict):
Expand All @@ -38,8 +40,9 @@ def _make_hash(self, report_dict):

def check_if_most_recent(self, provider, site_name, id, report_dict):
h = sha1()
h.update("%s|%s|%s" % (provider, site_name, id,))
item_id = h.hexhdigest()
hash_key = "%s|%s|%s" % (provider, site_name, 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()
if old_item:
Expand Down

0 comments on commit 9c25261

Please sign in to comment.