forked from OlympicCode/vHackOSBot-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.py
59 lines (51 loc) · 2.79 KB
/
update.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
from utils import Utils
from player import Player
import os, time, random
class Update():
def __init__(self, ut):
self.ut = ut
self.Configuration = self.ut.readConfiguration()
self.startFunctionUpdate()
def startFunctionUpdate(self):
p = Player(self.ut)
# get money info
if "money" in p.getStore and "apps" in p.getStore:
money = int(p.getStore["money"])
apps = p.getStore["apps"]
else:
apps = []
money = 0
getTask = self.ut.requestString("tasks.php", accesstoken=self.Configuration["accessToken"])
if 'updateCount' in getTask.keys():
update = int(getTask['updateCount'])
else:
update = 0
# get applications and update this
for count_update, applications in enumerate(apps):
# update application
if (count_update+update) < 9:
Appid = int(applications["appid"])
random.shuffle(self.Configuration["update"])
for list_update in self.Configuration["update"]:
application_update = int(p.getHelperApplication()[list_update]["appid"])
if money >= int(applications["price"]):
result = self.ut.requestString("store.php",
accesstoken=self.Configuration["accessToken"],
appcode=application_update,
action="100")
money = money - int(applications["price"])
if result['result'] == '0':
update = update+1
self.ut.viewsPrint("showMsgUpdate", "[{}] - Updated {} +1".format(os.path.basename(__file__), list_update))
else:
self.ut.viewsPrint("showMsgUpdate", "[{}] - you have not money to upgrade {}".format(os.path.basename(__file__), list_update))
else:
self.ut.viewsPrint("showMsgUpdatefull", "[{}] - full task list, please wait.".format(os.path.basename(__file__)))
# install application if level required < level
if int(applications["require"]) <= int(p.getStore["level"]) and int(applications["level"]) == 0:
result = self.ut.requestString("store.php",
accesstoken=self.Configuration["accessToken"],
appcode=applications["appid"],
action="200")
self.ut.viewsPrint("showMsgInstalleApp", "[{}] - Installed new application.".format(os.path.basename(__file__)))
break