Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I guess instead of updating my original post of the question I should have done the answer question. Hopefully its not confusing, I have put updated comment on the question section informing that the issue has been solved and here how I solved it with the help of Jeremy Banks function</p> <pre><code>import simplejson as json import sys import urllib import traceback, csv, string # "base" API URL URL_BASE = 'Some URL' # set user agent string urllib.version = "Data Collection Fix it" page_ids = [] def divide_list(list_, n): for i in range(0, len(list_), n): yield list_[i:i + n] def issue_query(): iFile = open('ReadFromThisFile.txt', "r") lines = iFile.readlines() #print len(lines) for line in lines: ids = string.split(line) ids = ids[0] page_ids.append(ids) url = URL_BASE indicies = range(len(page_ids)) File = open("WriteToThisFile.csv", "w") for indicies in divide_list(page_ids, 50): count = 0 fiftyIds =[] url = URL_BASE for id in indicies: str(id).strip url += str(id) + '|' print url fiftyIds.append(str(id)) count += 1 print count rv = urllib.urlopen(url) j = rv.read().decode("utf-8") #sys.stderr.write(j + "\n") data = json.loads(j) for id in fiftyIds: try: s = int(data["query"]["pages"][id]["revisions"][0]["size"]) sys.stderr.write("%d\t%d\n" % (int(id), s)) File.write("%d\t%d\n" % (int(id), s)) #print ("%d\t%d\n" % (int(id), s)) # do something interesting with id and s except Exception, e: traceback.print_exc() File.close() iFile.close() issue_query() </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload