Created
September 27, 2022 02:20
-
-
Save matoro/80f26d76f1f918eedc47b1f340d4e2ee to your computer and use it in GitHub Desktop.
Arch testing tracker in a wiki page (WIP)
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
from datetime import date | |
from os import system | |
from requests import Session | |
from sys import argv | |
USERNAME = "" | |
PASSWORD = "" | |
URL = "https://wiki.gentoo.org/api.php" | |
WIKIPAGE = "User:Matoro/ARCHtesting" | |
REPO = "" | |
session = Session() | |
req = session.get(url = URL, params = { "action": "query", "meta": "tokens", "type": "login", "format": "json" }, headers = { "Accept": "application/json" }) | |
token = req.json()["query"]["tokens"]["logintoken"] | |
req = session.post(url = URL, data = { "action": "login", "lgname": USERNAME, "lgpassword": PASSWORD, "lgtoken": token, "format": "json" }, headers = { "Accept": "application/json" }) | |
assert req.json()["login"]["result"] == "Success" | |
class Line: | |
def __init__(self, line = None): | |
if line: | |
self.date = line.split("|")[4] | |
self.nattka = line.split("|")[2].replace("}", "") | |
self.logs = line.split("|")[6] if len(line.split("|")) > 6 else None | |
else: | |
self.date = None | |
self.nattka = None | |
self.logs = None | |
def writelines(lines): | |
text = "{| class=\"wikitable sortable\"\n!Nattka!!Date tested!!Test logs\n" | |
for line in lines: | |
text += "|-\n|{{C|" + line.nattka + "}}||" + line.date + (("||" + line.logs) if line.logs else "") + "\n" | |
text += "|}" | |
req = session.get(url = URL, params = { "action": "query", "meta": "tokens", "format": "json" }, headers = { "Accept": "application/json" }) | |
csrf_token = req.json()["query"]["tokens"]["csrftoken"] | |
req = session.post(url = URL, data = { "action": "edit", "title": WIKIPAGE, "format": "json", "text": text, "token": csrf_token }, headers = { "Accept": "application/json" }) | |
def printlines(lines): | |
for i, line in enumerate(lines): | |
print("[" + str(i) + "] " + line.date + " -> " + line.nattka + ((" ( " + line.logs + " ) " ) if line.logs else "")) | |
req = session.get(url = URL, params = { "action": "query", "prop": "revisions", "titles": WIKIPAGE, "rvslots": "*", "rvprop": "content", "formatversion": 2, "format": "json" }, headers = { "Accept": "application/json" }) | |
content = req.json()["query"]["pages"][0]["revisions"][0]["slots"]["main"]["content"] | |
lines = [ Line(x) for x in list(filter("|-".__ne__, content.split("\n")[3:-1])) ] | |
if len(argv) <= 1: | |
printlines(lines) | |
elif argv[1] == "review": | |
while True: | |
try: | |
printlines(lines) | |
prompt = input("commit which? ") | |
# system("nattka --repo " + REPO + " apply " + lines[int(prompt)].nattka) | |
# system("nattka --repo " + REPO + " commit " + lines[int(prompt)].nattka) | |
# system("git -C " + REPO + " push") | |
# system("nattka --repo " + REPO + " resolve " + lines[int(prompt)].nattka) | |
del lines[int(prompt)] | |
writelines(lines) | |
except EOFError: | |
print("") | |
break | |
elif argv[1] == "logs": | |
while True: | |
try: | |
printlines(lines) | |
prompt = input("add logs to which? ") | |
lines[int(prompt)].logs = input("log url = ") | |
writelines(lines) | |
except EOFError: | |
print("") | |
break | |
else: | |
line = Line() | |
line.date = str(date.today()).replace("-", ".") | |
line.nattka = " ".join(argv[1:]) | |
lines.append(line) | |
writelines(lines) | |
printlines(lines) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment