-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot_actions.py
60 lines (53 loc) · 2.37 KB
/
bot_actions.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 actions import *
def kingdom(world):
headersInfo = setHeaders(world)
url = 'http://'+world+'.warkingdoms.com/military/view_all'+identifier
response = r.get(url, headers = headersInfo).json()
kingdomDetails = { 'id': 0, 'colony_count': 0 }
kingdomDetails['colony_count'] = response['colony_count']
for loc in response['place_units']:
if(loc['name'] == 'Kingdom Center'):
kingdomDetails['id'] = loc['id']
return kingdomDetails
def colony(world):
headersInfo = setHeaders(world)
url = 'http://'+world+'.warkingdoms.com/military/view_all'+identifier
response = r.get(url, headers = headersInfo).json()
colonyDetails = { 'id': [], 'troops': [] }
for colony in response['place_units']:
if(colony['name'] != 'Kingdom Center'):
troops = colony['owned'].split(" ")
if(troops[0] != '0'):
colonyDetails['id'].append(colony['id'])
colonyDetails['troops'].append(troops[0])
return colonyDetails
def attack_notification(world, colony):
headersInfo = setHeaders(world)
url = 'http://'+world+'.warkingdoms.com/mobilizing/view_all'+identifier
response = r.get(url, headers = headersInfo).json()
if(len(response['military_mobilizations']) == 0):
return False
else:
for ongoing in response['military_mobilizations']:
if(ongoing['info']['type_foreign'] == 1):
if(ongoing['info']['info_nolink'].find('attacking') > -1):
if(ongoing['info']['info'].find('/'+colony+'?') > -1):
return True
return False
def get_troop(world, colony):
headersInfo = setHeaders(world)
url = 'http://'+world+'.warkingdoms.com/military/view_units/military/'+colony+identifier
response = r.get(url, headers = headersInfo).json()
troops = {'type': [], 'count': []}
for troop in response['userunits'][0]['units']:
troops['type'].append(troop['type'])
troops['count'].append(troop['count'])
return troops
def export(world, kingdom, colony, troops):
headersInfo = setHeaders(world)
troop = {}
for i in range(len(troops['type'])):
troop.update({troops['type'][i] : troops['count'][i]})
url = 'http://'+world+'.warkingdoms.com/place/transfer_units/military/'+colony+'/'+kingdom+'/export'+identifier
response = r.post(url, headers = headersInfo, data = troop).json()
return response