Created
July 23, 2019 08:50
-
-
Save isidentical/31e32e2866fcdc9c3d5f49648499fad5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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