-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (42 loc) · 1.62 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
import asyncio
import os
from building.parse_town_buildings import UpgradeBuilding
from building.parse_village_fields import BuildField
from credentials import VILLAGE_URL, TOWN_URL, SERVER_URL
from send_troops import TroopsOrder
from logger import get_logger
logger = get_logger(__name__)
async def builders_manager(village_url, village_number):
f = open(f'/tmp/BUILDINGS_QUEUE_{village_number}', 'w+')
f.write(os.environ.get(f'BUILDINGS_QUEUE_{village_number}'))
f.close()
build_field = BuildField(VILLAGE_URL + village_url)
upgrade_building = UpgradeBuilding(TOWN_URL + village_url, f'/tmp/BUILDINGS_QUEUE_{village_number}')
while True:
await asyncio.gather(upgrade_building(), build_field())
# loop = asyncio.get_event_loop()
# loop.create_task(upgrade_building())
# loop.create_task(build_field())
# loop.run_forever()
async def troop_raid(url, village_number):
open(f'/tmp/RAIDS_{village_number}', 'w+').close()
send_troops = TroopsOrder(SERVER_URL + 'build.php' + url + 'id=39&tt=2&gid=16', village_number)
while True:
await send_troops()
def main():
loop = asyncio.get_event_loop()
village_number = 1
url = os.environ.get(f'VILLAGE_URL_{village_number}')
while url:
loop.create_task(builders_manager(url, village_number))
loop.create_task(troop_raid(url, village_number))
village_number += 1
url = os.environ.get(f'VILLAGE_URL_{village_number}')
try:
loop.run_forever()
except KeyboardInterrupt:
loop.close()
except Exception as e:
logger.error(e)
if __name__ == '__main__':
main()