Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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