示例#1
0
def get_emblem(server, clan, size):
    url = settings(mypath + '/' + SETTINGS_FILE_NAME)[
        server.upper() + '_emblem_link'] + str(clan[0]) + '/' + settings(
            mypath + '/' + SETTINGS_FILE_NAME)['emblem_' + size.lower()]
    with urllib.request.urlopen(url) as u:
        raw_data = u.read()
    return raw_data
def get_cw_clans(server):
    check_server_availability(server, 'uc')
    d = get_dic(settings(mypath + '/' + SETTINGS_FILE_NAME)['region_data_url'] + str(settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() + '_regions'][0]))
    l = []
    d_clans = d['clans']
    for i in d_clans:
        l.append((d_clans[i]['id'],d_clans[i]['tag']))
    return tuple(l)
示例#3
0
def get_cw_clans(server):
    check_server_availability(server, 'uc')
    d = get_dic(
        settings(mypath + '/' + SETTINGS_FILE_NAME)['region_data_url'] + str(
            settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() +
                                                        '_regions'][0]))
    l = []
    d_clans = d['clans']
    for i in d_clans:
        l.append((d_clans[i]['id'], d_clans[i]['tag']))
    return tuple(l)
示例#4
0
 def modlist():
     l = []
     s = settings(mypath + '/' + SETTINGS_FILE_NAME)
     for k in s.keys():
         if k[:4] == 'mod_' and s[k] :
             l.append(k[4:])
     return l
示例#5
0
 def modlist():
     l = []
     s = settings(mypath + '/' + SETTINGS_FILE_NAME)
     for k in s.keys():
         if k[:4] == 'mod_' and s[k]:
             l.append(k[4:])
     return l
示例#6
0
def wot_directory():
    wotdir = settings(mypath + '/' +
                      SETTINGS_FILE_NAME)['World_of_Tanks_directory']
    if not os.path.exists(wotdir):
        raise IncorrectWorldOfTanksDirectory(
            'Please set the correct World of Tanks path in {0}'.format(
                SETTINGS_FILE_NAME))
    return wotdir
示例#7
0
def download_emblems(server, clanref, size, path):
    clanlist = get_clanlist(server, clanref)
    if clanlist:
        for i in range(len(clanlist)):
            print('\rDownloading ' + size +
                  ' clan emblem: {0}/{1} ({2}%) [{3}]'.format(
                      i + 1, len(clanlist),
                      round((i + 1) / len(clanlist) * 100, 1),
                      clanlist[i][1]).ljust(40),
                  end='')
            with open(ensure_dir(path + 'clanicons/' + server.upper()) + '/' +
                      clanlist[i][1] + '_' +
                      settings(mypath + '/' +
                               SETTINGS_FILE_NAME)['emblem_' + size.lower()],
                      mode='w+b') as emblem:
                emblem.write(get_emblem(server, clanlist[i], size))
        print('')
def make_clanlist(server, start=None):
    
    check_server_availability(server, 'clanlist')
    
    if not start:
        try:
            with open(mypath + '/' + server.upper() + '_clans.lst', mode='r', encoding='utf_8') as clanlist:
                l = clanlist.readlines()
            start = int(l[-1].split('\t')[0]) + 1
        except:
            start = 1 + settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() + '_clan_index_shift']
    
    url = settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() + '_clan_page_link']

    i = start
    c = True
    while c:
        try:
            c = lxml.html.parse(url+str(i)+'/')
            known_404 = None
        except:
            known_404s = settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() + '_known_404']
            if isinstance(known_404s, int):
                if i == settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() + '_known_404']:
                    known_404 = True
            elif isinstance(known_404s, list) or isinstance(known_404s, tuple):
                if i in settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() + '_known_404']:
                    known_404 = True
            c = False
        if c and not known_404:
            t = c.find(".//title").text
            if settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() + '_disbanded'] not in t :
                tag_name = t[:-settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() + '_clan_page_trim']]
                tag_end = tag_name.find(']')
                clan_tag = tag_name[1:tag_end]
                clan_name = tag_name[tag_end+2:]
                print('\rProcessing clan: # {0} [{1}]'.format(i,clan_tag).ljust(67),end='')
                with open(mypath + '/' + server.upper() + '_clans.lst', mode='a', encoding='utf_8') as clanlist:
                    clanlist.write('{0}\t{1}\t{2}\n'.format(i,clan_tag,clan_name))
        if known_404:
            c = True
        i += 1

    print('\nDONE.')
示例#9
0
def wot_directory():
    wotdir = settings(mypath + '/' + SETTINGS_FILE_NAME)['World_of_Tanks_directory']
    if not os.path.exists(wotdir):
        raise IncorrectWorldOfTanksDirectory('Please set the correct World of Tanks path in {0}'.format(SETTINGS_FILE_NAME))
    return wotdir
