Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Commit

Permalink
fix : Requirements grabbed properly & more
Browse files Browse the repository at this point in the history
Requirements are now grabbed properly per mission, ripped the main mission code into a seperate function for readability- also the required quantity should be despatched with no extras. Any missions already done will not even be processed.
  • Loading branch information
jackbayliss committed Jan 25, 2020
1 parent 13536de commit 3834e51
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 55 deletions.
22 changes: 16 additions & 6 deletions helpers.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import random
vehicles = {
"Fire engines": {
"fire engines": {
"Water Ladder",
"Light 4X4 Pump (L4P)"
"Light 4X4 Pump (L4P)",
"Rescue Pump"
},
"Police cars": {
"Incident response vehicle (IRV)"

"police cars": {
"Incident response vehicle (IRV)",
"Dog Support Unit (DSU)",
"Armed Response Vehicle (ARV)",
"Police helicopter"
},
"": {

"ambulance": {
"Ambulance"
},

"Misc" : {
"Aerial Appliance",
"Fire Officer",
"Rescue Support Unit (RSU)",
"Rescue Pump",
"Water Carrier",
"HazMat Unit"
"HazMat Unit",
"Breathing Apparatus Support Units (BASU)",
"Incident Command and Control Unit (ICCU)"
}

}
Expand Down
98 changes: 49 additions & 49 deletions missionchief_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,56 +64,59 @@ def getMissions():
time.sleep(1)

def getRequirements(missionId):
requirementsurl = baseurl + "/einsaetze/3?mission_id=" + missionId
requirementsurl = browser.links.find_by_partial_href('/einsaetze/')[0]['href']
print(f"Visiting requirements {requirementsurl}")
browser.visit(requirementsurl)
requiredlist = []
requirements = browser.find_by_tag('td')
Style.RESET_ALL
print(Fore.YELLOW + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
for index, r in enumerate(requirements):
if "Required" in r.text:
if "Station" not in r.text:
requirement = r.text.replace('Required','').strip();
qty = requirements[index+1].text
print(f"Requirement found : {str(qty)} x {str(requirement)}")
requiredlist.append({'requirement':requirement,'qty': qty })
if r.text:
if "Required" in r.text:
if "Station" not in r.text:
requirement = r.text.replace('Required','').strip().lower();
qty = requirements[index+1].text
print(f"Requirement found : {str(qty)} x {str(requirement)}")
requiredlist.append({'requirement':requirement,'qty': qty })
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
Style.RESET_ALL
if(len(requiredlist)==0):
requiredlist.append({'requirement':'ambulance','qty': 1 })
return requiredlist

def doMissions():
count = 0
for href in hrefs:
count+=1
try:
browser.visit(href)
mission_str = str(count)
mission_text = browser.find_by_id('missionH1').text
print("MISSION " + mission_str +": " + mission_text)
missionId = href.split("/")[4]
browser.visit(href)
mission_str = str(count)
mission_text = browser.find_by_id('missionH1').text
print(Fore.MAGENTA + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
Style.RESET_ALL
print("MISSION " + mission_str +": " + mission_text)
missionId = href.split("/")[4]
if(len(despatched)>0):
for miss in despatched:
if(miss==missionId):
print(f"Already despatched this mission {missionId} - Skipping it")
rannum = randomint()
print(Fore.CYAN + f"Sleeping for {rannum} - seconds")
Style.RESET_ALL
time.sleep(rannum)
continue
if(miss==missionId):
print(f"Already despatched this mission {missionId} - Skipping it")
else:
Style.RESET_ALL
doMission(href,missionId)
else:
doMission(href,missionId)
Style.RESET_ALL
print(Fore.CYAN + "Getting requirements")
return


def doMission(href,missionId):
qtydes=0
requiredlist=getRequirements(missionId)
print(Fore.CYAN + "Got Requirements")
Style.RESET_ALL
print("Got Requirements")
browser.visit(href)
labels=browser.find_by_css('label[class="mission_vehicle_label"]')

for requirement in requiredlist:
try:
# Here we are seeing is any labels exists (i.e do we even have any vehicles we can despatch- if we don't throw print the below.)
print(labels.first);
except:
print(Fore.RED + "MISSION " + mission_str +":" + "CAN NOT DESPATCH A UNIT, ALL IN USE OR UNIT ALREADY DESPATCHED")
Style.RESET_ALL
qtytodes = int(requirement['qty'])
for label in labels:
if(requirement['requirement'] in label.text):
print("Direct match found...")
Expand All @@ -129,11 +132,8 @@ def doMissions():
for category in vehicles:
# If the cateogry matches the requirement
if(category in requirement['requirement']):
# qty required
for i in range(int(requirement['qty'])):
# Check vehicle is in the object
for vehicle in vehicles[category]:
print("found vehicle")
print(f"Checking {vehicle} against {label.text}")
# Find label
if(vehicle in label.text):
Expand All @@ -143,25 +143,25 @@ def doMissions():
for check in checkbox:
if(check['value']==checkid):
if(check['value']==checkid):
print(Fore.GREEN + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print(Fore.GREEN + f"Attempting to despatch {label.text}")
check.check()
print(Fore.GREEN + f"{label.text} despatched!")
print( Fore.GREEN +"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
despatched.append(missionId)
browser.find_by_name('commit').click()
Style.RESET_ALL
else:
print(Fore.RED + "NO MATCH, OR NO VEHICLE AVAILABLE")
Style.RESET_ALL
if(qtydes<qtytodes):
Style.RESET_ALL
print(Fore.GREEN + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print(Fore.GREEN + f"Attempting to despatch {label.text}")
check.check()
qtydes+=1
print( Fore.GREEN +f"{qtydes} to despatchh")
print(Fore.GREEN + f"{label.text} despatched!")
print( Fore.GREEN +"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
Style.RESET_ALL
else:
print( Fore.GREEN +"Max qty already despatched")

Style.RESET_ALL
despatched.append(missionId)
browser.find_by_name('commit').click()
Style.RESET_ALL

except Exception as e:
print(Fore.RED + "MISSION " + mission_str +":" + "CAN NOT DESPATCH A UNIT, ALL IN USE OR UNIT ALREADY DESPATCHED")
Style.RESET_ALL



# Taking account information from file
with open(path + '/account.txt', 'r') as f:
username = f.readline().strip()
Expand Down

0 comments on commit 3834e51

Please sign in to comment.