Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- from selenium.common.exceptions import NoSuchElementException
- from selenium.common.exceptions import ElementNotVisibleException
- from selenium.webdriver.common.by import By
- from selenium.webdriver.support.ui import WebDriverWait
- from selenium.webdriver.support import expected_conditions as EC
- import sys
- import time
- from datetime import datetime
- print(datetime.time().replace(hour,minute,second))
- def main():
- while True:
- checkMessages()
- autoausbau()
- time.sleep(20)
- return
- def autoausbau():
- chrome.get('/game.php?screen=main')
- building_queue = chrome.find_element(By.ID, 'build_queue')
- building_queue_entrys = build_queue.find_elements(By.TAG_NAME, 'tr')
- if len(building_queue_entrys) <= 3:
- table_buildings = chrome.find_element(By.CSS_SELECTOR, 'table#buildings')
- wood = table_buildings.find_element(By.ID, 'main_buildrow_wood')
- stone = table_buildings.find_element(By.ID, 'main_buildrow_stone')
- iron = table_buildings.find_element(By.ID, 'main_buildrow_iron')
- wood_button = wood.find_element(By.CSS_SELECTOR, 'a.btn.btn-build')
- stone_button = stone.find_element(By.CSS_SELECTOR, 'a.btn.btn-build')
- iron_button = iron.find_element(By.CSS_SELECTOR, 'a.btn.btn-build')
- wood_stufe = wood.find_element(By.TAG_NAME, 'span')
- stone_stufe = stone.find_element(By.TAG_NAME, 'span')
- iron_stufe = iron.find_element(By.TAG_NAME, 'span')
- wood_stufe = wood_stufe.text
- wood_stufe = wood_stufe.split(' ')
- wood_stufe = int(wood_stufe[1])
- stone_stufe = stone_stufe.text
- stone_stufe = stone_stufe.split(' ')
- stone_stufe = int(stone_stufe[1])
- iron_stufe = iron_stufe.texts
- iron_stufe = iron_stufe.split(' ')
- iron_stufe = int(iron_stufe[1])
- if wood_stufe > stone_stufe:
- stone_button.click()
- elif (iron+2) < stone:
- iron_button.click()
- else:
- wood_button.click()
- return
- def checkMessages():
- message = False
- try:
- message = chrome.find_element(By.CSS_SELECTOR, 'span.header.new_mail')
- except NoSuchElementException:
- print('Keine neuen Nachtichten')
- if not message == False:
- print('Neue Nachricht')
- message.click()
- message = chrome.find_elements(By.CLASS_NAME, 'vis')
- message = message[8]
- already_new = False
- filter = message.find_element(By.ID, 'filter_none')
- try:
- filter.click()
- except ElementNotVisibleException:
- already_new = True
- if already_new == False:
- filter_table = message.find_element(By.ID, 'filter')
- neu_link = filter_table.find_element(By.PARTIAL_LINK_TEXT, "Neu")
- neu_link.click();
- vis_table = chrome.find_elements(By.CSS_SELECTOR, 'table.vis')
- vis_table = vis_table[8]
- vis_tds = vis_table.find_elements(By.TAG_NAME, 'td')
- i = 4
- while i < len(vis_tds)-1:
- link = vis_tds[4].find_element(By.TAG_NAME, 'a')
- link.click()
- time.sleep(1)
- chrome.back()
- time.sleep(1)
- vis_table = chrome.find_elements(By.CSS_SELECTOR, 'table.vis')
- vis_table = vis_table[8]
- vis_tds = vis_table.find_elements(By.TAG_NAME, 'td')
- i += 3
- message = chrome.find_elements(By.CLASS_NAME, 'vis')
- message = message[7]
- filter = message.find_element(By.ID, 'filter_new')
- filter.click()
- filter_table = message.find_element(By.ID, 'filter')
- neu_link = filter_table.find_element(By.PARTIAL_LINK_TEXT, "Kein")
- neu_link.click();
- village_link = chrome.find_element(By.CSS_SELECTOR, 'a.nowrap.tooltip-delayed')
- village_link.click();
- else:
- print('Keine neuen Nachtichten')
- return
- print("Name: ")
- name = 'progammer'#sys.stdin.readline()
- print("Password: ")
- password = '123456q'#sys.stdin.readline()
- print('Welt:')
- world = '132'#sys.stdin.readline()
- awe = True
- chrome = webdriver.Chrome('D:\Python\selenium\webdriver\chrome\chromedriver.exe')
- chrome.get('https://www.die-staemme.de')
- chrome.implicitly_wait(15)
- print('Oeffne die-staemme.de')
- login_form = WebDriverWait(chrome, 15).until(EC.presence_of_element_located((By.ID, 'login_form')))
- if login_form == False:
- awe = False
- if(awe):
- login_user = login_form.find_element(By.ID, 'user')
- login_password = login_form.find_element(By.ID, 'password')
- login_button = login_form.find_element(By.CLASS_NAME, 'button_middle')
- login_user.send_keys(name)
- login_password.send_keys(password)
- login_button.click()
- server_form = WebDriverWait(chrome, 15).until(EC.presence_of_element_located((By.ID, 'server_select_list')))
- if server_form == False:
- awe = False
- if(awe):
- world_button = server_form.find_elements(By.CLASS_NAME, 'world_button_active')
- for worlds in world_button:
- text = str(worlds.text)
- welt = 'Welt '+str(world)
- if text == welt:
- worlds.click()
- print('Auf ' +welt+' eingeloggt')
- main()
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement