Merge branch 'kaylea/master' of github.com:CommunityDataScienceCollective/COVID-19_Digital_Observatory into kaylea/master
This commit is contained in:
commit
f5ac92330c
@ -57,23 +57,23 @@ def main():
|
|||||||
next(infile) #skip header
|
next(infile) #skip header
|
||||||
articleList = list(infile)
|
articleList = list(infile)
|
||||||
|
|
||||||
j = []
|
j = []
|
||||||
|
|
||||||
#2 Repeatedly call the API with that list of names
|
#2 Repeatedly call the API with that list of names
|
||||||
|
|
||||||
for a in articleList:
|
for a in articleList:
|
||||||
a = a.strip("\"\n") #destringify
|
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}"
|
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)
|
response = requests.get(url)
|
||||||
if response.ok:
|
if response.ok:
|
||||||
jd = json.loads(response.content)
|
jd = json.loads(response.content)
|
||||||
j.append(jd["items"][0])
|
j.append(jd["items"][0])
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
else:
|
else:
|
||||||
print(f"Not ok response: {response.status_code} from {url}")
|
print(f"Not ok response: {response.status_code} from {url}")
|
||||||
|
|
||||||
#3 Save results as a JSON and TSV
|
#3 Save results as a JSON and TSV
|
||||||
|
|
||||||
#all data in j now, make json file
|
#all data in j now, make json file
|
||||||
with open(j_Out, 'w') as j_outfile:
|
with open(j_Out, 'w') as j_outfile:
|
||||||
|
Loading…
Reference in New Issue
Block a user