From: Nathan TeBlunthuis Date: Sat, 28 Mar 2020 21:13:46 +0000 (-0700) Subject: Merge branch 'kaylea/master' of github.com:CommunityDataScienceCollective/COVID-19_Di... X-Git-Url: https://code.communitydata.science/covid19.git/commitdiff_plain/refs/heads/kaylea/master?hp=1b2bb7d1dfadb74c5ea4e3fd7b509797001a140d Merge branch 'kaylea/master' of github.com:CommunityDataScienceCollective/COVID-19_Digital_Observatory into kaylea/master --- diff --git a/wikipedia_views/scripts/fetch_daily_views.py b/wikipedia_views/scripts/fetch_daily_views.py index ab824c2..b604e26 100755 --- a/wikipedia_views/scripts/fetch_daily_views.py +++ b/wikipedia_views/scripts/fetch_daily_views.py @@ -57,23 +57,23 @@ def main(): next(infile) #skip header articleList = list(infile) - j = [] - - #2 Repeatedly call the API with that list of names - - for a in articleList: - a = a.strip("\"\n") #destringify - url= f"https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/all-access/all-agents/{a}/daily/{queryDate}/{queryDate}" - - response = requests.get(url) - if response.ok: - jd = json.loads(response.content) - j.append(jd["items"][0]) - time.sleep(.1) - else: - print(f"Not ok response: {response.status_code} from {url}") - - #3 Save results as a JSON and TSV + j = [] + + #2 Repeatedly call the API with that list of names + + for a in articleList: + a = a.strip("\"\n") #destringify + url= f"https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/all-access/all-agents/{a}/daily/{queryDate}/{queryDate}" + + response = requests.get(url) + if response.ok: + jd = json.loads(response.content) + j.append(jd["items"][0]) + time.sleep(.1) + else: + print(f"Not ok response: {response.status_code} from {url}") + + #3 Save results as a JSON and TSV #all data in j now, make json file with open(j_Out, 'w') as j_outfile: