Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3.4
- #requests to execute GET and POST requests
- import requests
- #bs4 to parse html
- from bs4 import BeautifulSoup as bs
- #time to sleep for 60 seconds
- import time
- #os to play sounds
- import os
- #random to not request _every_ 60 seconds
- import random
- def main(retry = 0):
- #credentials and server
- username = 'YourUserName'
- password = 'YourPassword'
- realm = 'en'
- server = 's142-en.ogame.gameforge.com'
- #to appear more human a random interval is selected.
- #it should be between 30 seconds and 5 minutes
- min_wait = 30
- max_wait = 500
- #Starte eine Session
- session = requests.session()
- #get the homepage
- homepage = session.get('https://' + realm + '.gameforge.com')
- #make it usable with BeautifulSoup
- soup = bs(homepage.content, 'html.parser')
- #prepare the POST data
- logindata = {'kid':'', 'login':username, 'pass':password, 'uni': server}
- #get the logged in page
- gamepage = session.post('https://' + realm + '.ogame.gameforge.com:443/main/login/index.php?', data=logindata)
- #make it usable with BeautifulSoup
- soup = bs(gamepage.content, 'html.parser')
- #save, if the login was successful or not
- login = False
- #game loop
- while(username in session.get('https://' + server + '/game/index.php?page=overview').text):
- #the login was successful, save it
- login = True
- #get the events using ajax
- eventpage = session.get('https://' + server + '/game/index.php?page=eventList&ajax=1')
- #make it usable using BeautifulSoup
- soup = bs(eventpage.content, 'html.parser')
- #Every fleet entry uses the class 'eventFleet', so select all of them
- fleets = soup.select('.eventFleet')
- #save, if any events happned
- event = False
- #check every fleet movement
- for fleet in fleets:
- #type 1 means attack
- if fleet.get('data-mission-type') == '1':
- #If the attack is hostile, warn!
- if fleet.select('.hostile'):
- event = True
- print('ENEMY ATTACKS!')
- for i in range(3):
- #can be replaced with a simple print or as complex as an email. this needs "SoX" to be installed
- os.system('play --no-show-progress --null --channels 1 synth 2.5 sin 667 gain -5 bend .35,180,.25 .15,740,.53 0,-520,.3 vol 0.25')
- #type 6 means espionage
- elif fleet.get('data-mission-type') == '6':
- #if the espionage is hostile, warn!
- if fleet.select('.hostile'):
- event = True
- print('ENEMY SPIES!')
- #if no event happened, at least say so
- if not event:
- print("Nothing happened...")
- #sleep for a random interval
- time.sleep(random.randint(min_sleep, max_sleep))
- #if it retried before and worked now, its safe to assume
- #a force logout and no user interaction
- retry = False
- if not login:
- print("Login not successful. Check credentials.")
- else:
- print("Player logged in or force logout.")
- if not retry:
- if time.gmtime().tm_hour == 1 and time.gmtime().tm_min > 50:
- print("Attempting to login again..")
- main(retry = time.time())
- elif time.gmtime().tm_hour == 2 and time.gmtime().tm_min < 10:
- print("Attempting to login again..")
- main(retry = time.time())
- else:
- print("Not the typical time to reset. Shutting down.")
- else:
- print("Already retryed login, user is possibly active. Shutting down.")
- print("Attackwarner shut down at {}:{}.".format(time.localtime().tm_hour, time.localtime().tm_min))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement