Skip to content

Instantly share code, notes, and snippets.

Created October 13, 2016 21:07
Show Gist options
  • Save anonymous/063403b1129a09ca10ebebe78bdf8a77 to your computer and use it in GitHub Desktop.
Save anonymous/063403b1129a09ca10ebebe78bdf8a77 to your computer and use it in GitHub Desktop.
import requests, re
problem_name = 'even-or-odd'
problem_url = 'https://www.codewars.com/kata/' + problem_name
users = [ 'fabiopedrosa', 'johnsardine', 'disbeat', 'pgcmarques', 'nnunobm', 'alexp100' ]
problem_id = re.findall('<div class="info-row code-challenge" data-id="(.+?)"', requests.get(problem_url).text)[0]
users = dict( [ (u, []) for u in users ] )
for user in users:
token = None
cids = {}
for page in range(0, 100):
url = "https://www.codewars.com/users/%s/completed?page=%d" % (user, page)
r = requests.get(url, headers = { 'x-requested-with': 'XMLHttpRequest', 'x-csrf-token': token })
if token == None: token = re.findall('content\="(.+?)" name="csrf-token"', r.text)[0]
pids = re.findall("data\-id=\"(.+?)\"", r.text)
if len(pids) == 0: break
for cid in pids: cids[cid] = True
print "\t=> %s has solved %d problems" % (user, len(cids))
users[user] = cids
print
print "*%s* (%s)" % ( problem_name, problem_url )
print
for user in users.keys():
print user, "Yep!" if problem_id in users[user] else "Nop"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment