Skip to content

Commit

Permalink
Merge pull request #1654 from UUDigitalHumanitieslab/feature/jewishmi…
Browse files Browse the repository at this point in the history
…gration-api-key

Jewishmigration: request data with API key
  • Loading branch information
BeritJanssen authored Sep 11, 2024
2 parents 14c6817 + e3f910f commit 04a27ff
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions backend/corpora/jewishmigration/jewishmigration.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class JewishMigration(PeacePortal, JSONCorpusDefinition):
data_directory = settings.JMIG_DATA_DIR
data_filepath = getattr(settings, 'JMIG_DATA', None)
data_url = getattr(settings, 'JMIG_DATA_URL', None)
data_api_key = getattr(settings, 'JMIG_DATA_API_KEY', None)

es_alias = getattr(settings, 'JMIG_ALIAS', None)
es_index = getattr(settings, 'JMIG_INDEX', 'jewishmigration')
image = 'jewish_inscriptions.jpg'
languages = ['en']
Expand All @@ -60,7 +62,11 @@ class JewishMigration(PeacePortal, JSONCorpusDefinition):

def sources(self, start, end):
if self.data_url:
response = requests.get(self.data_url)
if self.data_api_key:
headers = {"Authorization": f"Token {self.data_api_key}"}
response = requests.get(self.data_url, headers=headers)
else:
response = requests.get(self.data_url)
list_of_sources = response.json()
elif self.data_filepath:
with open(self.data_filepath, 'r') as f:
Expand All @@ -71,7 +77,6 @@ def sources(self, start, end):
for source in list_of_sources:
yield source


def __init__(self):
super().__init__()
self._id.extractor = extract.JSON(key='source')
Expand Down

0 comments on commit 04a27ff

Please sign in to comment.