Skip to content

Instantly share code, notes, and snippets.

@isidentical
Created July 23, 2019 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isidentical/31e32e2866fcdc9c3d5f49648499fad5 to your computer and use it in GitHub Desktop.
Save isidentical/31e32e2866fcdc9c3d5f49648499fad5 to your computer and use it in GitHub Desktop.
import subprocess
import json
import urllib.request
URL = "https://challange.oyk2019.ml"
def _find_author(filename, lineno):
prop = subprocess.check_output(f"git blame -pL {lineno},{lineno} {filename}", shell = True)
lines = prop.decode().split("\n")
commit = lines[0].split()[0]
author = lines[1].split()[1]
return commit, author
def find_author(line):
prop = subprocess.check_output(f"fgrep -rni {line!r} Python/", shell = True)
filename, lineno, line = prop.decode().split("\n")[0].split(":")
return _find_author(filename, lineno)
request = urllib.request.Request(url = URL)
request.add_header("User-Agent", "Monty Python")
with urllib.request.urlopen(request) as page:
response = json.loads(page.read().decode())
challange, token, _ = response.values()
commit, author = find_author(challange)
request = urllib.request.Request(url = URL, data = json.dumps({"token": token, "commit": commit, "author": author}).encode(), method = "POST")
request.add_header("User-Agent", "Monty Python")
with urllib.request.urlopen(request) as page:
response = json.loads(page.read().decode())
print(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment