-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwiki2helper
executable file
·79 lines (73 loc) · 1.84 KB
/
wiki2helper
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/python3
import sys, requests, re, urllib.parse
try:
page = urllib.parse.quote(sys.argv[1])
except:
sys.exit("Need one or two cmdline parameters: page_name wiki_server")
try:
server = sys.argv[2]
except:
server = 'http://wiki.rosalab.ru/ru/index.php'
prefix = '?title='
suffix = '&action=edit'
url = server + prefix + page + suffix
page = requests.get(url)
html = page.text
htmllist = []
for line in html.split("\n"):
htmllist.append(line)
save = False
space = True
textaria = []
preline = False
for line in htmllist:
if 'textarea' in line:
if save:
break
else:
save= True
if '<!--' in line:
save = False
continue
elif '-->' in line:
save= True
continue
if not save:
continue
#print(line)
line = re.sub('<.*?>', '', line)
if len(line) == 0 and not space:
textaria.append('+')
space = True
continue
if len(line) == 0 and space:
continue
space = False
line = re.sub('^;', '', line)
line = re.sub('<.*?>', '', line)
if line.endswith('\\'):
if not preline:
preline = ''
preline = preline + ' ' + re.sub(r"\\$", "", line.lstrip())
continue
if preline:
line = preline + ' ' + line
preline = ''
if line.lstrip().startswith("=") and line.rstrip().endswith("="):
line = re.sub('^=+', '+ ', line)
line = re.sub('=*\s*$', '', line, count=1)
elif line.lstrip().startswith("'''"):
line = line.replace("'''", "= green ; echo -n '", 1 )
line = line.replace("'''", " ' ; = default ; long '")
line = line + "'"
elif line.lstrip().startswith("''"):
line = line.replace("''", "= brown ; echo -n '", 1 )
line = line.replace("''", " ' ; = default ; long '")
line = line + "'"
else:
line = re.sub('^', 'long "', line, count=1)
line = re.sub('$', '"', line, count=1)
if save:
textaria.append(line.replace('$', '\$').replace("'''", "").replace("''", ""))
for line in textaria:
print(line)