def download_emblems(server, clanref, size, path):
    clanlist = get_clanlist(server, clanref)
    if clanlist:
        for i in range(len(clanlist)):
            print('\rDownloading '+ size +' clan emblem: {0}/{1} ({2}%) [{3}]'.format(i+1,len(clanlist),round((i+1)/len(clanlist)*100,1),clanlist[i][1]).ljust(40),end='')
            with open(ensure_dir(path + 'clanicons/' + server.upper()) + '/' + clanlist[i][1] + '_' + settings(mypath + '/' + SETTINGS_FILE_NAME)['emblem_' + size.lower()], mode='w+b') as emblem:
                emblem.write(get_emblem(server, clanlist[i], size))
        print('')
def get_emblem(server, clan, size):
    url = settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() + '_emblem_link'] + str(clan[0]) + '/' +  settings(mypath + '/' + SETTINGS_FILE_NAME)['emblem_' + size.lower()]
    with urllib.request.urlopen(url) as u:
        raw_data = u.read()
    return raw_data
示例#12
0
def make_clanlist(server, start=None):

    check_server_availability(server, 'clanlist')

    if not start:
        try:
            with open(mypath + '/' + server.upper() + '_clans.lst',
                      mode='r',
                      encoding='utf_8') as clanlist:
                l = clanlist.readlines()
            start = int(l[-1].split('\t')[0]) + 1
        except:
            start = 1 + settings(mypath + '/' +
                                 SETTINGS_FILE_NAME)[server.upper() +
                                                     '_clan_index_shift']

    url = settings(mypath + '/' + SETTINGS_FILE_NAME)[server.upper() +
                                                      '_clan_page_link']

    i = start
    c = True
    while c:
        try:
            c = lxml.html.parse(url + str(i) + '/')
            known_404 = None
        except:
            known_404s = settings(mypath + '/' +
                                  SETTINGS_FILE_NAME)[server.upper() +
                                                      '_known_404']
            if isinstance(known_404s, int):
                if i == settings(mypath + '/' +
                                 SETTINGS_FILE_NAME)[server.upper() +
                                                     '_known_404']:
                    known_404 = True
            elif isinstance(known_404s, list) or isinstance(known_404s, tuple):
                if i in settings(mypath + '/' +
                                 SETTINGS_FILE_NAME)[server.upper() +
                                                     '_known_404']:
                    known_404 = True
            c = False
        if c and not known_404:
            t = c.find(".//title").text
            if settings(mypath + '/' +
                        SETTINGS_FILE_NAME)[server.upper() +
                                            '_disbanded'] not in t:
                tag_name = t[:-settings(mypath + '/' +
                                        SETTINGS_FILE_NAME)[server.upper() +
                                                            '_clan_page_trim']]
                tag_end = tag_name.find(']')
                clan_tag = tag_name[1:tag_end]
                clan_name = tag_name[tag_end + 2:]
                print('\rProcessing clan: # {0} [{1}]'.format(
                    i, clan_tag).ljust(67),
                      end='')
                with open(mypath + '/' + server.upper() + '_clans.lst',
                          mode='a',
                          encoding='utf_8') as clanlist:
                    clanlist.write('{0}\t{1}\t{2}\n'.format(
                        i, clan_tag, clan_name))
        if known_404:
            c = True
        i += 1

    print('\nDONE.')
示例#13
0
def make_xvmconf():
    s = settings(mypath + '/' + SETTINGS_FILE_NAME)
    s2 = settings(emblem_downloader.mypath + '/' +
                  emblem_downloader.SETTINGS_FILE_NAME)

    if s['xvmconf_file']:
        xvmconffile = s['xvmconf_file']
    else:
        xvmconffile = rootpath + '/mods/wot-xvm/configs/gneposis.xvmconf'

    with open(xvmconffile, mode='r') as f_xvmconf:
        content = f_xvmconf.read()
    search_string_server = '"' + get_server() + '"'
    loc_server = content.find(search_string_server)
    loc0 = content[loc_server:].find('[\n') + loc_server + 2
    loc1_temp = content[loc0:].find(']\n') + loc0
    loc1 = content[:loc1_temp].rfind('\n')

    players_list = [c.strip() for c in content[loc0:loc1].split('\n')]

    nicks = []
    clans = []
    for p in players_list:
        p_splitted = p.split('"')
        try:
            if p_splitted[1] == 'nick':
                nicks.append((p_splitted[3], p_splitted[7]))
            elif p_splitted[1] == 'clan':
                clans.append(p_splitted[3][1:-1])
        except:
            pass

    if s['xvm_keep_clans']:
        s_clans = set(clans)
    else:
        s_clans = set()

    if s['clanicons']:
        l_clans = emblem_downloader.get_clanlist(get_server(), s['clanicons'])
    else:
        l_clans = []

    for i in l_clans:
        s_clans.add(i[1])

    new_xvmconf = content[:loc0]

    row_added = False

    if s['xvm_keep_nicks']:
        for i in nicks:
            print('\rAdding nick to XVM.xvmconf: {0}'.format(i[0]).ljust(40),
                  end='')
            new_xvmconf = new_xvmconf + '        { "nick": "' + i[
                0] + '", "icon": "' + i[1] + '" },\n'
            row_added = True

    for i in sorted(s_clans):
        print('\rAdding clan to XVM.xvmconf: [{0}]'.format(i).ljust(40),
              end='')
        new_xvmconf = new_xvmconf + '        { "clan": "[' + i + ']", "icon": "' + i + '_' + s2[
            'emblem_' + s['clanicon_size']] + '" },\n'
        row_added = True

    print('')

    # remove last comma, but only if no row added:
    if not row_added:
        new_xvmconf = new_xvmconf[:-1] + content[loc1:]
    else:
        new_xvmconf = new_xvmconf[:-2] + content[loc1:]

    v = get_wot_version()

    with open(rootpath + '/your_res_mods/' + v + '/gui/flash/XVM.xvmconf',
              mode='w') as n_xvmconf:
        n_xvmconf.write(new_xvmconf)

    return nicks, sorted(s_clans)
