Update README following unknows markup way

This commit is contained in:
iota97
2020-07-15 10:21:15 +02:00
parent f1e5dd2449
commit 8f37dbe3e4
3 changed files with 394 additions and 143 deletions
+34 -2
View File
@@ -1,10 +1,42 @@
#!/bin/python
#!/usr/bin/env python
import re
import time
import urllib.request
from urllib.error import HTTPError
import time
from lxml.html import parse
footer = ""
def replace_foo(match):
first_char = match.group(1)
id = match.group(2)
replace = first_char + "[#"+id+"][]"
url = "https://github.com/hrydgard/ppsspp/issues/"+id
title = None
while title is None:
try:
page = urllib.request.urlopen(url)
p = parse(page)
title = p.find(".//title").text.split('by')[0].split('·')[0].strip()
title = re.sub(r"\"", r'\\"', title)
except HTTPError:
print("Something went wrong, retrying in 10 sec...")
time.sleep(10)
pass
global footer
addition = "[#"+id+"]: https://github.com/hrydgard/ppsspp/issues/"+id+" \""+title+"\""
print("Done: " + addition)
footer += addition+"\n"
return replace
f = open("README.md", "r+")
cont = f.read()
updated = re.sub(r"([^[])#(\d+)", r"\1[#\2](https://github.com/hrydgard/ppsspp/issues/\2)", cont)
updated = re.sub(r"([^[])#(\d+)", replace_foo, cont)
f.seek(0)
f.write(updated)
f.write(footer)
f.truncate()
f.close()