Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-collier committed Sep 30, 2024
1 parent 670f32e commit f321b83
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions dlme_airflow/utils/partition_url_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,11 @@ def _prefetch_page_urls(self):
ids = []
while True:
api_endpoint = self.paging_config['pages_url'].format(offset,self.paging_config['limit'])
print(f"Fetching {api_endpoint}")
data = self._fetch_provider_data(api_endpoint)[self.paging_config['page_data']]
offset += self.paging_config["limit"]
harvested = len(data)

for i in data:
if validators.url(i['id']):
ids.append(i['id'])
else:
ids.append(f"{self.collection_url}{i['id']}")
ids += self._extract_ids(data)

if harvested < self.paging_config["limit"]:
break
Expand All @@ -90,3 +85,11 @@ def _fetch_provider_data(self, url):
resp = requests.get(url, headers=headers)
if resp.status_code == 200:
return resp.json()

def _extract_ids(self, data):
return [self._format_id(i['id']) for i in data]

def _format_id(self, id):
if validators.url(id):
return id
return f"{self.collection_url}{id}"

0 comments on commit f321b83

Please sign in to comment.