Guest User

Untitled

a guest
Nov 27th, 2018
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.26 KB | None | 0 0
  1. import mwclient
  2. from mwclient import Site
  3. import pathlib
  4. import configparser # reading config file
  5. import base64 # encryption
  6. import re
  7.  
  8. def main():
  9. # settings.ini file not found
  10. if not pathlib.Path("settings.ini").is_file():
  11. print("settings.ini not found. Creating new file...")
  12. new_settings()
  13.  
  14. print("reading settings.ini ...")
  15.  
  16. # reading settings.ini file
  17. config = configparser.ConfigParser()
  18. config.read('settings.ini')
  19. DEBUG = config['DEFAULT'].getboolean('debug',False) # enable/[disable] debug messages
  20.  
  21. # optional decryption
  22. p = ""
  23. if config['DEFAULT'].getboolean('encrypt',False):
  24. p = getpass.getpass("Client information is encrpyted. Please enter password: ")
  25.  
  26. # start
  27. print('ready')
  28. database = getdb()
  29.  
  30. #with open('unicorn.txt', 'r', encoding="utf-8") as myfile:
  31. # data=myfile.read()
  32.  
  33. site = mwclient.Site('azurlane.koumakan.jp')
  34. site.login(decode(p,config['DEFAULT'].get('user')), decode(p,config['DEFAULT'].get('pass')))
  35.  
  36. changes = 0
  37. for datapoint in database:
  38. changes = 0
  39. print('now reading: '+datapoint)
  40. page = site.pages[datapoint]
  41.  
  42. if not page.exists:
  43. print('Page '+page+' does not exist')
  44. continue
  45. if not page.can('edit'):
  46. print('Page '+page+' can not be edited')
  47. continue
  48.  
  49. print('Opening Page for editing')
  50. #Get Text
  51. text = page.text()
  52.  
  53. #Go through all skills
  54. for num in [1,2,3,4]:
  55. r = re.search('(Skill'+str(num)+') *= *(.*)',text)
  56. if r is None:
  57. print('Skill'+str(num)+'not found')
  58. continue
  59. name = r.group(2)
  60. print('Skill '+str(num)+' is '+name)
  61. if name == 'All Out Assault' or name == 'Full Barrage':
  62. print('Omitting barrage skill icon')
  63. continue
  64. if name == '--' or name == '-' or name == '' or name == ' ' or name == ' ':
  65. print('Omitting empty Skill')
  66. continue
  67.  
  68. rI = re.search('(Skill'+str(num)+'Icon) *= *(.*)',text)
  69. n = getSkillIconNumber(datapoint,num)
  70. if rI is None: #no SkillIcon found
  71. print('SkillIcon not found, approve the following:')
  72. print('\tSkill: '+name)
  73. print('\tSkillIcon: '+str(n))
  74. ans = input('[y/N]:')
  75. if ans == 'y':
  76. text = re.sub('(Skill'+str(num)+') *= *(.*)','\g<1> = \g<2>\n | Skill'+str(num)+'Icon = '+str(n),text)
  77. changes = 1
  78. else:
  79. if rI.group(1) == '':
  80. print('SkillIcon empty, approve the following:')
  81. print('\tSkill: '+name)
  82. print('\tSkillIcon: '+str(n))
  83. ans = input('[y/N]:')
  84. if ans == 'y':
  85. text = re.sub('(Skill'+str(num)+'Icon) *= *(.*)','\g<1> = '+str(n),text)
  86. changes = 1
  87. else:
  88. ans = input('SkillIcon found as '+rI.group(2)+'. Replace with '+str(n)+'? [y/N]:')
  89. if ans == 'y':
  90. text = re.sub('(Skill'+str(num)+'Icon) *= *(.*)','\g<1> = '+str(n),text)
  91. print('SkillIcon updated')
  92. changes = 1
  93.  
  94. if changes:
  95. ## #save(text, summary=u'SkillIcon update', minor=False, bot=True, section=None, **kwargs)
  96. page.save(text, summary=u'added SkillIcon', minor=False, bot=True)
  97. print('Changes Saved')
  98.  
  99. input("Press Enter to continue...")
  100. exit()
  101.  
  102. def encode(key, clear):
  103. """ Vigenere cipher encoder """
  104. if not len(key): return clear
  105. enc = []
  106. for i in range(len(clear)):
  107. key_c = key[i % len(key)]
  108. enc_c = chr((ord(clear[i]) + ord(key_c)) % 256)
  109. enc.append(enc_c)
  110. return base64.b64encode("".join(enc).encode()).decode()
  111.  
  112. def decode(key, enc):
  113. """ Vigenere cipher decoder """
  114. if not len(key): return enc
  115. dec = []
  116. enc = base64.b64decode(enc).decode()
  117. for i in range(len(enc)):
  118. key_c = key[i % len(key)]
  119. dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256)
  120. dec.append(dec_c)
  121. return "".join(dec)
  122.  
  123. def new_settings():
  124. """ Creates settings.ini with the following information:
  125.  
  126. Username
  127. Password
  128. Optional Encrpytion of the above credentials
  129. """
  130. config = configparser.ConfigParser()
  131. config['DEFAULT'] = {}
  132. config['DEFAULT']['debug'] = '0'
  133. config['DEFAULT']['encrypt'] = '0'
  134. config['DEFAULT']['user'] = input("Username: ")
  135. config['DEFAULT']['pass'] = input("Password: ")
  136. while True:
  137. a = input("Do you want to encrypt your settings.ini file? [Y/n]: ")
  138. if a in ['Y','y','N','n','']: break
  139. print("invalid response")
  140. if a in ['Y','y','']:
  141. p = getpass.getpass("Enter password to use: ")
  142. config['DEFAULT']['user'] = encode(p,config['DEFAULT']['user'])
  143. config['DEFAULT']['pass'] = encode(p,config['DEFAULT']['pass'])
  144. config['DEFAULT']['encrypt'] = 1
  145. with open('settings.ini', 'w') as cf:
  146. config.write(cf)
  147.  
  148. def getdb():
  149. d = {
  150. "Universal Bullin": [14],
  151. "Trial Bullin MKII": [15],
  152. "Cassin": [10010, 20021, 20022],
  153. "Downes": [10010, 20021, 20022],
  154. "Gridley": [1011, 2051, 20031, 20032],
  155. "Craven": [2051, 20031, 20032],
  156. "McCall": [2051, 20031, 20032],
  157. "Maury": [10020, 2051, 20031, 20032],
  158. "Fletcher": [10030, 1051, 20041, 20042],
  159. "Charles Ausburne": [10040, 2011, 20041, 20042],
  160. "Thatcher": [2011, 20041, 20042],
  161. "Aulick": [2001, 20041, 20042],
  162. "Foote": [2001, 20041, 20042],
  163. "Spence": [2001, 20041, 20042],
  164. "Benson": [1081, 20061, 20062],
  165. "Laffey": [10410, 29051, 29052],
  166. "Sims": [1001, 20051, 20052],
  167. "Hammann": [10400, 20051, 20052],
  168. "Eldridge": [10050, 29021, 29022],
  169. "Bailey": [4081, 20061, 20062],
  170. "Radford": [2011, 20041, 20042],
  171. "Jenkins": [2011, 20041, 20042],
  172. "Nicholas": [10750, 2011, 11480], #replaced 20041, 20042
  173. "Omaha": [2001, 20111, 20112],
  174. "Raleigh": [2001, 20111, 20112],
  175. "Brooklyn": [1002, 20121, 20122],
  176. "Phoenix": [10060, 20121, 20122],
  177. "Helena": [10070, 20121, 20122],
  178. "Atlanta": [1042, 4091, 20131, 20132],
  179. "Juneau": [10080, 4091, 20131, 20132],
  180. "San Diego": [10090, 20131, 20132],
  181. "Cleveland": [2031, 4091, 20141, 20142],
  182. "Columbia": [5051, 4091, 20141, 20142],
  183. "Richmond": [1002, 20111, 20112],
  184. "Honolulu": [2011, 20121, 20122],
  185. "St. Louis": [10880, 4091, 20121, 20122],
  186. "Montpelier": [11200, 4091, 20141, 20142],
  187. "Denver": [2011, 4091, 20141, 20142],
  188. "Pensacola": [2021, 20211, 20212],
  189. "Salt Lake City": [2011, 20211, 20212],
  190. "Northampton": [1002, 20221, 20222],
  191. "Chicago": [2041, 20221, 20222],
  192. "Houston": [10100, 20221, 20222],
  193. "Portland": [10110, 4011, 20231, 20232],
  194. "Indianapolis": [10120, 4021, 20231, 20232],
  195. "Astoria": [11470, 4121, 20241, 20242],
  196. "Quincy": [2011, 4121, 20241, 20242],
  197. "Vincennes": [2011, 4121, 20241, 20242],
  198. "Wichita": [1002, 2061, 20251, 20252],
  199. "Nevada": [4021,2040], #added 2040
  200. "Oklahoma": [4021,2040], #added 2040
  201. "Pennsylvania": [10130],
  202. "Arizona": [10140],
  203. "Tennessee": [10150],
  204. "California": [2041],
  205. "South Dakota": [10160, 2041],
  206. "Massachusetts": [11550, 11560],
  207. "Long Island": [3001, 3040], #added 3040
  208. "Bogue": [3001, 1040], #added 1040
  209. "Langley": [10170, 1030], #added 1030
  210. "Lexington": [10180, 3021],
  211. "Saratoga": [10180, 3021, 11400], #added 11400
  212. "Ranger": [3001, 3010], #added 3010
  213. "Yorktown": [10190, 3021],
  214. "Enterprise": [10200],
  215. "Hornet": [10210, 3011],
  216. "Dace": [3581, 3511, 20311, 20312],
  217. "Vestal": [10220, 10520, 10521, 10522],
  218. "Amazon": [10230, 21011, 21012],
  219. "Acasta": [10840, 4081, 21011, 21012],
  220. "Ardent": [5021, 5001, 21011, 21012],
  221. "Beagle": [4071, 21021, 21022],
  222. "Bulldog": [4071, 21021, 21022],
  223. "Comet": [1011, 21031, 21032],
  224. "Crescent": [4071, 21031, 21032],
  225. "Cygnet": [4071, 21031, 21032],
  226. "Foxhound": [1031, 21041, 21042],
  227. "Fortune": [4071, 21041, 21042],
  228. "Glowworm": [10240, 4071, 29061, 29062],
  229. "Javelin": [10250, 29081, 29082],
  230. "Juno": [4081, 21071, 21072],
  231. "Vampire": [10580, 29091, 29092],
  232. "Jupiter": [5031, 21071, 21072],
  233. "Matchless": [2121, 5001, 21081, 21082],
  234. "Musketeer": [11180, 21081, 21082],
  235. "Leander": [1002, 21111, 21112],
  236. "Achilles": [2011, 21111, 21112],
  237. "Ajax": [2011, 21111, 21112],
  238. "Sheffield": [11140, 11150, 21151, 21152],
  239. "Edinburgh": [2081, 21141, 21142],
  240. "Belfast": [10610, 4101, 29101, 29102],
  241. "Arethusa": [2021, 21131, 21132],
  242. "Galatea": [2011, 21131, 21132],
  243. "Aurora": [11080, 11090, 21131, 21132],
  244. "Fiji": [11160, 21161, 21162],
  245. "Jamaica": [11170, 21161, 21162],
  246. "Belchan": [11280, 11290, 21141, 21142],
  247. "London": [1004, 21211, 21212],
  248. "Shropshire": [2061, 21211, 21212],
  249. "Kent": [2031, 21221, 21222],
  250. "Suffolk": [2061, 21221, 21222],
  251. "Norfolk": [4051, 21231, 21232],
  252. "Dorsetshire": [10560, 21231, 21232],
  253. "York": [10260, 21241, 21242],
  254. "Exeter": [2011, 4011, 21241, 21242],
  255. "Sussex": [2061, 21211, 21212],
  256. "Renown": [10270],
  257. "Repulse": [10280],
  258. "Hood": [10290],
  259. "Queen Elizabeth": [10300],
  260. "Warspite": [10310],
  261. "Nelson": [10320],
  262. "Rodney": [10320],
  263. "Prince of Wales": [10540],
  264. "Duke of York": [11100, 11110],
  265. "Hermes": [3011],
  266. "Unicorn": [3031, 1034],
  267. "Centaur": [11580, 11590],
  268. "Ark Royal": [10330, 3011],
  269. "Illustrious": [10340],
  270. "Victorious": [11120, 3011],
  271. "Glorious": [3021, 3051],
  272. "Erebus": [10350],
  273. "Terror": [10350],
  274. "Abercrombie": [11300],
  275. "Fubuki": [10960, 22021, 22022],
  276. "Ayanami": [10730, 29111, 29112],
  277. "Akatsuki": [10770, 22071, 22072],
  278. "Ikazuchi": [10620, 22071, 22072],
  279. "Inazuma": [10630, 22071, 22072],
  280. "Shiratsuyu": [1013, 22031, 22032],
  281. "Yuudachi": [10360, 29121, 29122],
  282. "Shigure": [10370, 22031, 22032],
  283. "Yukikaze": [11230, 11240, 29131, 29132],
  284. "Kagerou": [1013, 2051, 22051, 22052],
  285. "Shiranui": [2051, 22051, 22052],
  286. "Nowaki": [10780, 22051, 22052],
  287. "Hatsuharu": [2051, 22041, 22042],
  288. "Wakaba": [2051, 22041, 22042],
  289. "Hatsushimo": [2051, 22041, 22042],
  290. "Ariake": [2051, 22041, 22042],
  291. "Yuugure": [5021, 22041, 22042],
  292. "Kuroshio": [2011, 2051, 22051, 22052],
  293. "Oyashio": [2011, 2051, 22051, 22052],
  294. "Kamikaze": [10740, 22081, 22082],
  295. "Matsukaze": [2001, 22081, 22082],
  296. "Mutsuki": [2001, 22011, 22012],
  297. "Kisaragi": [2001, 22011, 22012],
  298. "Uzuki": [2001, 22011, 22012],
  299. "Minazuki": [2001, 22011, 22012],
  300. "Fumizuki": [2001, 22011, 22012],
  301. "Mikazuki": [2001, 22011, 22012],
  302. "Kawakaze": [11360, 2151, 29281, 29282],
  303. "Niizuki": [2021, 4091, 22061, 22062],
  304. "Harutsuki": [2131, 22061, 22062],
  305. "Yoizuki": [2131, 22061, 22062],
  306. "Urakaze": [10900, 22051, 22052],
  307. "Isokaze": [11190, 22051, 22052],
  308. "Hamakaze": [10900, 22051, 22052],
  309. "Tanikaze": [11030, 22051, 22052],
  310. "Asashio": [11350, 2141, 22091, 22092],
  311. "Ooshio": [2141, 22091, 22092],
  312. "Yuubari": [10590, 2011, 22161, 22162],
  313. "Nagara": [2011, 22141, 22142],
  314. "Isuzu": [4091, 22141, 22142],
  315. "Abukuma": [1011, 22141, 22142],
  316. "Mogami": [2011, 4111, 11220], #originally 22251, 22252, 22253
  317. "Mikuma": [5021, 4111, 22251, 22252],
  318. "Sendai": [1091, 5040, 22132], #changed
  319. "Jintsuu": [10870, 22131, 22132],
  320. "Agano": [1001, 5021, 22151, 22152],
  321. "Furutaka": [2011, 22211, 22212],
  322. "Kako": [2011, 22211, 22212],
  323. "Aoba": [2011, 22221, 22222],
  324. "Kinugasa": [2011, 22221, 22222],
  325. "Myoukou": [4041, 22231, 22232],
  326. "Nachi": [4041, 22231, 22232],
  327. "Takao": [2041, 2051, 22261, 22262],
  328. "Atago": [10570, 2051, 22261, 22262],
  329. "Maya": [10600, 22261, 22262],
  330. "Choukai": [11250, 2041, 22261, 22262],
  331. "Kongou": [11330],
  332. "Hiei": [10930],
  333. "Haruna": [11340],
  334. "Kirishima": [11270],
  335. "Fusou": [2071, 10830],
  336. "Yamashiro": [2071, 10830],
  337. "Ise": [2071, 11610], #added 11610
  338. "Hyuuga": [1005, 2071, 11600], #added 11600
  339. "Nagato": [11310, 11420],
  340. "Mutsu": [11430],
  341. "Mikasa": [10910, 10920],
  342. "Hiyou": [11260],
  343. "Junyou": [11260],
  344. "Houshou": [10170, 3041],
  345. "Shouhou": [3031, 3040], #added 3040
  346. "Akagi": [10420, 10430],
  347. "Kaga": [10420, 10440],
  348. "Souryuu": [3021, 10460],
  349. "Hiryuu": [10450, 10470],
  350. "Shoukaku": [10790, 10810],
  351. "Zuikaku": [10800, 10820],
  352. "I-19": [11370, 3531, 29261, 29262],
  353. "I-26": [3591, 3511, 22311, 22312],
  354. "I-58": [11380, 22311, 22312],
  355. "Akashi": [10550, 1034, 10520, 10521, 10522],
  356. "Z1": [10380, 29171, 29172],
  357. "Z18": [2081, 23031, 23032],
  358. "Z19": [2081, 23031, 23032],
  359. "Z20": [2081, 23031, 23032],
  360. "Z21": [2081, 23031, 23032],
  361. "Z23": [10530, 29201, 29202],
  362. "Z25": [2011, 5051, 23041, 23042],
  363. "Z35": [11450, 23051, 23052],
  364. "Z46": [10640, 2081, 29211, 29212],
  365. "Königsberg": [1032, 23111, 23112],
  366. "Karlsruhe": [2011, 23111, 23112],
  367. "Köln": [2011, 23111, 23112],
  368. "Leipzig": [1052, 23121, 23122],
  369. "Admiral Hipper": [10720, 4021, 23211, 23212],
  370. "Prinz Eugen": [10390, 23211, 23212],
  371. "Deutschland": [10650, 23221, 23222],
  372. "Admiral Graf.Spee": [10650, 23221, 23222],
  373. "Scharnhorst": [10660, 2101],
  374. "Gneisenau": [10700, 2101],
  375. "Tirpitz": [10670, 2091],
  376. "Graf Zeppelin": [10680, 10690],
  377. "U-81": [11390, 11410, 29271, 29272],
  378. "U-47": [11440, 11460, 29311, 29312],
  379. "U-557": [3571, 3611, 23311, 23312],
  380. "An Shan": [11040, 24011, 24012],
  381. "Fu Shun": [11050, 24011, 24012],
  382. "Chang Chun": [11060, 24011, 24012],
  383. "Tai Yuan": [11070, 24011, 24012],
  384. "Yat Sen": [10760, 10500, 24121, 24122],
  385. "Ning Hai": [10480, 10500, 24111, 24112],
  386. "Ping Hai": [10490, 10500, 24111, 24112],
  387. "Avrora": [10510, 29191, 29192],
  388. "Le Triomphant": [11500, 11510, 29331, 29332],
  389. "Forbin": [5071, 28011, 28012],
  390. "Emile Bertin": [11520, 5061, 28111, 28112],
  391. "Surcouf": [11570, 3521, 29321, 29322],
  392. "Le Mars": [5081, 28011, 28012],
  393. "Dunkerque": [11490],
  394. "Jean Bart": [11530, 11540],
  395. "HDN Neptune": [101010],
  396. "Noire": [101020],
  397. "Blanc": [101030],
  398. "Vert": [101040],
  399. "Purple Heart": [101050, 101060, 101070],
  400. "Black Heart": [101080, 101090],
  401. "White Heart": [101100, 101110],
  402. "Green Heart": [101120, 101130],
  403. "HMS Neptune": [19010, 19020, 19000, 29231, 19001, 19002, 29232],
  404. "Monarch": [19030, 19040, 19000, 19001, 19002],
  405. "Ibuki": [19050, 19060, 19000, 29221, 19001, 19002, 29222],
  406. "Izumo": [19070, 19080, 19000, 19001, 19002],
  407. "Roon": [19090, 19100, 19000, 29241, 19001, 19002, 29242],
  408. "Saint Louis": [19110, 19120, 19000, 29251, 19001, 19002, 29252],
  409. "Bush": [2171, 20041, 20042],
  410. "Colorado": [10320],
  411. "Maryland": [10320, 10970],
  412. "West Virginia": [10320],
  413. "North Carolina": [10980, 10990],
  414. "Washington": [11000, 11010],
  415. "Wasp": [11020],
  416. "Jersey": [10850, 21071, 21072],
  417. "Michishio": [5031, 22091, 22092],
  418. "Arashio": [22091, 22092],
  419. "22": [102020, 29291, 29292],
  420. "33": [102010, 29301, 29302],
  421. "Taihou": [11620, 11630],
  422. "Essex": [11640, 11650,11660],
  423. "Albacore": [11670, 11680, 29340],
  424. "Le Temeraire": [11700, 4140]
  425. }
  426. return d
  427.  
  428. def getSkillIconNumber(name,num):
  429. database = getdb()
  430.  
  431. misc = {
  432. "20021": 2000,
  433. "22051": 2120,
  434. "28011": 4070,
  435. "29111": 10940,
  436. "21011": 1080,
  437. "23111": 2110,
  438. "22081": 11130,
  439. "21111": 10710,
  440. "24111": 10950,
  441. "21041": 1060,
  442. "22082": 11130,
  443. "22131": 10890,
  444. "20061": 5000,
  445. "20051": 4090,
  446. "21031": 4080,
  447. "21221": 2010,
  448. "22141": 2050,
  449. "21241": 10710,
  450. "22211": 2050,
  451. "22052": 5020,
  452. "22011": 1010
  453. }
  454.  
  455. if name not in database:
  456. return ''
  457.  
  458. if len(database[name]) < num:
  459. return ''
  460.  
  461. snum = database[name][num-1]
  462.  
  463. if str(snum) in misc:
  464. return misc[str(snum)]
  465. elif snum > 100:
  466. return snum - snum % 10 #replace last digit
  467. else:
  468. return snum
  469.  
  470. if __name__ == "__main__":
  471. main()
Add Comment
Please, Sign In to add comment