-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlauncher_functions.py
72 lines (61 loc) · 2.26 KB
/
launcher_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# coding: utf-8
import requests
import re
import os
import os.path
try:
import xml.etree.cElementTree as et
except ImportError:
import xml.etree.ElementTree as et
DISTRIBUTION_PARAMS = {
'sg': {
'launcher_update_url': 'http://update.worldoftanks.asia',
'langs': ['fil', 'id', 'ja', 'ko', 'ms', 'th', 'vi', 'zh_sg', 'zh_tw', 'en'],
},
'ru': {
'launcher_update_url': 'http://update.wot.ru.wargaming.net',
'langs': ['be', 'uk', 'kk', 'ru'],
},
'eu': {
'launcher_update_url': 'http://update.worldoftanks.eu',
'langs': ['pt', 'de', 'no', 'sr', 'fi', 'es', 'hu', 'pl', 'nl', 'it', 'hr', 'fr', 'lt', 'el', 'da', 'bg',
'lv', 'et', 'cs', 'tr', 'sv', 'ro', 'en'],
},
'na': {
'launcher_update_url': 'http://update.worldoftanks.com',
'langs': ['ja', 'ko', 'pt_br', 'fr', 'es_ar', 'en'],
},
'cn': {
'launcher_update_url': 'http://update.worldoftanks.cn',
'langs': ['zh_cn'],
},
}
__all__ = ['get_patches_with_launcher']
def get_patches_with_launcher(realm):
list_with_urls = get_urls(realm)
download_patches(realm, list_with_urls)
def get_urls(realm):
params = dict()
list_with_urls = list()
params['protocol_ver'] = '4'
params['install_id'] = 'C8BD7B9BD74484CC719CE637719CE6370ADF6C3C'
params['target'] = 'locale'
params['locale_ver'] = '0'
for lang in DISTRIBUTION_PARAMS[realm]['langs']:
params['lang'] = lang
response = requests.get(DISTRIBUTION_PARAMS[realm]['launcher_update_url'], params=params)
content = response.content
pattern = r'<http name="\w*">(.*)</http>'
url_to_download = re.search(pattern, content)
list_with_urls.append(url_to_download.group(1))
print 'Links have been got.'
return list_with_urls
def download_patches(realm, list_with_urls):
if not os.path.exists(realm):
os.mkdir(realm)
for url in list_with_urls:
response = requests.get(url)
patch_name = re.split('/', url)[-1]
if response:
print '{} has been downloaded'.format(patch_name)
open(os.path.join(os.getcwd(), realm, patch_name), 'wb').write(response.content)