Skip to content

Commit b0835d8

Browse files
committed
Address peer review
1 parent 21a87bd commit b0835d8

1 file changed

Lines changed: 16 additions & 28 deletions

File tree

process.py

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,27 @@
1111
}
1212
ARTICLE_PATH = pathlib.Path('/temp-output-directory/alternative/regalytics/articles')
1313

14-
def main(date):
14+
def main(process_date):
1515
# objectives:# download data from API -> temp folder or in memory. Output processed datat to /temp-output-directory/alternative/regalytics/articles/yyyyMMdd.json
1616
ARTICLE_PATH.mkdir(parents=True, exist_ok=True)
1717
articles_by_date = {}
18+
19+
process_datetime = datetime.strptime(process_date, '%Y%m%d').date()
20+
process_date = process_datetime.strftime('%Y-%m-%d')
1821

19-
if date == "all":
20-
url = f"{URL}/get-all"
21-
payload = json.dumps({
22-
"apikey": os.environ["REGALYTICS_API_KEY"]
23-
})
24-
25-
response = requests.post(url, headers=HEADERS, data=payload).json()
26-
max_page = response['all_pages']
27-
articles = response['results']
28-
29-
for i in range(2, max_page + 1):
30-
response = requests.post(f'{url}?page={i}', headers=HEADERS, data=payload).json()
31-
articles += response['results']
32-
33-
else:
34-
url = f"{URL}/search"
35-
payload = json.dumps({
36-
"apikey": os.environ["REGALYTICS_API_KEY"],
37-
"search_options": {
38-
"created_at": {
39-
"start": date,
40-
"end": date
41-
}
22+
url = f"{URL}/search"
23+
payload = json.dumps({
24+
"apikey": os.environ["REGALYTICS_API_KEY"],
25+
"search_options": {
26+
"created_at": {
27+
"start": process_date,
28+
"end": process_date
4229
}
43-
})
44-
45-
response = requests.post(url, headers=HEADERS, data=payload).json()
46-
articles = response['articles']
30+
}
31+
})
32+
33+
response = requests.post(url, headers=HEADERS, data=payload).json()
34+
articles = response['articles']
4735

4836
# "agencies": [
4937
# {

0 commit comments

Comments
 (0)