3 ###############################################################################
 
   5 # This script assumes the presence of the COVID-19 repo.
 
   7 # It (1) reads in the article list and then (2) calls the Wikimedia API to 
 
   8 # fetch view information for each article. Output is to a (3) TSV file.
 
  11 ###############################################################################
 
  14 #1 Load up the list of article names
 
  16 #2 Repeatedly call the API with that list of names
 
  18 #3 Save results as a TSV
 
  32     parser = argparse.ArgumentParser(description='Call the views API repeatedly.')
 
  33     parser.add_argument('-o', '--output_folder', help='Where to save output', default="", type=str)
 
  34     parser.add_argument('-i', '--article_file', help='File listing article names', default="../resources/articles.txt", type=str)
 
  35     parser.add_argument('-d', '--query_date', help='Date if not yesterday, in YYYYMMDD format please.', type=str)
 
  36     args = parser.parse_args()
 
  45     outputPath = args.output_folder
 
  46     articleFile = args.article_file
 
  48         queryDate = args.query_date
 
  50         queryDate = datetime.datetime.today().strftime("%Y%m%d")
 
  53     with open(articleFile, 'r') as infileHandle:
 
  54         theInfile = csv.reader(infileHandle, quotechar='"')
 
  55         for currentLine in theInfile:
 
  56             articleList.append(currentLine["Article"])
 
  58     with open(outputPath, 'w') as outfile:
 
  61     i = 0 #iterator to deal with end of file
 
  65         url= "https://wikimedia.org/api/rest_v1/metrics/pageviews/per-article/en.wikipedia/all-access/all-agents/"
 
  66         url= url + a + "/daily/" + queryDate + "/" + queryDate #for now, single date at a time
 
  69         response = requests.get(url)
 
  71             with open(outputPath, 'a') as outfile:
 
  72                 json.dump(json.loads(ident_response.content), outfile)
 
  81     with open(outputPath, 'a') as outfile:
 
  86 if __name__ == "__main__":