def signalTrigger(stockcode): """base on technical indicator ,trigger order signals ,captalized word means dealing Long terms """ maLine_lst = DealDatum[stockcode]['mas'] macd_lst = DealDatum[stockcode]['macd'] xsLine_lst = DealDatum[stockcode]['xs'] flux_lst = DealDatum[stockcode]['flux'] wav_lst = DealDatum[stockcode]['wave'] highlow_lst = DealDatum[stockcode]['turtle'] volmin_lst = DealDatum[stockcode]['volmin'] print "stock code ====> ",stockcode print "Ma ==>", maLine_lst print "XS ==>",xsLine_lst print "Vol in 1 min,mean, std===>",volmin_lst, np.mean(volmin_lst),np.std(volmin_lst) print "Wave range list,mean ,std ==>",wav_lst,np.mean(wav_lst),np.std(wav_lst) print "20days high low pos ===>" ,highlow_lst print "MACD ===>" ,macd_lst #maLine_lst[0][-2:] # MA4 line last 2 points #maLine_lst[1][-2:] # MA10 line last 2 points #utilities.ifLineCross(line2p,Line2p) MA4_10 = ifLineCross(maLine_lst[0],maLine_lst[1]) MA10_40 = ifLineCross(maLine_lst[1],maLine_lst[2]) MACD_DIF_DEA = ifLineCross(macd_lst[0],macd_lst[1]) print "MA4_10",MA4_10 print "MA10_40",MA10_40 print "MACD DIF vs Dea",MACD_DIF_DEA utilities.pause()
def main(): try: base_url = "http://teach.speakagent.com/#" driver = webdriver.Chrome() # driver = webdriver.Firefox() data = [] for lpk, lipk in pks: path = "/lessons/preview/{lpk}/picturepairs/{lipk}/".format( lpk=lpk, lipk=lipk) url = base_url + path driver.get(url) pause(7, "Loading up page") btn = driver.find_element_by_class_name("btn-with-symbol") btn.click() rounds, result, last_card = play_game(driver) data.append((lpk, lipk, rounds, result, last_card)) print_results(data) pause(2) except Exception as inst: print "Error", inst, inst.args pass # At least let me get my data return driver, data
def add_tall_tales(driver): ttbtn = driver.find_element_by_id("tallTalesLabel") ttbtn.click() next_btn = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/span") next_btn.click() pause(2) tales = driver.find_elements_by_name("tales") tales[0].click()
def play_game(driver): # We're going to keep clicking random items until we run out of screens while True: cards = driver.find_elements_by_class_name('lexeme') try: choice(cards).click() except ElementNotInteractableException: print "Game done" return pause(3)
def add_vocab_lab(driver): vlbtn = driver.find_element_by_id("vocabLabLabel") vlbtn.click() next_btn = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/span") next_btn.click() pause(3) vls = driver.find_elements_by_name("vocab") vls[0].click() save_btn = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/div/form/div[41]/button") save_btn.click()
def add_text_activity(driver): txtbtn = driver.find_element_by_id("textLabel") txtbtn.click() next_btn = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/span") next_btn.click() pause(2) ttl = driver.find_element_by_id("li_title") ttl.send_keys("Selenium text activity") bdy = driver.find_element_by_name("text") bdy.send_keys("This is some sample text. Generated by Selenium automated test suite.") sbmt = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/form/div[3]/button") sbmt.click()
def add_video(driver, url="https://www.youtube.com/watch?v=z_yeSidJNcE"): videobtn = driver.find_element_by_id("videoLabel") videobtn.click() pause(2) next_btn = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/span") next_btn.click() vurl = driver.find_element_by_id("video_url") vurl.send_keys(url) ttl = driver.find_element_by_id("video_title") ttl.send_keys("Selium video") sbmt = driver.find_element_by_xpath("/html/body/div[1]/div/div/div[2]/form/div[3]/button") sbmt.click()
def play_game(driver): cards = driver.find_elements_by_class_name("word-card") cards[0].click() pause(3) for i in range(len(cards) - 1): nextbtn = driver.find_element_by_class_name('next-word') nextbtn.click() pause(3) allbtn = driver.find_element_by_xpath( "/html/body/section/div/ui-view/aside/a[1]") allbtn.click()
def add_words(driver): data = [] driver.find_element_by_partial_link_text("ADD WORDS").click() words = ['apple', 'blue', 'button', 'auto'] for word in words: driver.find_element_by_name("new_target_word-0").send_keys(word) pause(3, "waiting for words") wd = driver.find_element_by_xpath("//form[2]/div/div[2]/a[1]/div") data.append(("Word", wd.text)) wd.click() driver.find_element_by_name("new_target_word-0").clear() driver.find_element_by_xpath("//form[2]/div/div[3]/div[1]/input").click() return data
def create_lesson_from_wl(driver): ''' Creates a lesson from the 'create lesson' button on a wordlist. Assumes that the wordlist the 'create lesson' button is active. ''' btn = driver.find_element_by_xpath("/html/body/section/div/ui-view/div/div/div[2]/div[3]/button") btn.click() pause(5) title = driver.find_element_by_id("wl-new-title") title.clear() t = "Selenium test lesson from wl " + datetime.now().strftime("%Y-%m-%d %H:%M") title.send_keys(t) # Find by ID, not xpath btn = driver.find_element_by_id("save-lesson") btn.click()
def start_game_play(player, gameDisplay): print(111111111111111111) w, h = pygame.display.get_surface().get_size() music_player = music.Music_Player() music_player.play_ambtrack2() gameDisplay.fill(config.black) buttons = [ Button("BACK", config.white, pygame.font.Font("assets/fonts/CHILLER.ttf", 70), (90, 60), gameDisplay) ] gui = pygame.Surface((w, h)) while True: for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: global paused paused = True print(420420420) utilities.pause() #if s button is pressed save the character's stats if event.key == pygame.K_s: print('saved the game') utilities.save(player) #if l button is pressed load the character's stats if event.key == pygame.K_l: utilities.load() player.pos = utilities.loaddata['pos'] player.health = utilities.loaddata['health'] player.actions = utilities.loaddata['actions'] player.items = utilities.loaddata['items'] player.hp = utilities.loaddata['hp'] elif (event.type == pygame.QUIT): pygame.quit() quit() elif (event.type == pygame.MOUSEBUTTONDOWN and event.button == 1 and buttons[0].rect.collidepoint(pygame.mouse.get_pos())): pass # main_menu() # for button in buttons: # Button.check_Hover(button, gameDisplay) pygame.display.update() gui.fill(config.white) gameDisplay.blit(gui, (0, 0)) game_start(player, gameDisplay) clock.tick(15)
def create_student(driver): ''' This is all the logic related to the creation of multiple students in the previously created classroom. ''' return_data = [] driver.find_element_by_id('add-classroom-student').click() pause(3) time = datetime.now().strftime("%Y-%m-%d %H:%M") students_names = ('Selenium Test 1 %s, Selenium Test 2 %s') % (time, time) driver.find_element_by_id('add-student-names').send_keys(students_names) return_data.append(("students", students_names)) driver.find_element_by_id('add-student-btn').click() return return_data
def update_student(driver): return_data = [] driver.find_element_by_id('edit-student-button').click() time = datetime.now().strftime("%Y-%m-%d %H:%M") new_student_name = ('Selenium Edit Student %s') % (time) srudent_name = driver.find_element_by_id('input-student-edit-name') srudent_name.clear() srudent_name.send_keys(new_student_name) return_data.append(("new student name", new_student_name)) driver.find_element_by_id('update-student-btn-1').click() pause(6) driver.find_element_by_id('cancel-student-btn-1').click() return return_data
def check_for_bad(driver): # If we find a red word, put it in the next empty div # But first, check! bad = get_bads(driver) print "Bad:", bad source_area, target_area = driver.find_elements_by_class_name( 'advancedDemo') targets = target_area.find_elements_by_class_name('itemlist') print "Targets:", targets if not bad: return bad, targets num = len(targets) print "Num", num dropped = "" # TODO: We need to keep track of where we dropped it for i in range(num): print "Round", i bad = get_bads(driver) print "Bads:", bad if not bad: return bad, targets targets = target_area.find_elements_by_class_name('itemlist') print "Targets:" for target in targets: print "\t", target if targets[i]._id == dropped: print "Same slot as last round. Skip" continue if targets[i].text: print "There's text. Something is already here. Assuming it's correct for now." continue bad[0].click() targets[i].click() dropped = targets[i]._id pause(1, "Pausing for next bit") return bad, targets
def checkToDeal(name, momentPrice): """ check the previous 1 day done transaction , decide when to bid again just for the thought of higher frequency of transaction""" #global todayTask_lst name = name[2:] logger.info ( "\n ===Check Deal ====>> Name== %s"%name) dealtype = '' BidExecuted = False taskLst = DealDatum['todayTask_lst'] check_lst = [row for row in taskLst if row[0] == name] check_lst.sort(lambda x, y: cmp(x[1], y[1])) # the min at first min==>->big sequence logger.info("check previous order list ===>%s<==="%check_lst) #signalTrigger(name) checkLatestTrend(name,momentPrice) print "pause inside checkToDeal function" utilities.pause() #logger.debug(" \n ==Show the loop List ==> \n %s "%check_lst) for order in check_lst: #[['300070', -1, 46.83, 100.0, 4683.0], ['300... # stockCode , sellbuyFlag , dealATprice,Volumn = oder[0],order[1] , order[2], order[3] #only sell last bought, leave buying done manually!!r if order[3] < 0 : # Cancelled Bidding continue # next one, if vol < 0 means a canceled order elif order[1] == 1 : # First check previous 1 days Sold Shares Volumn , buy again #if utilities.percentValue(0.997*momentPrice,order[2]) > 4.0 : # !!! need more consideration!!!! if (0.998*momentPrice-order[2])*order[3] < -159.0 : dealtype = "buy" if momentPrice * int(order[3]) > 5000.0 : # should improve if split vol may cause a tax or fee rise!!! buy_vol = int(5000.0/momentPrice/100)*100+100 #ignore the available money deal_info = [order[0],momentPrice+0.1 ,buy_vol] #first to check else: deal_info = [order[0], momentPrice+0.1,int(order[3])] #first to check elif order[1] == -1 : if (0.997*momentPrice-order[2])*order[3] > 99.0 : dealtype = "sell" #!!!order[2] far less thean momentPrice, Deal should be committed right now deal_info = [order[0],order[2] ,int(order[3])] if dealtype == '' : break # out the loop ,cause same staock in min 2 max order else : callAutoTransaction(dealtype,deal_info) logger.info(">>====Sell stock done by Bidding \n %s====>>>"%deal_info) DealDatum['todayTask_lst'].remove(order) #todayTask_lst.remove(order) # remove from the global task list BidExecuted = True break # just wait for nex moment another round deal check return BidExecuted
def FeaturesOfHoldings(stockcodeList): """daily traits of the Holdings TODO 1: to see 1 min trading vol statistics""" preDate = 20130329 print stockcodeList for stockcode in stockcodeList: stockname = "sh"+stockcode if stockcode[:2] == "60" else "sz"+stockcode filename = stockname[2:]+".day" instance = utilities.prepareStock(filename,100) sdatum = instance.getPrevDateDatum(preDate,100) close_np, vol_np = sdatum.T[4]/100.0,sdatum.T[6] logger.info("****************\n previous Date Datum list ===> \n %s "% sdatum.T[0][-5:] ) mas_lst = utilities.getMAs(close_np,3) macd_np = Math.MACD(close_np,6) #print "MACD ap array of last 6==>", macd_np xs_lst = Math.XSchannel(sdatum,5) #<<<<<<< local # volma_np = np.array(Math.getMovingAverages(vol_np,10)) #VOL 6 10 days MA # minuteVol = np.round(volma_np/240.0 ,3) #compare to the volumn from hq sina to check how wide is the diff!! # print "1minutes Vol 10 day list",minuteVol[-20:] #got to be divided by 10K, should compare to vol diff 1 min #======= volma_np = np.array(Math.getMovingAverages(vol_np,10)) #VOL 6 10 days MA minuteVol = np.round(vol_np/240.0 ,0)[-10:] #compare to the volumn from hq sina to check how wide is the diff!! #print "1minutes Vol 10 day list",minuteVol[-10:] #got to be divided by 10K #>>>>>>> other wav_np = Math.getWavingRange(sdatum) highlow20 = utilities.getTurtlePos(close_np) #print "waving diff==>" ,wav_np #vcohlst = Math.getVCOHL(sdatum) #print "VolX CloseOpenHighLow ==> ",vcohlst fluxpare_np = Math.getFluxPare(sdatum,10) #logger.debug("flux pare uprate , vol ==>\n %s "%fluxpare_np ) stock_tech_stat = { 'mas': mas_lst, 'macd':macd_np, 'volmin':minuteVol, 'xs': xs_lst, 'wave': wav_np,'flux':fluxpare_np, 'turtle':highlow20 } stockcode = stockcode[2:] DealDatum[stockcode] = stock_tech_stat logger.debug("stock Tech statistics ==>\n %s "%DealDatum[stockcode]) #print stockcode #assert DealDatum['002236'] == DealDatum[stockcode] signalTrigger(stockcode) print DealDatum.keys() utilities.pause()
def create_classroom(driver): ''' This is all the logic related to the cretion of a classroom. ''' return_data = [] driver.find_element_by_id("n-classes").click() pause(5) driver.find_element_by_id("add-classroom").click() pause(1) title = driver.find_element_by_id("classroom-new-title") classroom_title = "Selenium test " + datetime.now().strftime( "%Y-%m-%d %H:%M") return_data.append(("title", classroom_title)) title.send_keys(classroom_title) driver.find_element_by_id("classroom-new-description").send_keys( "Description Test") section_name = "Section Name Test" driver.find_element_by_id("classroom-new-section-name").send_keys( section_name) driver.find_element_by_id("classroom-new-add-class-btn").click() pause(5, "Loading before returning") driver.find_element_by_link_text(classroom_title + " | " + section_name).click() return return_data
def get_word(driver): used = [] pause(5, "Letting Annie talk 2") btn = driver.find_element_by_xpath("//*[contains(text(), 'Next')]") btn.click() pause(5, "Letting Annie talk 3") ings = get_ingredients(driver) blanks = driver.find_elements_by_class_name('border-bottom-lines') combos = itertools.combinations(range(len(ings)), len(blanks)) # NEXT: Click ingredients until mix can be interacted with. Add them to used. for i, j in combos: print "Trying", i, j try: ings[i].click() ings[j].click() except ElementNotInteractableException: print "Returning..." continue driver.find_element_by_link_text('Mix!').click() pause(3, "Waiting for mixing animation")
def main(): base_url = "http://127.0.0.1:5000/lingshare-dev/#" lpk = '2103' lipk = '8638' path = "/lessons/preview/{lpk}/picturepairs/{lipk}/".format(lpk=lpk, lipk=lipk) url = base_url + path data = [] driver = webdriver.Firefox() driver.get(url) pause(5, "Loading up page") driver.find_element_by_xpath( "/html/body/section/div/ui-view/div[3]/div[1]/div[1]/div[2]/button" ).click() pause(2) play_game(driver) return driver, data
def main(): base_url = "http://127.0.0.1:5000/lingshare-dev/#" driver = webdriver.Firefox() driver.get(base_url) pause(5, "Loading up page") teacher_login(driver) pause(5) data = create_classroom(driver) pause(5) data.extend(create_student(driver)) pause(5) data.extend(update_classroom(driver)) return driver, data
def main(wlpk=2545): base_url = "http://127.0.0.1:5000/lingshare-dev/#" wl_path = "/author/wordlists/{}/edit/".format(wlpk) driver = webdriver.Firefox() driver.get(base_url) pause(5) teacher_login(driver) pause(5) driver.get(base_url+wl_path) pause(5) create_lesson_from_wl(driver) pause(5) add_activities(driver) return driver
def main(): base_url = "http://127.0.0.1:5000/lingshare-dev/#" driver = webdriver.Firefox() driver.get(base_url) pause(5, "Loading up page") teacher_login(driver) pause(5) data = create_wl(driver) pause(5) data.extend(add_words(driver)) pause(5) check_data(driver, data) return driver, data
def main(): base_url = "http://127.0.0.1:5000/lingshare-dev/#" lpk = '2103' lipk = '8638' path = "/lessons/preview/{lpk}/picturepairs/{lipk}/".format( lpk=lpk, lipk=lipk) url = base_url + path data = [] # driver = webdriver.Firefox() driver = webdriver.Chrome() driver.get(url) pause(5, "Loading up page") btn = driver.find_element_by_class_name("btn-with-symbol") btn.click() pause(2) play_game(driver) return driver, data
def play_game(driver): found_words = [] btn = driver.find_element_by_xpath("//*[contains(text(), 'Play Now!')]") btn.click() pause(5, "Allowing game to load") # There's an offscreen non-clickable play now btn = driver.find_elements_by_xpath( "//*[contains(text(), 'Play Now!')]")[1] btn.click() pause(5, "Let Annie talk...") words = driver.find_elements_by_class_name("bold") n = 0 for word in words: if word.text: n += 1 for i in range(n): words = driver.find_elements_by_class_name("bold") found_words.append(words[i].text) words[i].click() get_word(driver)
def add_activities(driver): btn = driver.find_element_by_link_text("ADD ACTIVITIES") btn.click() add_scramble(driver) pause(3) # add_tall_tales() # pause(3) btn = driver.find_element_by_link_text("ADD ACTIVITIES") btn.click() add_vocab_lab(driver) pause(3) btn = driver.find_element_by_link_text("ADD ACTIVITIES") btn.click() add_video(driver) pause(3) btn = driver.find_element_by_link_text("ADD ACTIVITIES") btn.click() add_text_activity(driver) pause(3)
def start_game(driver): driver.execute_script("window.scrollTo(0, 1080)") load_btn = driver.find_element_by_class_name('btn-container-new-game') load_btn.click() pause(5, "Wait for gremlins") start_btn = driver.find_element_by_xpath( '//*[contains(text(),"Start Game")]') start_btn.click() pause(1, "Wait for screen to load") driver.execute_script("window.scrollTo(0, 1080)") pick_level = driver.find_element_by_xpath( '//*[contains(text(),"Pick Level")]') pick_level.click() pause(3, "Picking a level") grs = driver.find_elements_by_class_name("gremling-box") grs[-1].click() # Only the second one works, since that's our active one. next_btn = driver.find_elements_by_xpath('//*[contains(text(),"Next")]')[1] next_btn.click()
def create_wl(driver): return_data = [] wlnav = driver.find_element_by_id("n-wordlist") wlnav.click() pause(3) addwl = driver.find_element_by_id("add-wordlist") addwl.click() title = driver.find_element_by_id("wl-new-title") t = "Selenium test " + datetime.now().strftime("%Y-%m-%d %H:%M") return_data.append(("title", t)) title.send_keys(t) lang = driver.find_element_by_xpath( "//select[@id='languagesDropdown']/option[text()='English (U.S.)']") lang.click() tags = driver.find_element_by_name("tags") tags.send_keys("selenium1, selenium2") grades = driver.find_element_by_name("gradesSelection") grades.click() pause(1) gr = grades.find_element_by_xpath("//ul/li/div[6]/span") return_data.append(("Grade", gr.text)) #Save the grade for later. gr.click() # Click to close the drop down driver.find_element_by_xpath("/html/body").click() subs = driver.find_element_by_name("subjectsSelection") subs.click() sub = driver.find_element_by_xpath( "//form/fieldset/div[3]/div[2]/div[1]/ul/li/div[3]/span") return_data.append(("Subject", sub.text)) sub.click() # Close dropdown driver.find_element_by_xpath("/html/body").click() driver.find_element_by_id("wl-save").click() pause(3, "Loading before returning") return return_data
def main(): # http://127.0.0.1:5000/lingshare-dev/#/lessons/preview/2103/review/8637 base_url = "http://127.0.0.1:5000/lingshare-dev/#" lpk = '2103' lipk = '8788' path = "/lessons/preview/{lpk}/vocablab/{lipk}/".format(lpk=lpk, lipk=lipk) url = base_url + path data = [] driver = webdriver.Firefox() driver.get(base_url) pause(5, "Loading up page") teacher_login(driver) pause(5) driver.get(url) pause(5) play_game(driver) return driver, data
def play_game(driver): # We're going to keep clicking random items until we run out of screens rounds = 0 cards = driver.find_elements_by_class_name('lexeme') imgs = [] i = 0 while True: words = [] img = driver.find_element_by_class_name('large-card') if img.get_attribute('src') not in imgs: imgs.append(img.get_attribute('src')) for card in cards: words.append(card.text) try: try: cards[i].click() i += 1 except IndexError: pause(10, "Ugh, need to load more...") cards = driver.find_elements_by_class_name('lexeme') cards[i].click() i += 1 pause(3, "Letting the new screen load if needed") cards = driver.find_elements_by_class_name('lexeme') curr_words = [] for card in cards: curr_words.append(card.text) print "Checking", words, curr_words if not words == curr_words: rounds += 1 i = 0 except ElementNotInteractableException: print "Game done" return rounds, "Done", imgs except ElementNotVisibleException: print "Game done 2" return rounds, "Done 2", imgs pause(3)
def create_student(driver): return_data = [] driver.find_element_by_id("n-classes").click() pause(5) driver.find_element_by_id('your-students-tab').click() driver.find_element_by_id("add-student").click() pause(1) time = datetime.now().strftime("%Y-%m-%d %H:%M") student_name = ('Selenium Test %s') % (time) driver.find_element_by_id('add-student-names').send_keys(student_name) return_data.append(("student", student_name)) driver.find_element_by_id('add-student-btn').click() pause(5, "Loading before returning") driver.find_element_by_link_text(student_name).click() return return_data
a = int(input('Choice No : ')) if(a == 1): url = input('Enter the url of the file you wish to download :\n') download_object = download.Download_object(url, 4) if(download_object in list_of_downloads): print("Already being downloaded") else: list_of_downloads.append(download_object) utilities.init_download(download_object) t= Thread(target=utilities.downNow, args = (download_object,)) t.start() elif(a == 2): if(len(list_of_downloads)==1): if(list_of_downloads[0].paused ==0): utilities.pause(list_of_downloads[0]) print('Percentage completed : ', (list_of_downloads[0].current_size//list_of_downloads[0].size)*100) else: print('Already paused') else: for i in range(len(list_of_downloads)): print(i+1, list_of_downloads[i].fileName) x = int(input('Enter the download you want to pause : ')) if((x)>len(list_of_downloads)): print('Invalid choice.') else: if(list_of_downloads[x-1].paused == 0): utilities.pause(list_of_downloads[x-1]) print('Percentage completed : ', (list_of_downloads[x-1].current_size//list_of_downloads[x-1].size)*100) else: print('Already paused')