This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (51 loc) · 2.34 KB
/
main.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
import configparser
import random
import time
from datetime import datetime
from datetime import timedelta
from travianApi import TravianApi
from wonderApi import WonderApi
global config
config = configparser.ConfigParser()
def main():
updated = False
while True is True:
travian = TravianApi(config['Travian']['username'],
config['Travian']['password'],
config['Travian']['WWVillageName'],
config['Travian']['linkToDorf2'],
config['General']['userAgent'])
loopWWVillage(travian)
travian.openMarketplace()
if travian.checkIsCurrentVillageWW():
source = travian.getSourcecode()
wonder = WonderApi(config['Wonder']['username'],
config['Wonder']['password'],
config['Wonder']['cropToolName'])
updated = wonder.updateResources(source)
# Task run every 15 minutes. (900)
if updated:
min = int(config['General']['minDelay'])
max = int(config['General']['maxDelay'])
if checkNightmode():
wonder.logActions("[Nightmode] Night detected!")
min *= int(config['Nightmode']['nightDelayMultiplier'])
max *= int(config['Nightmode']['nightDelayMultiplier'])
randomSleep = random.randint(min, max)
print("Done! Now let me sleep for " + str(randomSleep / 60) + " min ... Next update at "
+ str(datetime.now() + timedelta(seconds=randomSleep)))
time.sleep(randomSleep)
updated = False
def loopWWVillage(travian):
while not travian.checkIsCurrentVillageWW():
travian.openWWVillage()
def checkNightmode():
start = datetime(year=datetime.now().year, month=datetime.now().month, day=datetime.now().day,
hour=int(config['Nightmode']['nightStartAt']), minute=0, second=0)
end = datetime(year=datetime.now().year, month=datetime.now().month, day=datetime.now().day+1,
hour=int(config['Nightmode']['nightEndAt']), minute=0, second=0)
curr = datetime.now()
return config['Nightmode']['nightEnabled'] in ['True', 'true'] and (start <= curr <= end)
if __name__ == "__main__":
config.read('config.ini')
main()