Created
November 27, 2018 21:06
-
-
Save NanoSmasher/c50d9f033b43e7d08ddcdffc3b98b4a8 to your computer and use it in GitHub Desktop.
Very specific script to edit skill template information in mediawikis
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
import mwclient | |
from mwclient import Site | |
import pathlib | |
import configparser # reading config file | |
import base64 # encryption | |
import re | |
def main(): | |
# settings.ini file not found | |
if not pathlib.Path("settings.ini").is_file(): | |
print("settings.ini not found. Creating new file...") | |
new_settings() | |
print("reading settings.ini ...") | |
# reading settings.ini file | |
config = configparser.ConfigParser() | |
config.read('settings.ini') | |
DEBUG = config['DEFAULT'].getboolean('debug',False) # enable/[disable] debug messages | |
# optional decryption | |
p = "" | |
if config['DEFAULT'].getboolean('encrypt',False): | |
p = getpass.getpass("Client information is encrpyted. Please enter password: ") | |
# start | |
print('ready') | |
database = getdb() | |
#with open('unicorn.txt', 'r', encoding="utf-8") as myfile: | |
# data=myfile.read() | |
site = mwclient.Site('azurlane.koumakan.jp') | |
site.login(decode(p,config['DEFAULT'].get('user')), decode(p,config['DEFAULT'].get('pass'))) | |
changes = 0 | |
for datapoint in database: | |
changes = 0 | |
print('now reading: '+datapoint) | |
page = site.pages[datapoint] | |
if not page.exists: | |
print('Page '+page+' does not exist') | |
continue | |
if not page.can('edit'): | |
print('Page '+page+' can not be edited') | |
continue | |
print('Opening Page for editing') | |
#Get Text | |
text = page.text() | |
#Go through all skills | |
for num in [1,2,3,4]: | |
r = re.search('(Skill'+str(num)+') *= *(.*)',text) | |
if r is None: | |
print('Skill'+str(num)+'not found') | |
continue | |
name = r.group(2) | |
print('Skill '+str(num)+' is '+name) | |
if name == 'All Out Assault' or name == 'Full Barrage': | |
print('Omitting barrage skill icon') | |
continue | |
if name == '--' or name == '-' or name == '' or name == ' ' or name == ' ': | |
print('Omitting empty Skill') | |
continue | |
rI = re.search('(Skill'+str(num)+'Icon) *= *(.*)',text) | |
n = getSkillIconNumber(datapoint,num) | |
if rI is None: #no SkillIcon found | |
print('SkillIcon not found, approve the following:') | |
print('\tSkill: '+name) | |
print('\tSkillIcon: '+str(n)) | |
ans = input('[y/N]:') | |
if ans == 'y': | |
text = re.sub('(Skill'+str(num)+') *= *(.*)','\g<1> = \g<2>\n | Skill'+str(num)+'Icon = '+str(n),text) | |
changes = 1 | |
else: | |
if rI.group(1) == '': | |
print('SkillIcon empty, approve the following:') | |
print('\tSkill: '+name) | |
print('\tSkillIcon: '+str(n)) | |
ans = input('[y/N]:') | |
if ans == 'y': | |
text = re.sub('(Skill'+str(num)+'Icon) *= *(.*)','\g<1> = '+str(n),text) | |
changes = 1 | |
else: | |
ans = input('SkillIcon found as '+rI.group(2)+'. Replace with '+str(n)+'? [y/N]:') | |
if ans == 'y': | |
text = re.sub('(Skill'+str(num)+'Icon) *= *(.*)','\g<1> = '+str(n),text) | |
print('SkillIcon updated') | |
changes = 1 | |
if changes: | |
## #save(text, summary=u'SkillIcon update', minor=False, bot=True, section=None, **kwargs) | |
page.save(text, summary=u'added SkillIcon', minor=False, bot=True) | |
print('Changes Saved') | |
input("Press Enter to continue...") | |
exit() | |
def encode(key, clear): | |
""" Vigenere cipher encoder """ | |
if not len(key): return clear | |
enc = [] | |
for i in range(len(clear)): | |
key_c = key[i % len(key)] | |
enc_c = chr((ord(clear[i]) + ord(key_c)) % 256) | |
enc.append(enc_c) | |
return base64.b64encode("".join(enc).encode()).decode() | |
def decode(key, enc): | |
""" Vigenere cipher decoder """ | |
if not len(key): return enc | |
dec = [] | |
enc = base64.b64decode(enc).decode() | |
for i in range(len(enc)): | |
key_c = key[i % len(key)] | |
dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256) | |
dec.append(dec_c) | |
return "".join(dec) | |
def new_settings(): | |
""" Creates settings.ini with the following information: | |
Username | |
Password | |
Optional Encrpytion of the above credentials | |
""" | |
config = configparser.ConfigParser() | |
config['DEFAULT'] = {} | |
config['DEFAULT']['debug'] = '0' | |
config['DEFAULT']['encrypt'] = '0' | |
config['DEFAULT']['user'] = input("Username: ") | |
config['DEFAULT']['pass'] = input("Password: ") | |
while True: | |
a = input("Do you want to encrypt your settings.ini file? [Y/n]: ") | |
if a in ['Y','y','N','n','']: break | |
print("invalid response") | |
if a in ['Y','y','']: | |
p = getpass.getpass("Enter password to use: ") | |
config['DEFAULT']['user'] = encode(p,config['DEFAULT']['user']) | |
config['DEFAULT']['pass'] = encode(p,config['DEFAULT']['pass']) | |
config['DEFAULT']['encrypt'] = 1 | |
with open('settings.ini', 'w') as cf: | |
config.write(cf) | |
def getdb(): | |
d = { | |
"Universal Bullin": [14], | |
"Trial Bullin MKII": [15], | |
"Cassin": [10010, 20021, 20022], | |
"Downes": [10010, 20021, 20022], | |
"Gridley": [1011, 2051, 20031, 20032], | |
"Craven": [2051, 20031, 20032], | |
"McCall": [2051, 20031, 20032], | |
"Maury": [10020, 2051, 20031, 20032], | |
"Fletcher": [10030, 1051, 20041, 20042], | |
"Charles Ausburne": [10040, 2011, 20041, 20042], | |
"Thatcher": [2011, 20041, 20042], | |
"Aulick": [2001, 20041, 20042], | |
"Foote": [2001, 20041, 20042], | |
"Spence": [2001, 20041, 20042], | |
"Benson": [1081, 20061, 20062], | |
"Laffey": [10410, 29051, 29052], | |
"Sims": [1001, 20051, 20052], | |
"Hammann": [10400, 20051, 20052], | |
"Eldridge": [10050, 29021, 29022], | |
"Bailey": [4081, 20061, 20062], | |
"Radford": [2011, 20041, 20042], | |
"Jenkins": [2011, 20041, 20042], | |
"Nicholas": [10750, 2011, 11480], #replaced 20041, 20042 | |
"Omaha": [2001, 20111, 20112], | |
"Raleigh": [2001, 20111, 20112], | |
"Brooklyn": [1002, 20121, 20122], | |
"Phoenix": [10060, 20121, 20122], | |
"Helena": [10070, 20121, 20122], | |
"Atlanta": [1042, 4091, 20131, 20132], | |
"Juneau": [10080, 4091, 20131, 20132], | |
"San Diego": [10090, 20131, 20132], | |
"Cleveland": [2031, 4091, 20141, 20142], | |
"Columbia": [5051, 4091, 20141, 20142], | |
"Richmond": [1002, 20111, 20112], | |
"Honolulu": [2011, 20121, 20122], | |
"St. Louis": [10880, 4091, 20121, 20122], | |
"Montpelier": [11200, 4091, 20141, 20142], | |
"Denver": [2011, 4091, 20141, 20142], | |
"Pensacola": [2021, 20211, 20212], | |
"Salt Lake City": [2011, 20211, 20212], | |
"Northampton": [1002, 20221, 20222], | |
"Chicago": [2041, 20221, 20222], | |
"Houston": [10100, 20221, 20222], | |
"Portland": [10110, 4011, 20231, 20232], | |
"Indianapolis": [10120, 4021, 20231, 20232], | |
"Astoria": [11470, 4121, 20241, 20242], | |
"Quincy": [2011, 4121, 20241, 20242], | |
"Vincennes": [2011, 4121, 20241, 20242], | |
"Wichita": [1002, 2061, 20251, 20252], | |
"Nevada": [4021,2040], #added 2040 | |
"Oklahoma": [4021,2040], #added 2040 | |
"Pennsylvania": [10130], | |
"Arizona": [10140], | |
"Tennessee": [10150], | |
"California": [2041], | |
"South Dakota": [10160, 2041], | |
"Massachusetts": [11550, 11560], | |
"Long Island": [3001, 3040], #added 3040 | |
"Bogue": [3001, 1040], #added 1040 | |
"Langley": [10170, 1030], #added 1030 | |
"Lexington": [10180, 3021], | |
"Saratoga": [10180, 3021, 11400], #added 11400 | |
"Ranger": [3001, 3010], #added 3010 | |
"Yorktown": [10190, 3021], | |
"Enterprise": [10200], | |
"Hornet": [10210, 3011], | |
"Dace": [3581, 3511, 20311, 20312], | |
"Vestal": [10220, 10520, 10521, 10522], | |
"Amazon": [10230, 21011, 21012], | |
"Acasta": [10840, 4081, 21011, 21012], | |
"Ardent": [5021, 5001, 21011, 21012], | |
"Beagle": [4071, 21021, 21022], | |
"Bulldog": [4071, 21021, 21022], | |
"Comet": [1011, 21031, 21032], | |
"Crescent": [4071, 21031, 21032], | |
"Cygnet": [4071, 21031, 21032], | |
"Foxhound": [1031, 21041, 21042], | |
"Fortune": [4071, 21041, 21042], | |
"Glowworm": [10240, 4071, 29061, 29062], | |
"Javelin": [10250, 29081, 29082], | |
"Juno": [4081, 21071, 21072], | |
"Vampire": [10580, 29091, 29092], | |
"Jupiter": [5031, 21071, 21072], | |
"Matchless": [2121, 5001, 21081, 21082], | |
"Musketeer": [11180, 21081, 21082], | |
"Leander": [1002, 21111, 21112], | |
"Achilles": [2011, 21111, 21112], | |
"Ajax": [2011, 21111, 21112], | |
"Sheffield": [11140, 11150, 21151, 21152], | |
"Edinburgh": [2081, 21141, 21142], | |
"Belfast": [10610, 4101, 29101, 29102], | |
"Arethusa": [2021, 21131, 21132], | |
"Galatea": [2011, 21131, 21132], | |
"Aurora": [11080, 11090, 21131, 21132], | |
"Fiji": [11160, 21161, 21162], | |
"Jamaica": [11170, 21161, 21162], | |
"Belchan": [11280, 11290, 21141, 21142], | |
"London": [1004, 21211, 21212], | |
"Shropshire": [2061, 21211, 21212], | |
"Kent": [2031, 21221, 21222], | |
"Suffolk": [2061, 21221, 21222], | |
"Norfolk": [4051, 21231, 21232], | |
"Dorsetshire": [10560, 21231, 21232], | |
"York": [10260, 21241, 21242], | |
"Exeter": [2011, 4011, 21241, 21242], | |
"Sussex": [2061, 21211, 21212], | |
"Renown": [10270], | |
"Repulse": [10280], | |
"Hood": [10290], | |
"Queen Elizabeth": [10300], | |
"Warspite": [10310], | |
"Nelson": [10320], | |
"Rodney": [10320], | |
"Prince of Wales": [10540], | |
"Duke of York": [11100, 11110], | |
"Hermes": [3011], | |
"Unicorn": [3031, 1034], | |
"Centaur": [11580, 11590], | |
"Ark Royal": [10330, 3011], | |
"Illustrious": [10340], | |
"Victorious": [11120, 3011], | |
"Glorious": [3021, 3051], | |
"Erebus": [10350], | |
"Terror": [10350], | |
"Abercrombie": [11300], | |
"Fubuki": [10960, 22021, 22022], | |
"Ayanami": [10730, 29111, 29112], | |
"Akatsuki": [10770, 22071, 22072], | |
"Ikazuchi": [10620, 22071, 22072], | |
"Inazuma": [10630, 22071, 22072], | |
"Shiratsuyu": [1013, 22031, 22032], | |
"Yuudachi": [10360, 29121, 29122], | |
"Shigure": [10370, 22031, 22032], | |
"Yukikaze": [11230, 11240, 29131, 29132], | |
"Kagerou": [1013, 2051, 22051, 22052], | |
"Shiranui": [2051, 22051, 22052], | |
"Nowaki": [10780, 22051, 22052], | |
"Hatsuharu": [2051, 22041, 22042], | |
"Wakaba": [2051, 22041, 22042], | |
"Hatsushimo": [2051, 22041, 22042], | |
"Ariake": [2051, 22041, 22042], | |
"Yuugure": [5021, 22041, 22042], | |
"Kuroshio": [2011, 2051, 22051, 22052], | |
"Oyashio": [2011, 2051, 22051, 22052], | |
"Kamikaze": [10740, 22081, 22082], | |
"Matsukaze": [2001, 22081, 22082], | |
"Mutsuki": [2001, 22011, 22012], | |
"Kisaragi": [2001, 22011, 22012], | |
"Uzuki": [2001, 22011, 22012], | |
"Minazuki": [2001, 22011, 22012], | |
"Fumizuki": [2001, 22011, 22012], | |
"Mikazuki": [2001, 22011, 22012], | |
"Kawakaze": [11360, 2151, 29281, 29282], | |
"Niizuki": [2021, 4091, 22061, 22062], | |
"Harutsuki": [2131, 22061, 22062], | |
"Yoizuki": [2131, 22061, 22062], | |
"Urakaze": [10900, 22051, 22052], | |
"Isokaze": [11190, 22051, 22052], | |
"Hamakaze": [10900, 22051, 22052], | |
"Tanikaze": [11030, 22051, 22052], | |
"Asashio": [11350, 2141, 22091, 22092], | |
"Ooshio": [2141, 22091, 22092], | |
"Yuubari": [10590, 2011, 22161, 22162], | |
"Nagara": [2011, 22141, 22142], | |
"Isuzu": [4091, 22141, 22142], | |
"Abukuma": [1011, 22141, 22142], | |
"Mogami": [2011, 4111, 11220], #originally 22251, 22252, 22253 | |
"Mikuma": [5021, 4111, 22251, 22252], | |
"Sendai": [1091, 5040, 22132], #changed | |
"Jintsuu": [10870, 22131, 22132], | |
"Agano": [1001, 5021, 22151, 22152], | |
"Furutaka": [2011, 22211, 22212], | |
"Kako": [2011, 22211, 22212], | |
"Aoba": [2011, 22221, 22222], | |
"Kinugasa": [2011, 22221, 22222], | |
"Myoukou": [4041, 22231, 22232], | |
"Nachi": [4041, 22231, 22232], | |
"Takao": [2041, 2051, 22261, 22262], | |
"Atago": [10570, 2051, 22261, 22262], | |
"Maya": [10600, 22261, 22262], | |
"Choukai": [11250, 2041, 22261, 22262], | |
"Kongou": [11330], | |
"Hiei": [10930], | |
"Haruna": [11340], | |
"Kirishima": [11270], | |
"Fusou": [2071, 10830], | |
"Yamashiro": [2071, 10830], | |
"Ise": [2071, 11610], #added 11610 | |
"Hyuuga": [1005, 2071, 11600], #added 11600 | |
"Nagato": [11310, 11420], | |
"Mutsu": [11430], | |
"Mikasa": [10910, 10920], | |
"Hiyou": [11260], | |
"Junyou": [11260], | |
"Houshou": [10170, 3041], | |
"Shouhou": [3031, 3040], #added 3040 | |
"Akagi": [10420, 10430], | |
"Kaga": [10420, 10440], | |
"Souryuu": [3021, 10460], | |
"Hiryuu": [10450, 10470], | |
"Shoukaku": [10790, 10810], | |
"Zuikaku": [10800, 10820], | |
"I-19": [11370, 3531, 29261, 29262], | |
"I-26": [3591, 3511, 22311, 22312], | |
"I-58": [11380, 22311, 22312], | |
"Akashi": [10550, 1034, 10520, 10521, 10522], | |
"Z1": [10380, 29171, 29172], | |
"Z18": [2081, 23031, 23032], | |
"Z19": [2081, 23031, 23032], | |
"Z20": [2081, 23031, 23032], | |
"Z21": [2081, 23031, 23032], | |
"Z23": [10530, 29201, 29202], | |
"Z25": [2011, 5051, 23041, 23042], | |
"Z35": [11450, 23051, 23052], | |
"Z46": [10640, 2081, 29211, 29212], | |
"Königsberg": [1032, 23111, 23112], | |
"Karlsruhe": [2011, 23111, 23112], | |
"Köln": [2011, 23111, 23112], | |
"Leipzig": [1052, 23121, 23122], | |
"Admiral Hipper": [10720, 4021, 23211, 23212], | |
"Prinz Eugen": [10390, 23211, 23212], | |
"Deutschland": [10650, 23221, 23222], | |
"Admiral Graf.Spee": [10650, 23221, 23222], | |
"Scharnhorst": [10660, 2101], | |
"Gneisenau": [10700, 2101], | |
"Tirpitz": [10670, 2091], | |
"Graf Zeppelin": [10680, 10690], | |
"U-81": [11390, 11410, 29271, 29272], | |
"U-47": [11440, 11460, 29311, 29312], | |
"U-557": [3571, 3611, 23311, 23312], | |
"An Shan": [11040, 24011, 24012], | |
"Fu Shun": [11050, 24011, 24012], | |
"Chang Chun": [11060, 24011, 24012], | |
"Tai Yuan": [11070, 24011, 24012], | |
"Yat Sen": [10760, 10500, 24121, 24122], | |
"Ning Hai": [10480, 10500, 24111, 24112], | |
"Ping Hai": [10490, 10500, 24111, 24112], | |
"Avrora": [10510, 29191, 29192], | |
"Le Triomphant": [11500, 11510, 29331, 29332], | |
"Forbin": [5071, 28011, 28012], | |
"Emile Bertin": [11520, 5061, 28111, 28112], | |
"Surcouf": [11570, 3521, 29321, 29322], | |
"Le Mars": [5081, 28011, 28012], | |
"Dunkerque": [11490], | |
"Jean Bart": [11530, 11540], | |
"HDN Neptune": [101010], | |
"Noire": [101020], | |
"Blanc": [101030], | |
"Vert": [101040], | |
"Purple Heart": [101050, 101060, 101070], | |
"Black Heart": [101080, 101090], | |
"White Heart": [101100, 101110], | |
"Green Heart": [101120, 101130], | |
"HMS Neptune": [19010, 19020, 19000, 29231, 19001, 19002, 29232], | |
"Monarch": [19030, 19040, 19000, 19001, 19002], | |
"Ibuki": [19050, 19060, 19000, 29221, 19001, 19002, 29222], | |
"Izumo": [19070, 19080, 19000, 19001, 19002], | |
"Roon": [19090, 19100, 19000, 29241, 19001, 19002, 29242], | |
"Saint Louis": [19110, 19120, 19000, 29251, 19001, 19002, 29252], | |
"Bush": [2171, 20041, 20042], | |
"Colorado": [10320], | |
"Maryland": [10320, 10970], | |
"West Virginia": [10320], | |
"North Carolina": [10980, 10990], | |
"Washington": [11000, 11010], | |
"Wasp": [11020], | |
"Jersey": [10850, 21071, 21072], | |
"Michishio": [5031, 22091, 22092], | |
"Arashio": [22091, 22092], | |
"22": [102020, 29291, 29292], | |
"33": [102010, 29301, 29302], | |
"Taihou": [11620, 11630], | |
"Essex": [11640, 11650,11660], | |
"Albacore": [11670, 11680, 29340], | |
"Le Temeraire": [11700, 4140] | |
} | |
return d | |
def getSkillIconNumber(name,num): | |
database = getdb() | |
misc = { | |
"20021": 2000, | |
"22051": 2120, | |
"28011": 4070, | |
"29111": 10940, | |
"21011": 1080, | |
"23111": 2110, | |
"22081": 11130, | |
"21111": 10710, | |
"24111": 10950, | |
"21041": 1060, | |
"22082": 11130, | |
"22131": 10890, | |
"20061": 5000, | |
"20051": 4090, | |
"21031": 4080, | |
"21221": 2010, | |
"22141": 2050, | |
"21241": 10710, | |
"22211": 2050, | |
"22052": 5020, | |
"22011": 1010 | |
} | |
if name not in database: | |
return '' | |
if len(database[name]) < num: | |
return '' | |
snum = database[name][num-1] | |
if str(snum) in misc: | |
return misc[str(snum)] | |
elif snum > 100: | |
return snum - snum % 10 #replace last digit | |
else: | |
return snum | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment