File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111}
1212ARTICLE_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 # {
You can’t perform that action at this time.
0 commit comments