updated code to handle printing on windows
[harrypotter-wikipedia-cdsw] / build_hpwp_dataset.py
index 97cc5338251324b76ecef0467313dc31141b90ed..9d381ae1e1a66b4e5904940c00f3d56791d4a53a 100644 (file)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 # coding=utf-8
 
+import encoding_fix
 import requests
 
 # get_article_revisions is a function that takes an article title in
@@ -85,7 +86,7 @@ category = "Harry Potter"
 #
 # The following requests call basically does the same thing as this string:
 # "http://tools.wmflabs.org/catscan2/catscan2.php?depth=10&categories={0}&doit=1&format=json".format(category)
-url_catscan = "http://tools.wmflabs.org/catscan2/catscan2.php"
+url_catscan = "http://tools.wmflabs.org/catscan3/catscan2.php"
 
 parameters = {'depth' : 10,
               'categories' : category,
@@ -96,7 +97,7 @@ parameters = {'depth' : 10,
 
 r = requests.get(url_catscan, params=parameters)
 articles_json = r.json()
-articles = articles_json["*"][0]["a"]["*"]
+articles = articles_json["*"][0]["*"]
 
 # open a file to write all the output
 output = open("hp_wiki.tsv", "w", encoding="utf-8")
@@ -107,6 +108,7 @@ for article in articles:
 
     # first grab the article's title
     title = article["a"]["title"]
+    print(title)
 
     # get the list of revisions from our function and then iterate through it,
     # printing it to our output file

Benjamin Mako Hill || Want to submit a patch?