Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.16 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.common.exceptions import NoSuchElementException
  3. from selenium.common.exceptions import ElementNotVisibleException
  4. from selenium.webdriver.common.by import By
  5. from selenium.webdriver.support.ui import WebDriverWait
  6. from selenium.webdriver.support import expected_conditions as EC
  7. import sys
  8. import time
  9. from datetime import datetime
  10.  
  11. print(datetime.time().replace(hour,minute,second))
  12.  
  13. def main():
  14.     while True:
  15.         checkMessages()
  16.         autoausbau()
  17.  
  18.         time.sleep(20)
  19.     return
  20.  
  21. def autoausbau():
  22.     chrome.get('/game.php?screen=main')
  23.    
  24.     building_queue = chrome.find_element(By.ID, 'build_queue')
  25.     building_queue_entrys = build_queue.find_elements(By.TAG_NAME, 'tr')
  26.     if len(building_queue_entrys) <= 3:
  27.         table_buildings = chrome.find_element(By.CSS_SELECTOR, 'table#buildings')
  28.         wood = table_buildings.find_element(By.ID, 'main_buildrow_wood')
  29.         stone = table_buildings.find_element(By.ID, 'main_buildrow_stone')
  30.         iron = table_buildings.find_element(By.ID, 'main_buildrow_iron')
  31.    
  32.         wood_button = wood.find_element(By.CSS_SELECTOR, 'a.btn.btn-build')
  33.         stone_button = stone.find_element(By.CSS_SELECTOR, 'a.btn.btn-build')
  34.         iron_button = iron.find_element(By.CSS_SELECTOR, 'a.btn.btn-build')
  35.    
  36.         wood_stufe = wood.find_element(By.TAG_NAME, 'span')
  37.         stone_stufe = stone.find_element(By.TAG_NAME, 'span')
  38.         iron_stufe = iron.find_element(By.TAG_NAME, 'span')
  39.        
  40.         wood_stufe = wood_stufe.text
  41.         wood_stufe = wood_stufe.split(' ')
  42.         wood_stufe = int(wood_stufe[1])
  43.        
  44.         stone_stufe = stone_stufe.text
  45.         stone_stufe = stone_stufe.split(' ')
  46.         stone_stufe = int(stone_stufe[1])
  47.        
  48.         iron_stufe = iron_stufe.texts
  49.         iron_stufe = iron_stufe.split(' ')
  50.         iron_stufe = int(iron_stufe[1])
  51.    
  52.         if wood_stufe > stone_stufe:
  53.             stone_button.click()
  54.         elif (iron+2) < stone:
  55.             iron_button.click()
  56.         else:
  57.             wood_button.click()
  58.    
  59.    
  60.     return
  61.    
  62. def checkMessages():
  63.     message = False
  64.     try:
  65.         message = chrome.find_element(By.CSS_SELECTOR, 'span.header.new_mail')
  66.     except NoSuchElementException:
  67.         print('Keine neuen Nachtichten')
  68.  
  69.     if not message == False:
  70.         print('Neue Nachricht')
  71.         message.click()
  72.         message = chrome.find_elements(By.CLASS_NAME, 'vis')
  73.         message = message[8]
  74.         already_new = False        
  75.        
  76.         filter = message.find_element(By.ID, 'filter_none')
  77.  
  78.         try:
  79.             filter.click()
  80.         except ElementNotVisibleException:
  81.             already_new = True
  82.  
  83.         if already_new == False:
  84.             filter_table = message.find_element(By.ID, 'filter')
  85.             neu_link = filter_table.find_element(By.PARTIAL_LINK_TEXT, "Neu")
  86.             neu_link.click();
  87.  
  88.         vis_table = chrome.find_elements(By.CSS_SELECTOR, 'table.vis')
  89.         vis_table = vis_table[8]
  90.         vis_tds = vis_table.find_elements(By.TAG_NAME, 'td')
  91.         i = 4
  92.         while i < len(vis_tds)-1:
  93.             link = vis_tds[4].find_element(By.TAG_NAME, 'a')
  94.             link.click()
  95.             time.sleep(1)
  96.             chrome.back()
  97.             time.sleep(1)
  98.             vis_table = chrome.find_elements(By.CSS_SELECTOR, 'table.vis')
  99.             vis_table = vis_table[8]
  100.             vis_tds = vis_table.find_elements(By.TAG_NAME, 'td')
  101.             i += 3
  102.         message = chrome.find_elements(By.CLASS_NAME, 'vis')
  103.         message = message[7]
  104.  
  105.         filter = message.find_element(By.ID, 'filter_new')
  106.         filter.click()
  107.  
  108.         filter_table = message.find_element(By.ID, 'filter')
  109.         neu_link = filter_table.find_element(By.PARTIAL_LINK_TEXT, "Kein")
  110.         neu_link.click();
  111.  
  112.         village_link = chrome.find_element(By.CSS_SELECTOR, 'a.nowrap.tooltip-delayed')
  113.         village_link.click();
  114.  
  115.     else:
  116.         print('Keine neuen Nachtichten')
  117.     return
  118.  
  119.  
  120. print("Name: ")
  121. name = 'progammer'#sys.stdin.readline()
  122.  
  123. print("Password: ")
  124. password = '123456q'#sys.stdin.readline()
  125.  
  126. print('Welt:')
  127. world = '132'#sys.stdin.readline()
  128.  
  129. awe = True
  130.  
  131. chrome = webdriver.Chrome('D:\Python\selenium\webdriver\chrome\chromedriver.exe')
  132. chrome.get('https://www.die-staemme.de')
  133. chrome.implicitly_wait(15)
  134. print('Oeffne die-staemme.de')
  135.  
  136. login_form = WebDriverWait(chrome, 15).until(EC.presence_of_element_located((By.ID, 'login_form')))
  137. if login_form == False:
  138.     awe = False
  139.  
  140. if(awe):
  141.     login_user = login_form.find_element(By.ID, 'user')
  142.     login_password = login_form.find_element(By.ID, 'password')
  143.     login_button = login_form.find_element(By.CLASS_NAME, 'button_middle')
  144.     login_user.send_keys(name)
  145.     login_password.send_keys(password)
  146.     login_button.click()
  147.  
  148.     server_form = WebDriverWait(chrome, 15).until(EC.presence_of_element_located((By.ID, 'server_select_list')))
  149.     if server_form == False:
  150.         awe = False
  151.  
  152.     if(awe):
  153.         world_button = server_form.find_elements(By.CLASS_NAME, 'world_button_active')
  154.         for worlds in world_button:
  155.             text = str(worlds.text)
  156.             welt = 'Welt '+str(world)
  157.             if text == welt:
  158.                 worlds.click()
  159.                 print('Auf ' +welt+' eingeloggt')
  160.                 main()
  161.                 break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement