Created
November 9, 2016 04:33
-
-
Save devnoname120/066d6e6241083604e70b709eac464e34 to your computer and use it in GitHub Desktop.
Script that helped in changing the wiki.henkaku.xyz between Library and Module
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
#! /usr/bin/env python3 | |
import requests | |
import re | |
from bs4 import BeautifulSoup | |
def dicadd(dic, dic_add): | |
for key in dic_add: | |
dic[key] = dicadd[key] | |
baseURL = 'https://wiki.henkaku.xyz/' | |
with requests.Session() as session: | |
# Ignore SSL certificate errors, not a good idea | |
#session.verify = False | |
page = session.get("https://wiki.henkaku.xyz/vita/index.php?title=Special:UserLogin&returnto=Main+Page") | |
html = BeautifulSoup(page.text, 'html.parser') | |
wpLoginToken = html.find('input', attrs={'name':'wpLoginToken'})['value'] | |
#session.post("https://wiki.henkaku.xyz/vita/load.php?debug=false&lang=en&modules=mediawiki.htmlform.styles%7Cmediawiki.legacy.commonPrint%2Cshared%7Cmediawiki.sectionAnchor%2Cui%7Cmediawiki.skinning.interface%7Cmediawiki.special.userlogin.common.styles%7Cmediawiki.special.userlogin.login.styles%7Cmediawiki.ui.button%2Ccheckbox%2Cinput%2Cradio%7Cskins.vector.styles&only=styles&skin=vector", data=dicadd(basic_query_string[:], {}) | |
data = { | |
"wpName": YOURUSERNAMEHERE, | |
"wpPassword": YOURPASSWORDHERE, | |
"wpLoginAttempt": "Log in", | |
"wpEditToken": "+\\", | |
"title": "Special:UserLogin", | |
"authAction": "login", | |
"force": "", | |
"wpLoginToken": wpLoginToken, | |
"wpForceHttps": "1", | |
"wpFromhttp": "1" | |
} | |
session.post("https://wiki.henkaku.xyz/vita/index.php?title=Special:UserLogin&returnto=Main+Page", data=data) | |
page = session.get("https://wiki.henkaku.xyz/vita/Category:Libraries") | |
html = BeautifulSoup(page.text, 'html.parser') | |
articles = html.find(id='mw-pages').find('ul').find_all('li') | |
for article in articles: | |
href = baseURL + article.find('a')['href'] | |
page = session.get(href) | |
html = BeautifulSoup(page.text, 'html.parser') | |
edit = baseURL + html.find(id='ca-edit').find('a')['href'] | |
articlename = href.split('/')[-1] | |
page = session.get(edit) | |
html = BeautifulSoup(page.text, 'html.parser') | |
editform = html.find(id='editform') | |
submit = baseURL + editform['action'] | |
articletext = html.find(id='wpTextbox1').get_text() | |
articletextoriginal = articletext[:] | |
# Do the changes here | |
articletext = re.sub(r'== Library ==', '== Module ==', articletext) | |
articletext = re.sub(r'== Modules ==', '== Libraries ==', articletext) | |
articletext = re.sub(r'\[\[Category:Libraries\]\]', '[[Category:Modules]]', articletext) | |
modfind = re.findall(r"== Module ==", articletext) | |
if len(modfind) >= 2: | |
print('Warning, ' + articlename + ' contains more than 1 == Module ==", skipping...') | |
continue | |
if re.search(r"== Library ==", articletext): | |
print('Warning, ' + articlename + ' contains == Library == which should not exist anymore, skipping...') | |
continue | |
if re.search(r"[ .:(\n](?:module|library)[. :;)\n]", articletext): | |
print('Warning, ' + articlename + ' contains 1 or more unhandled text "module", skipping...') | |
continue | |
if articletext == articletextoriginal: | |
print(articlename + ' text unchanged, skipping...') | |
continue | |
multipart = { | |
'wpAntispam': ('', editform.find(id='wpAntispam')['value'], ''), | |
'editingStatsId': ('', editform.find('input', attrs={'name':'editingStatsId'})['value'], ''), | |
'wpSection': ('', editform.find('input', attrs={'name':'wpSection'})['value'], ''), | |
'wpStarttime': ('', editform.find('input', attrs={'name':'wpStarttime'})['value'], ''), | |
'wpEdittime': ('', editform.find('input', attrs={'name':'wpEdittime'})['value'], ''), | |
'wpScrolltop': ('', editform.find('input', attrs={'name':'wpScrolltop'})['value'], ''), | |
'wpAutoSummary': ('', editform.find('input', attrs={'name':'wpAutoSummary'})['value'], ''), | |
'oldid': ('', editform.find('input', attrs={'name':'oldid'})['value'], ''), | |
'parentRevId': ('', editform.find('input', attrs={'name':'parentRevId'})['value'], ''), | |
'format': ('', editform.find('input', attrs={'name':'format'})['value'], ''), | |
'model': ('', editform.find('input', attrs={'name':'model'})['value'], ''), | |
'wpTextbox1': ('', articletext, ''), | |
'wpSummary': ('', 'Swapped Module <-> Library, see revision 1.1 under "Revision History" of "Vita SDK specifications" (https://wiki.henkaku.xyz/vita/File:Vita_SDK_specifications.pdf)', ''), | |
'wpSave': ('', editform.find('input', attrs={'name':'wpSave'})['value'], ''), | |
'wpEditToken': ('', editform.find('input', attrs={'name':'wpEditToken'})['value'], ''), | |
'wpUltimateParam': ('', editform.find('input', attrs={'name':'wpUltimateParam'})['value'], '') | |
} | |
print('Submitting ' + articlename + '...') | |
session.post(submit, files=multipart) | |
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
beautifulsoup4==4.5.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment