SegFault

在2016年5月6日 (星期五)加入
添加540字节 、​ 2016年10月3日 (星期一)
无编辑摘要
无编辑摘要
无编辑摘要
第2行: 第2行:
from urllib.request import urlopen
from urllib.request import urlopen
import json
import json
url = 'http://login.jianniang.com/index/getInitConfigs'
specialShipNames = [ '重庆', '奥希金斯', '信赖', '萝德尼' ]
countryNames = [ '', '日本', '德国', '英国', '美国', '意大利', '法国', '苏联', '中国', '???' ]
specialCountries = { '戈本':'土耳其', '德·鲁伊特':'荷兰', '苏赫巴托尔':'蒙古', '奥希金斯':'智利', '吸血鬼':'英国', '海达人':'加拿大', '奥丁':'冰岛' }
shipTypeNames = [ '', '航空母舰', '轻型航空母舰', '装甲航母', '战列舰', 'BBV', '战列巡洋舰', '航空战列舰', \
        'CAV', 'CLT', '轻巡洋舰', '浅水重炮舰', '驱逐舰', 'SSV', '潜艇', '重炮潜艇', '补给舰' ]
rangeNames = [ '', '短', '中', '长', '超长' ]
coreNames = { 10441:'驱逐', 10341:'巡洋', 10241:'战列', 10141:'航母', 10541:'潜艇' }
remodelPostfix = '·改'
specialPostfix = '(特殊)'
canNotEquip = '不可装备'
noEquipt = '无'
aquire = '获得'
day = '白天'
night = '夜间'
formation = '阵型'
attack = '攻击'
nightAttack = '夜战'
damaged = '中破'
vow = '誓约'
desc = '简介'


def getShipName(ship):
def getShipName(ship):
     name = ship['title'].strip()
     name = ship['title'].strip()
     idx = int(ship['shipIndex'])
     idx = int(ship['shipIndex'])
     if idx < 1000 or name in [ '重庆', '奥希金斯', '信赖', '萝德尼' ]:
     if idx < 1000 or name in specialShipNames:
         return name
         return name
     elif idx < 2000:
     elif idx < 2000:
         return name + '·改'
         return name + remodelPostfix
     else:
     else:
         return name + '(特殊)'
         return name + specialPostfix


def getShipAttr(ship, allShips, equipts):
def getShipAttr(ship, allShips, equipts):
第22行: 第46行:
             cap[i] = ship['capacityInit'][i]
             cap[i] = ship['capacityInit'][i]


     eq = [ '不可装备' ] * 4
     eq = [ canNotEquip ] * 4
     n = len(ship['equipment'])
     n = len(ship['equipment'])
     for i in range(n):
     for i in range(n):
         eq[i] = [ e['title'] for e in equipts if e['cid'] == ship['equipment'][i] ][0]
         eq[i] = [ e['title'] for e in equipts if e['cid'] == ship['equipment'][i] ][0]
     for i in range(n, ship['equipmentNum']):
     for i in range(n, ship['equipmentNum']):
         eq[i] = '无'
         eq[i] = noEquipt


    t = [ '', '日本', '德国', '英国', '美国', '意大利', '法国', '苏联', '中国', '???' ]
     country = countryNames[int(ship['country'])]
     country = t[int(ship['country'])]
     if ship['title'] in specialCountries:
    t = { '戈本':'土耳其', '德·鲁伊特':'荷兰', '苏赫巴托尔':'蒙古', '奥希金斯':'智利', '吸血鬼':'英国', '海达人':'加拿大', '奥丁':'冰岛' }
         country = specialCountries[ship['title']]
     if ship['title'] in t:
         country = t[ship['title']]


     ret = "ships['%s'] = {\n    " % getShipName(ship)
     ret = "ships['%s'] = {\n    " % getShipName(ship)
第39行: 第61行:
     ret += "index=%s, " % int(ship['shipIndex'])
     ret += "index=%s, " % int(ship['shipIndex'])
     ret += "rarity=%s, " % ship['star']
     ret += "rarity=%s, " % ship['star']
    t = [ '', '航空母舰', '轻型航空母舰', '装甲航母', '战列舰', 'BBV', '战列巡洋舰', '航空战列舰', \
 
            'CAV', 'CLT', '轻巡洋舰', '浅水重炮舰', '驱逐舰', 'SSV', '潜艇', '重炮潜艇', '补给舰' ]
     ret += "type='%s', " % shipTypeNames[ship['type']]
     ret += "type='%s', " % t[ship['type']]
     ret += "country='%s', " % country
     ret += "country='%s', " % country
     ret += "class='%s', " % ship['classNo']
     ret += "class='%s', " % ship['classNo']
第57行: 第78行:
     ret += "speed=%s, " % ship['speed']
     ret += "speed=%s, " % ship['speed']
     ret += "luck=%s, " % ship['luck']
     ret += "luck=%s, " % ship['luck']
    t = [ '', '短', '中', '长', '超长' ]
     ret += "range='%s', " % rangeNames[ship['range']]
     ret += "range='%s', " % t[ship['range']]


     ret = ret[:-1] + '\n    '
     ret = ret[:-1] + '\n    '
