-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhamster.py
47 lines (41 loc) · 1.97 KB
/
hamster.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
from core.common import logger, SEP_LENGTH, randint, sleep, time, datetime
from core.mainConfig import MainConfig
def main():
logger.info("-" * SEP_LENGTH)
logger.info(" <b>Hamster Kombat Bot by Qx</b> ".center(SEP_LENGTH + 7, "-"))
logger.info("-" * SEP_LENGTH + "\n")
HamsterConfig = MainConfig()
HamsterConfig.loadConfig()
HamsterConfig.initClients()
while True:
try:
clientIndex = 0
while clientIndex < HamsterConfig.lenClients:
HamsterConfig.getHamster(clientIndex).sync()
clientIndex += 1
minDelay = HamsterConfig.minDelay() + randint(1, 20)
iterTime = time()
if HamsterConfig.enablePromoGames:
while time() + 900 < iterTime + minDelay and len(HamsterConfig.clientsPromoGames) > 0:
HamsterConfig.initPromoGames()
for clientPromoId in HamsterConfig.clientsPromoGames:
promoClient = HamsterConfig.promoGames.get(clientPromoId, None)
if promoClient:
promoKey = promoClient.genPromoKey()
if promoKey:
HamsterConfig.claimPromoCode(clientPromoId, promoKey)
logger.info("-" * SEP_LENGTH + "\n")
remainsDelay = int((iterTime + minDelay) - time())
except Exception as ex:
logger.error(ex)
remainsDelay = HamsterConfig.defaultDelay
if remainsDelay > 0:
logger.info(f"Continue in {remainsDelay} sec ({datetime.fromtimestamp(time() + remainsDelay).strftime('%d.%m.%Y, %H:%M:%S')})")
logger.info("*" * SEP_LENGTH + "\n\n")
sleep(remainsDelay)
HamsterConfig.updateConfig()
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
logger.info("Hamster Kombat Bot terminated".ljust(SEP_LENGTH, " "))