def close(window): while True: try: logger.debug('回答締め切り') window.find_element_by_xpath( '/html/body/div/div/div[4]/div/div[1]/button').click() except NoSuchElementException: logger.warning('回答締め切りボタンがない') continue except TimeoutException: logger.warning('回答を占めきれなかった') continue else: logger.info('回答を締め切ろうとしている') break justwait.justWait(window, 1) try: logger.debug('回答締め切り確認') window.find_element_by_xpath( '/html/body/div/div/div[4]/div[1]/div/div/div[3]/button[2]').click( ) except NoSuchElementException: pass except TimeoutException: pass else: logger.info('回答を締め切りました')
def enter(window): try: justwait.justWait(window, 5) window.find_element_by_xpath( '/html/body/div/div[2]/div/span/div[1]/div/div/div[1]/div/div[5]/div[2]/button' ).click() except NoSuchElementException: return None
def flag(window): justwait.justWait(window, 1) f = window.find_element_by_xpath( '/html/body/div/div/div[4]/div/h3/pre').text if f == 'おわり' or f == '終わり': return True else: return False
def vote(window): logger.debug('投票フェーズに入りました') justwait.justWait(window, 5) logger.debug('画像お題であればダウンロードします') getImage.getImage(window) svgtimer.svgtimerevent(window) closevote.close(window) logger.debug('投票フェーズを抜けます')
def waiting(window): logger.debug('待ち状態') while True: phase_name = phase.getPhaseName(window) if phase_name is None: justwait.justWait(window, 5) continue else: logger.info('待ち状態を抜けます') break
def create(window): while True: try: logger.debug('部屋を建てようとした') justwait.justWait(window, 3) window.find_element_by_xpath( '/html/body/div/div[2]/p/button').click() except NoSuchElementException: logger.warning('部屋建てに失敗したのでもう一度') continue else: logger.info('部屋を立てるボタンを押した') break
def result(window): while True: justwait.justWait(window, 5) a = phase.getPhaseName(window) if a != '結果フェーズ': break else: try: window.find_element_by_tag_name('svg') except NoSuchElementException: closepriority.close(window) questioning.question(window) break else: continue
def svgtimerevent(window): """ svgタグが存在する限りループさせます """ while True: try: justwait.justWait(window, 2) window.find_element_by_tag_name("svg") except NoSuchElementException: break except TimeoutException: break else: justwait.justWait(window, 3) continue
def question(window): try: justwait.justWait(window, 2) window.find_element_by_xpath('/html/body/div/div/div[4]/div/div[1]/button').click() except NoSuchElementException: pass try: window.find_element_by_xpath('/html/body/div/div/div[4]/div[1]/div/div/div[2]/div[3]/textarea').send_keys('お題募集') except NoSuchElementException: window.find_element_by_xpath('/html/body/div/div/div[4]/div[1]/div/div/div[1]/button/span').click() try: window.find_element_by_xpath('/html/body/div/div/div[4]/div[1]/div/div/div[3]/button[2]').click() except NoSuchElementException: window.find_element_by_xpath('/html/body/div/div/div[4]/div[1]/div/div/div[1]/button/span').click() else: justwait.justWait(window, 3)
def signin(window): try: logger.debug('サインインしようとした') justwait.justWait(window, 1) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div/input').send_keys( config.MY_NAME) except NoSuchElementException: logger.warning('サインインに失敗した') try: logger.debug('サインイン確認しようとした') justwait.justWait(window, 1) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[3]/button[2]').click() except NoSuchElementException: logger.warning('サインイン確認に失敗した')
def delete(window): try: logger.debug('部屋消去開始') justwait.justWait(window, 3) window.find_element_by_css_selector('.btn-secondary').click() except NoSuchElementException: logger.warning('部屋消し失敗continue') else: logger.info('部屋消し準備ok') try: logger.debug('部屋消し確認します') justwait.justWait(window, 3) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[3]/button[2]').click() except NoSuchElementException: logger.warning('部屋消し確認失敗、部屋消しは手動で行ってください') else: logger.info('部屋を削除しました')
def init(): driver = webdriver.Firefox() logger.info("connect bigiri-ch") driver.get(config.BIGIRI_URL) # driver.maximize_window() justwait.justWait(driver, 5) logger.info("create room") createroom.create(driver) signin.signin(driver) options.setting(driver) logger.info("enter room") enter.enter(driver) logger.info("waiting...") waitphase.waiting(driver) while True: logger.info("answer phase") answerphase.answer(driver) if leaveflag.flag(driver): logger.info("post process") csvfiledownload.csvDL(driver) break if '回答フェーズ' == phase.getPhaseName(driver): logger.info("recreate room") newroomcreate.create__cannot_voting(driver) logger.info("vote phase") votephase.vote(driver) logger.info("result phase") resultphase.result(driver) newroomcreate.create__cannot_questioning(driver) logger.info("leave room") leave.leave(driver) logger.info("delete room") deleteroom.delete(driver) driver.close()
def close(window): try: justwait.justWait(window, 1) window.find_element_by_xpath( '/html/body/div/div/div[4]/div/div[1]/span[2]/button').click() except NoSuchElementException: return None else: justwait.justWait(window, 1) try: window.find_element_by_xpath( '/html/body/div/div/div[4]/div[1]/div/div/div[3]/button[2]').click( ) except NoSuchElementException: return None else: justwait.justWait(window, 1)
def answer(window): logger.debug('回答フェーズに入りました') justwait.justWait(window, 5) access.permission(window) svgtimer.svgtimerevent(window) closeanswer.close(window)
def setting(window): justwait.justWait(window, 5) # PW # window.find_element_by_xpath('/html/body/div/div[1]/div/div/div[2]/div[4]/div[2]/label/input').click() window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[5]/div[2]/label/input' ).click() window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[7]/div[2]/label/input' ).click() window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[8]/div[2]/label/input' ).click() window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[9]/div[2]/label/input' ).click() window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[10]/div[3]/label/input' ).click() window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[12]/div[2]/label/input' ).click() window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[13]/div[2]/label/input' ).click() window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[14]/div[2]/label/input' ).click() window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[15]/div[2]/label/input' ).click() window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[16]/div[3]/label/input' ).click() # 投票制限 window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[17]/div[2]/label/input' ).click() justwait.justWait(window, 2) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[1]/input').send_keys( config.ROOM_NAME) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[2]/textarea').send_keys( config.ROOM_DESCRIPTION) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[3]/input').send_keys( config.REF_URL) # window.find_element_by_xpath('/html/body/div/div[1]/div/div/div[2]/div[4]/div[3]/input').send_keys(config.PASSWD) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[5]/div[3]/input').send_keys( config.PRIORITY_TIME) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[8]/div[3]/input').send_keys( config.ANSWER_TIME) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[9]/div[3]/input').send_keys( config.ANSWER_LIMIT) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[13]/div[3]/input').send_keys( config.VOTE_TIME_BASE) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[13]/div[4]/input').send_keys( config.VOTE_TIME_COEFFICIENT) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[14]/div[3]/input').send_keys( config.VOTE_LIMIT_PER_QUESTION) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[2]/div[15]/div[3]/input').send_keys( config.VOTE_LIMIT_PER_ANSWER) justwait.justWait(window, 1) window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[3]/button[2]').click()
def permission(window): def __find_css_selector(selector): try: window.find_element_by_css_selector(selector) except NoSuchElementException: return False else: return True def __wrapper_find_css_element(selector): try: ele = window.find_element_by_css_selector(selector) except NoSuchElementException: pass except: pass else: return ele def __wrapper_find_css_elements(selector): try: ele_list = window.find_elements_by_css_selector(selector) except NoSuchElementException: pass except: pass else: return ele_list def __wrapper_find_tag_element(selector): try: ele = window.find_element_by_tag_name(selector) except NoSuchElementException: pass except: pass else: return ele try: justwait.justWait(window, 2) window.find_element_by_xpath('/html/body/div/div/button').click() except NoSuchElementException: pass else: justwait.justWait(window, 1) try: allow_buttons = window.find_elements_by_css_selector( 'body > div > div.modal > div > div > div.modal-body > div > div > div > div.card-footer > div > button:nth-child(3)' ) except: pass else: for allow in allow_buttons: if '追加' in allow.text: justwait.justWait(window, 1) allow.click() justwait.justWait(window, 1) try: window.find_element_by_xpath( '/html/body/div/div[1]/div/div/div[1]/button/span').click() except NoSuchElementException: pass else: justwait.justWait(window, 1)
def create__cannot_voting(window): """ こちらの場合、いつまで経っても回答フェーズであるため フェーズ名を監視します """ justwait.justWait(window, 2) if '回答フェーズ' == phase.getPhaseName(window): leave.leave(window) justwait.justWait(window, 3) deleteroom.delete(window) justwait.justWait(window, 3) createroom.create(window) justwait.justWait(window, 1) options.setting(window) justwait.justWait(window, 1) enter.enter(window) justwait.justWait(window, 1) waitphase.waiting(window)
def create__cannot_questioning(window): justwait.justWait(window, 2) if '結果フェーズ' == phase.getPhaseName(window): if isExistClassElement(window, '.modal'): window.find_element_by_xpath('/html/body/div/div[1]/div/div/div[1]/button/span').click() leave.leave(window) justwait.justWait(window, 3) deleteroom.delete(window) justwait.justWait(window, 3) createroom.create(window) justwait.justWait(window, 1) options.setting(window) justwait.justWait(window, 1) enter.enter(window) justwait.justWait(window, 1) waitphase.waiting(window)