示例#14
0
def add_clanicons(clanlist):
    s = settings(mypath + '/' + SETTINGS_FILE_NAME)
    if s['mod_wot-xvm']:
        emblem_downloader.download_emblems(get_server(), clanlist,
                                           s['clanicon_size'],
                                           rootpath + '/your_res_mods/')
示例#15
0
def add_clanicons(clanlist):
    s = settings(mypath + '/' + SETTINGS_FILE_NAME)
    if s['mod_wot-xvm']:
        emblem_downloader.download_emblems(get_server(),clanlist,s['clanicon_size'],rootpath + '/your_res_mods/')
示例#16
0
def make_xvmconf():
    s = settings(mypath + '/' + SETTINGS_FILE_NAME)
    s2 = settings(emblem_downloader.mypath + '/' + emblem_downloader.SETTINGS_FILE_NAME)
    
    if s['xvmconf_file']:
        xvmconffile = s['xvmconf_file']
    else:
        xvmconffile = rootpath + '/mods/wot-xvm/configs/gneposis.xvmconf'

    with open(xvmconffile,mode='r') as f_xvmconf:
        content=f_xvmconf.read()
    search_string_server = '"'+get_server()+'"'
    loc_server = content.find(search_string_server)
    loc0 = content[loc_server:].find('[\n') + loc_server + 2
    loc1_temp = content[loc0:].find(']\n') + loc0
    loc1 = content[:loc1_temp].rfind('\n')
    
    players_list = [ c.strip() for c in content[loc0:loc1].split('\n') ]
    
    nicks = []
    clans = []
    for p in players_list:
        p_splitted = p.split('"')
        try:
            if p_splitted[1] == 'nick':
                nicks.append((p_splitted[3],p_splitted[7]))
            elif p_splitted[1] == 'clan':
                clans.append(p_splitted[3][1:-1])
        except:
            pass
    
    if s['xvm_keep_clans']:
        s_clans = set(clans)
    else:
        s_clans = set()

    if s['clanicons']:
        l_clans = emblem_downloader.get_clanlist(get_server(),s['clanicons'])
    else:
        l_clans = []
    
    for i in l_clans:
        s_clans.add(i[1])
    
    new_xvmconf = content[:loc0]
    
    row_added = False
    
    if s['xvm_keep_nicks']:
        for i in nicks:
            print('\rAdding nick to XVM.xvmconf: {0}'.format(i[0]).ljust(40),end='')
            new_xvmconf = new_xvmconf + '        { "nick": "'+i[0]+'", "icon": "'+i[1]+'" },\n'
            row_added = True
    
    for i in sorted(s_clans):
        print('\rAdding clan to XVM.xvmconf: [{0}]'.format(i).ljust(40),end='')
        new_xvmconf = new_xvmconf + '        { "clan": "['+i+']", "icon": "'+i+'_'+s2['emblem_'+s['clanicon_size']]+'" },\n'
        row_added = True
    
    print('')
    
    # remove last comma, but only if no row added:
    if not row_added:
        new_xvmconf = new_xvmconf[:-1] + content[loc1:]
    else:
        new_xvmconf = new_xvmconf[:-2] + content[loc1:]
    
    v = get_wot_version()
    
    with open(rootpath + '/your_res_mods/'+v+'/gui/flash/XVM.xvmconf',mode='w') as n_xvmconf:
        n_xvmconf.write(new_xvmconf)
    
    return nicks, sorted(s_clans)
示例#17
0
def check_server_availability(server, criteria):
    if server.upper() not in settings(mypath + '/' + SETTINGS_FILE_NAME)[
            criteria + '_available_servers']:
        raise NotValidServer('This server is not valid: {0}'.format(server))