Merge pull request #1 from CommunityDataScienceCollective/kaylea/master
Some suggested changes.
This commit is contained in:
commit
dd7d968bb6
@ -20,7 +20,6 @@ import datetime
|
|||||||
#import feather
|
#import feather
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Call the views API repeatedly.')
|
parser = argparse.ArgumentParser(description='Call the views API repeatedly.')
|
||||||
@ -51,31 +50,28 @@ def main():
|
|||||||
articleList = []
|
articleList = []
|
||||||
#1 Load up the list of article names
|
#1 Load up the list of article names
|
||||||
|
|
||||||
with open(articleFile, 'r') as infileHandle:
|
j_Out = f"{outputPath}dailyviews{queryDate}.json"
|
||||||
theInfile = csv.reader(infileHandle)
|
t_Out = f"{outputPath}dailyviews{queryDate}.tsv"
|
||||||
next(theInfile) #skip header
|
|
||||||
for currentLine in theInfile:
|
|
||||||
articleList.append(currentLine)
|
|
||||||
|
|
||||||
j_Out = outputPath + "dailyviews" + queryDate + ".json"
|
with open(articleFile, 'r') as infile:
|
||||||
t_Out = outputPath + "dailyviews" + queryDate + ".tsv"
|
next(infile) #skip header
|
||||||
|
articleList = list(infile)
|
||||||
|
|
||||||
j = []
|
j = []
|
||||||
|
|
||||||
i = 0 #iterator to deal with end of file
|
|
||||||
|
|
||||||
#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[0] #destringify
|
a = a.strip("\"\n") #destringify
|
||||||
i = i+1
|
url= f"https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/all-access/all-agents/{a}/daily/{queryDate}/{queryDate}"
|
||||||
url= "https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/all-access/all-agents/"
|
|
||||||
url= url + a + "/daily/" + queryDate + "/" + queryDate #for now, single date at a time
|
|
||||||
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:
|
||||||
|
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
|
||||||
|
|
||||||
@ -89,7 +85,7 @@ def main():
|
|||||||
dw.writerows(j)
|
dw.writerows(j)
|
||||||
|
|
||||||
|
|
||||||
f_Out = outputPath + "dailyviews" + queryDate + ".feather"
|
# f_Out = outputPath + "dailyviews" + queryDate + ".feather"
|
||||||
# read the json back in and make a feather file?
|
# read the json back in and make a feather file?
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user