第105行: 第125行:
         ret += "mod='%s', " % getShipName(t[0])
         ret += "mod='%s', " % getShipName(t[0])
         ret += "modLv=%s, " % ship['evoLevel']
         ret += "modLv=%s, " % ship['evoLevel']
        t = { 10441:'驱逐', 10341:'巡洋', 10241:'战列', 10141:'航母', 10541:'潜艇' }
         ret += "coreType='%s', " % coreNames[ship['evoNeedItemCid']]
         ret += "coreType='%s', " % t[ship['evoNeedItemCid']]
         ret += "coreNum=%s, " % ship['evoNeedResource'][str(ship['evoNeedItemCid'])]
         ret += "coreNum=%s, " % ship['evoNeedResource'][str(ship['evoNeedItemCid'])]
         ret += "mFuel=%s, " % mod['2']
         ret += "mFuel=%s, " % mod['2']
第114行: 第133行:


     return ret[:-2] + '\n}\n'
     return ret[:-2] + '\n}\n'


def getDialogue(ship):
def getDialogue(ship):
     name = getShipName(ship)
     name = getShipName(ship)
     ret = "text['" + name + "']= { }\n"
     ret = "text['" + name + "'] = { }\n"
     ret += "text['" + name + "']['获得'] = '" + ship['getDialogue'].strip() + "'\n"
     ret += "text['" + name + "']['" + aquire + "'] = '" + ship['getDialogue'].strip() + "'\n"
     if ship['mainDialogue'] and ship['mainDialogue'][0]:
     if ship['mainDialogue'] and ship['mainDialogue'][0]:
         ret += "text['" + name + "']['白天1'] = '" + ship['mainDialogue'][0].strip() + "'\n"
         ret += "text['" + name + "']['" + day + "1'] = '" + ship['mainDialogue'][0].strip() + "'\n"
         ret += "text['" + name + "']['白天2'] = '" + ship['mainDialogue'][1].strip() + "'\n"
         ret += "text['" + name + "']['" + day + "2'] = '" + ship['mainDialogue'][1].strip() + "'\n"
         ret += "text['" + name + "']['白天3'] = '" + ship['mainDialogue'][2].strip() + "'\n"
         ret += "text['" + name + "']['" + day + "3'] = '" + ship['mainDialogue'][2].strip() + "'\n"
     if ship['mainDialogue'] and ship['mainDialogue'][6]:
     if ship['mainDialogue'] and ship['mainDialogue'][6]:
         ret += "text['" + name + "']['夜间1'] = '" + ship['mainDialogue'][6].strip() + "'\n"
         ret += "text['" + name + "']['" + night + "1'] = '" + ship['mainDialogue'][6].strip() + "'\n"
         ret += "text['" + name + "']['夜间2'] = '" + ship['mainDialogue'][7].strip() + "'\n"
         ret += "text['" + name + "']['" + night + "2'] = '" + ship['mainDialogue'][7].strip() + "'\n"
         ret += "text['" + name + "']['夜间3'] = '" + ship['mainDialogue'][8].strip() + "'\n"
         ret += "text['" + name + "']['" + night + "3'] = '" + ship['mainDialogue'][8].strip() + "'\n"
     if ship['formationDialogue']:
     if ship['formationDialogue']:
         ret += "text['" + name + "']['阵型'] = '" + ship['formationDialogue'].strip() + "'\n"
         ret += "text['" + name + "']['" + formation + "'] = '" + ship['formationDialogue'].strip() + "'\n"
     if ship['atkDialogue']:
     if ship['atkDialogue']:
         ret += "text['" + name + "']['攻击'] = '" + ship['atkDialogue'].strip() + "'\n"
         ret += "text['" + name + "']['" + attack + "'] = '" + ship['atkDialogue'].strip() + "'\n"
     if ship['nightAtkDialogue']:
     if ship['nightAtkDialogue']:
         ret += "text['" + name + "']['夜战'] = '" + ship['nightAtkDialogue'].strip() + "'\n"
         ret += "text['" + name + "']['" + nightAttack + "'] = '" + ship['nightAtkDialogue'].strip() + "'\n"
     if ship['breakDialogue']:
     if ship['breakDialogue']:
         ret += "text['" + name + "']['中破'] = '" + ship['breakDialogue'].strip() + "'\n"
         ret += "text['" + name + "']['" + damaged + "'] = '" + ship['breakDialogue'].strip() + "'\n"
     ret += "text['" + name + "']['誓约'] = '" + ship['vow'].strip() + "'\n"
     ret += "text['" + name + "']['" + vow + "'] = '" + ship['vow'].strip() + "'\n"
     ret += "text['" + name + "']['简介'] = '" + ship['desc'].strip() + "'\n"
     ret += "text['" + name + "']['" + desc + "'] = '" + ship['desc'].strip() + "'\n"


     return ret + '\n'
     return ret + '\n'
第183行: 第201行:
     for equipt in data['shipEquipmnt']:
     for equipt in data['shipEquipmnt']:
         if equipt['picId'] == 998: continue
         if equipt['picId'] == 998: continue
         if equipt['title'] == '喵': continue
         if equipt['title'] == '喵' or equipt['title'] == '': continue
         f.write(getEquiptAttr(equipt))
         f.write(getEquiptAttr(equipt))
         f.write('\n')
         f.write('\n')
第190行: 第208行:


def download():
def download():
     j = urlopen('http://login.jianniang.com/index/getInitConfigs').read().decode('utf-8')
     j = urlopen(url).read().decode('utf-8')
     return json.loads(j)
     return json.loads(j)