-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·133 lines (104 loc) · 4.3 KB
/
app.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/python3
import datetime
import json
import os
import random
import re
import time
from argparse import ArgumentParser
from mgsv_emulator.emulator.client import Client
dir_path = os.path.dirname(os.path.realpath(__file__))
info_list_re = re.compile("I=C=cmn-col-.*?\|")
p = ArgumentParser()
p.add_argument('-d', '--delay', action='store_true')
args = p.parse_args()
if args.delay:
delay = random.randrange(600, 2400)
time.sleep(delay)
def save_nukes_data(update_time, nuke_amount, platform):
f = open(os.path.join(dir_path,"{}.txt".format(platform)), "a")
f.write('{},{}\n'.format(update_time, nuke_amount))
f.close()
def get_nuke_data(platform):
f = open(os.path.join(dir_path,"{}.txt".format(platform)), 'r').read().split('\n')
text = ""
for line in f:
if line == "":
continue
full_date, value = line.split(',')
date, hours = full_date.split(" ")
text += "{" + " x: '{}', y: {}, group:'{}'".format(
date,
value,
platform
) + '},\n'
return text.rstrip(',')
def get_fob_info(data):
fob_event_main = ""
event_id = data['fob_event_task_result_param']['one_event_param'][0]['event_id']
english_text = list(filter(lambda x: x['language']=='en', data['server_texts']))
# gross
if len(str(event_id)) != 2:
event_id_str = '0' + str(event_id)
fob_event_main += "<p>Name: " + list(filter(lambda x: x['identifier'] == "mb_fob_event_name_{}".format(event_id_str), english_text ))[0]['text'] + '</p>'
fob_event_main += "<p>Description: " + list(filter(lambda x: x['identifier'] == "mb_fob_event_info_{}".format(event_id_str), english_text ))[0]['text'].replace('\n',' ') + '</p>'
fob_event_main += "<p>" + list(filter(lambda x: x['identifier'] == "ranking_evnt_term", english_text ))[0]['text'] + '</p>'
fob_event_others = ""
for i in english_text:
if 'event_name' in i['identifier']:
if 'event_name_{}'.format(event_id_str) not in i['identifier']:
fob_event_others += '<p>Name: ' + i['text'] + '</p>'
if 'event_info' in i['identifier']:
if 'event_info_{}'.format(event_id_str) not in i['identifier']:
fob_event_others += '<p>Description: ' + i['text'] + '</p><hr>'
return (fob_event_main, fob_event_others)
def get_info_list_data(data):
result = ""
for i in data['data']['info_list']:
result += "<p>ID: {}</p>".format(i['info_id'])
text = info_list_re.sub('',i['mes_body']).replace('\r','')
text = text.replace('<','').replace('>','').replace('\n','<br>')
result += "<p>Message: {}</p><hr>\n".format(text)
return result
def gather_data():
nuke_amount = {'stm':-1, 'ps3':0,'ps4':-1}
steam_client = Client()
steam_client.login()
nukes = steam_client.get_nuclear()[0]
login_info = steam_client.get_login_data()[0]
info_list = steam_client.get_info_list()[0]
nuke_amount['stm'] = nukes['data']['info']['num']
nuke_amount['ps3'] = 0
ps4_client = Client(platform='ps4')
ps4_nukes = ps4_client.get_nuclear()[0]
nuke_amount['ps4'] = ps4_nukes['data']['info']['num']
update_time = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:00')
save_nukes_data(update_time, nuke_amount['stm'], 'stm')
save_nukes_data(update_time, nuke_amount['ps3'], 'ps3')
save_nukes_data(update_time, nuke_amount['ps4'], 'ps4')
nuke_data_steam = get_nuke_data('stm')
nuke_data_ps3 = get_nuke_data('ps3')
nuke_data_ps4 = get_nuke_data('ps4')
fob_info = get_fob_info(login_info['data'])
fob_info_main = fob_info[0]
fob_info_others = fob_info[1]
infolist = get_info_list_data(info_list)
# should use .format of something like that
template = open(os.path.join(dir_path,'template.html'),'r').read()
out = template.replace('-nukes_steam-', str(nuke_amount['stm']))
out = out.replace('-nukes_ps3-', str(nuke_amount['ps3']))
out = out.replace('-nukes_ps4-', str(nuke_amount['ps4']))
out = out.replace('-fob_event_main-',str(fob_info_main))
out = out.replace('-fob_event_others-',str(fob_info_others))
out = out.replace('-last_nuke_update-',str(update_time))
out = out.replace('-infolist-',str(infolist))
out = out.replace('-nuke_data_steam-',nuke_data_steam)
out = out.replace('-nuke_data_ps3-',nuke_data_ps3)
out = out.replace('-nuke_data_ps4-',nuke_data_ps4)
f = open(os.path.join(dir_path,'index.html'),'w')
f.write(out)
f.close()
gather_data()
# fob_event_task_list # tpp_fob.eng.lng2
# online_challenge_task # list of online mission tasks
# server_product_params # list of price fixes