forked from hrydgard/ppsspp
-
Notifications
You must be signed in to change notification settings - Fork 3
/
link_readme.py
executable file
·42 lines (37 loc) · 976 Bytes
/
link_readme.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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+)", replace_foo, cont)
f.seek(0)
f.write(updated)
f.write(footer)
f.truncate()
f.close()