无编辑摘要 |
无编辑摘要 |
||
| (未显示同一用户的3个中间版本) | |||
| 第1行: | 第1行: | ||
<pre | <pre> | ||
from urllib.request import urlopen | from urllib.request import urlopen | ||
import json | import json | ||
| 第5行: | 第5行: | ||
url = 'http://login.jianniang.com/index/getInitConfigs' | url = 'http://login.jianniang.com/index/getInitConfigs' | ||
countryNames = [ '', '日本', '德国', '英国', '美国', '意大利', '法国', '苏联', '中国' ] | |||
countryNames = [ '', '日本', '德国', '英国', '美国', '意大利', '法国', '苏联', '中国 | shipTypeNames = [ '', '航空母舰', '轻型航空母舰', '装甲航母', '战列舰', '航空战列舰', '战列巡洋舰', '重巡洋舰', \ | ||
shipTypeNames = [ '', '航空母舰', '轻型航空母舰', '装甲航母', '战列舰', ' | |||
'CAV', 'CLT', '轻巡洋舰', '浅水重炮舰', '驱逐舰', 'SSV', '潜艇', '重炮潜艇', '补给舰' ] | 'CAV', 'CLT', '轻巡洋舰', '浅水重炮舰', '驱逐舰', 'SSV', '潜艇', '重炮潜艇', '补给舰' ] | ||
rangeNames = [ '', '短', '中', '长', '超长' ] | rangeNames = [ '', '短', '中', '长', '超长' ] | ||
| 第14行: | 第12行: | ||
remodelPostfix = '·改' | remodelPostfix = '·改' | ||
canNotEquip = '不可装备' | canNotEquip = '不可装备' | ||
noEquipt = '无' | noEquipt = '无' | ||
| 第27行: | 第24行: | ||
desc = '简介' | desc = '简介' | ||
def getShipName(ship): | def getShipName(ship, allShips): | ||
name = ship['title'].strip() | name = ship['title'].strip() | ||
idx = int(ship['shipIndex']) | idx = int(ship['shipIndex']) | ||
if idx < 1000 | if idx < 1000: | ||
return name | return name | ||
orig = [ s for s in allShips if int(s['shipIndex']) == idx % 1000 ][0] | |||
if name == orig['title'].strip(): | |||
name += remodelPostfix | |||
return name | |||
def getShipAttr(ship, allShips, equipts): | def getShipAttr(ship, allShips, equipts): | ||
| 第53行: | 第51行: | ||
eq[i] = noEquipt | eq[i] = noEquipt | ||
ret = "ships['%s'] = {\n " % getShipName(ship, allShips) | |||
ret = "ships['%s'] = {\n " % getShipName(ship) | |||
ret += "index=%s, " % int(ship['shipIndex']) | ret += "index=%s, " % int(ship['shipIndex']) | ||
| 第63行: | 第57行: | ||
ret += "type='%s', " % shipTypeNames[ship['type']] | ret += "type='%s', " % shipTypeNames[ship['type']] | ||
ret += "country='%s', " % country | if int(ship['country']) < 9: | ||
ret += "country='%s', " % countryNames[int(ship['country'])] | |||
ret += "class='%s', " % ship['classNo'] | ret += "class='%s', " % ship['classNo'] | ||
| 第123行: | 第118行: | ||
ret = ret[:-1] + '\n ' | ret = ret[:-1] + '\n ' | ||
ret += "mod='%s', " % getShipName(t[0]) | ret += "mod='%s', " % getShipName(t[0], allShips) | ||
ret += "modLv=%s, " % ship['evoLevel'] | ret += "modLv=%s, " % ship['evoLevel'] | ||
ret += "coreType='%s', " % coreNames[ship['evoNeedItemCid']] | ret += "coreType='%s', " % coreNames[ship['evoNeedItemCid']] | ||
| 第134行: | 第129行: | ||
return ret[:-2] + '\n}\n' | return ret[:-2] + '\n}\n' | ||
def getDialogue(ship): | def getDialogue(ship, allShips): | ||
name = getShipName(ship) | name = getShipName(ship, allShips) | ||
ret = " | ret = "ships['" + name + "']['" + aquire + "'] = '" + ship['getDialogue'].strip() + "'\n" | ||
if ship['mainDialogue'] and ship['mainDialogue'][0]: | if ship['mainDialogue'] and ship['mainDialogue'][0]: | ||
ret += " | ret += "ships['" + name + "']['" + day + "1'] = '" + ship['mainDialogue'][0].strip() + "'\n" | ||
ret += " | ret += "ships['" + name + "']['" + day + "2'] = '" + ship['mainDialogue'][1].strip() + "'\n" | ||
ret += " | ret += "ships['" + name + "']['" + day + "3'] = '" + ship['mainDialogue'][2].strip() + "'\n" | ||
if ship['mainDialogue'] and ship['mainDialogue'][6]: | if ship['mainDialogue'] and ship['mainDialogue'][6] != ship['mainDialogue'][0]: | ||
ret += " | ret += "ships['" + name + "']['" + night + "1'] = '" + ship['mainDialogue'][6].strip() + "'\n" | ||
ret += " | ret += "ships['" + name + "']['" + night + "2'] = '" + ship['mainDialogue'][7].strip() + "'\n" | ||
ret += " | ret += "ships['" + name + "']['" + night + "3'] = '" + ship['mainDialogue'][8].strip() + "'\n" | ||
if ship['formationDialogue']: | if ship['formationDialogue']: | ||
ret += " | ret += "ships['" + name + "']['" + formation + "'] = '" + ship['formationDialogue'].strip() + "'\n" | ||
if ship['atkDialogue']: | if ship['atkDialogue']: | ||
ret += " | ret += "ships['" + name + "']['" + attack + "'] = '" + ship['atkDialogue'].strip() + "'\n" | ||
if ship['nightAtkDialogue']: | if ship['nightAtkDialogue']: | ||
ret += " | ret += "ships['" + name + "']['" + nightAttack + "'] = '" + ship['nightAtkDialogue'].strip() + "'\n" | ||
if ship['breakDialogue']: | if ship['breakDialogue']: | ||
ret += " | ret += "ships['" + name + "']['" + damaged + "'] = '" + ship['breakDialogue'].strip() + "'\n" | ||
ret += " | ret += "ships['" + name + "']['" + vow + "'] = '" + ship['vow'].strip() + "'\n" | ||
ret += " | ret += "ships['" + name + "']['" + desc + "'] = '" + ship['desc'].strip() + "'\n" | ||
return ret + '\n' | return ret + '\n' | ||
| 第177行: | 第171行: | ||
return ret + ' }' | return ret + ' }' | ||
def | def parse(data): | ||
f = open('data.lua', 'w') | |||
f.write('local equipts = { }\nlocal ships = { }\n\n') | |||
# equipment attributes | |||
f.write(' | f.write('-' * 100 + '\n\n') | ||
for | for equipt in data['shipEquipmnt']: | ||
f.write( | #if equipt['picId'] == 998: continue | ||
if equipt['title'] == '喵' or equipt['title'] == '': continue | |||
f.write(getEquiptAttr(equipt)) | |||
f.write('\n') | |||
# ship attributes | |||
f.write('\n' + '-' * 100 + '\n\n') | |||
ships = [ s for s in data['shipCard'] if int(s['npc']) == 0 and int(s['shipIndex']) < 2000 ] | ships = [ s for s in data['shipCard'] if int(s['npc']) == 0 and int(s['shipIndex']) < 2000 ] | ||
for s in ships: | for s in ships: | ||
f.write(getShipAttr(s, ships, data['shipEquipmnt'])) | f.write(getShipAttr(s, ships, data['shipEquipmnt'])) | ||
f.write('\n') | f.write('\n') | ||
# dialogue | |||
f.write(' | f.write('-' * 100 + '\n\n') | ||
for | for s in ships: | ||
f.write(getDialogue(s, ships)) | |||
f.write( | f.write('-' * 100 + '\n\n') | ||
f.write('return { equipts=equipts, ships=ships }') | |||
f.write(' | |||
f.close() | f.close() | ||
| 第211行: | 第203行: | ||
return json.loads(j) | return json.loads(j) | ||
if __name__ == '__main__': | |||
data = download() | data = download() | ||
parse(data) | |||
</pre> | |||