-
Notifications
You must be signed in to change notification settings - Fork 0
/
software_category_add.py
139 lines (126 loc) · 5.42 KB
/
software_category_add.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import requests
import math
import os
# Session and wpEditToken are updated regularly by MediaWiki
# Retrieve from header and POST parameters sent by the browser on a save page request
sessionid = "***"
edittoken = "***"
wikitoken = "***"
# Get links from mediawiki category page content
def getLinks(r):
orgs = []
sections = r.split("</h3>")[1:-8]
for section in sections:
links = section.split('href="')[1:]
for link in links:
if "index.php/" in link:
orgs += [link.split('"')[0]]
return orgs
# Collect software pages
resp = str(requests.get("https://bciwiki.org/index.php/Category:Software").content)
software = []
software += getLinks(resp)
outof = resp.split("out of ")[1]
outof = float(outof.split(" ")[0])
pagecount = outof/200
pagecount = math.ceil(pagecount)
nextpage = resp.split(') (<a href="')[1]
nextpage = nextpage.split('"')[0]
nextpage = nextpage.replace("amp;", "")
nextpage = nextpage.replace("amp%", "")
while pagecount > 1:
resp = str(requests.get("https://bciwiki.org"+nextpage).content)
software += getLinks(resp)
if ') (<a href="' in resp:
nextpage = resp.split(') (<a href="')[1]
nextpage = nextpage.split('"')[0]
nextpage = nextpage.replace("amp;", "")
nextpage = nextpage.replace("amp%", "")
pagecount -= 1
print("Software List Collected")
# Add categories to software pages
for a in range(0, len(software)):
if a % 25 == 0:
print(a)
name = software[a].split("/")[2]
resp = requests.get("https://bciwiki.org/index.php?title="+name.replace(" ", "_")+"&action=edit").text
if 'wpTextbox1">' in resp:
resp = resp.split('wpTextbox1">')[1]
resp = resp.split('</textarea>')[0]
resp = resp.replace("\\n", "\n")
newtext = resp
if "play.google.com" in resp and "Category:Play_Store_Apps" not in resp:
newtext = "[[Category:Play_Store_Apps]]\n"+newtext
if "apps.apple.com" in resp and "Category:App_Store_Apps" not in resp:
newtext = "[[Category:App_Store_Apps]]\n"+newtext
if "GitHub]" in resp and "Category:GitHub_Repos" not in resp:
newtext = "[[Category:GitHub_Repos]]\n"+newtext
requests.post("https://bciwiki.org/index.php?title="+name.replace(" ", "_")+"&action=submit", params={
"wpUnicodeCheck": open("unicode.txt", mode="r", encoding="utf-8").read(),
"wpSave": "Save changes",
"format": "text/x-wiki",
"model": "wikitext",
"editingStatsId": "",
"wpStarttime": "",
"wpEdittime": "",
"wpTextbox1": newtext,
"wpEditToken": edittoken,
"wpWatchthis": "",
"wpUltimateParam": "1",
"mode": "text"}, cookies={
"ls_smartpush": "1",
"mw_installer_session": "",
"u216253868_bciwiki_session": sessionid,
"u216253868_bciwikiToken": wikitoken,
"u216253868_bciwikiUserID": "1",
"u216253868_bciwikiUserName": "Landonodnal",
"VEE": "wikitext",
"wikiEditor-0-toolbar-section": "advanced"
}, headers={'Content-type': 'text/html; charset=utf-8'})
else:
print(name)
# Collect dev tool pages
resp = str(requests.get("https://bciwiki.org/index.php/Category:Developer_Tools").content)
devtools = getLinks(resp)
print("Developer Tools List Collected")
# Add categories to dev tool pages
for a in range(0, len(devtools)):
if a % 25 == 0:
print(a)
name = devtools[a].split("/")[2]
resp = requests.get("https://bciwiki.org/index.php?title="+name.replace(" ", "_")+"&action=edit").text
if 'wpTextbox1">' in resp:
resp = resp.split('wpTextbox1">')[1]
resp = resp.split('</textarea>')[0]
resp = resp.replace("\\n", "\n")
newtext = resp
if "play.google.com" in resp and "Category:Play_Store_Apps" not in resp:
newtext = "[[Category:Play_Store_Apps]]\n"+newtext
if "apps.apple.com" in resp and "Category:App_Store_Apps" not in resp:
newtext = "[[Category:App_Store_Apps]]\n"+newtext
if "GitHub]" in resp and "Category:GitHub_Repos" not in resp:
newtext = "[[Category:GitHub_Repos]]\n"+newtext
requests.post("https://bciwiki.org/index.php?title="+name.replace(" ", "_")+"&action=submit", params={
"wpUnicodeCheck": open("unicode.txt", mode="r", encoding="utf-8").read(),
"wpSave": "Save changes",
"format": "text/x-wiki",
"model": "wikitext",
"editingStatsId": "",
"wpStarttime": "",
"wpEdittime": "",
"wpTextbox1": newtext,
"wpEditToken": edittoken,
"wpWatchthis": "",
"wpUltimateParam": "1",
"mode": "text"}, cookies={
"ls_smartpush": "1",
"mw_installer_session": "",
"u216253868_bciwiki_session": sessionid,
"u216253868_bciwikiToken": wikitokenn,
"u216253868_bciwikiUserID": "1",
"u216253868_bciwikiUserName": "Landonodnal",
"VEE": "wikitext",
"wikiEditor-0-toolbar-section": "advanced"
}, headers={'Content-type': 'text/html; charset=utf-8'})
else:
print(name)