Best Python code snippet using websmith_python
GMONavigator.py
Source:GMONavigator.py  
1#!/usr/bin/env python32# -*- coding: utf-8 -*-3"""4Created on Tue Jun 19 21:58:49 20185@author: iku6"""7import os8import sys9current_dir = os.path.abspath(os.path.dirname(__file__))10sys.path.append(current_dir + "/../common")11sys.path.append(current_dir + "/../private")12import threading13from ChromeHandler import ChromeHandler14import OptionParser15import Nikkei225fParser16from OptionDb import OptionDb, TickTable17from OptionPrice import importFromTable18from datetime import datetime, timedelta19import time20from CalendarTime import Today, DeltaMonth21import account_click_sec as account22from Timer import Timer23#chrome1 = ChromeHandler()24chrome2 = ChromeHandler()25intervalSec = 0.126timer1 = None27timer2 = None28def now():29    return datetime.now()30class EveryMinutesTimer(object):31    32    def __init__(self, minutes):33        t = now()34        tnext = datetime(t.year, t.month, t.day, t.hour)35        self.minutes = minutes36        while tnext < t:37            tnext += timedelta(minutes=minutes)38        self.next_time = tnext39        40    def shouldDo(self):41        t = now()42        if t >= self.next_time:43            self.next_time += timedelta(minutes=self.minutes)44            return True45        else:46            return False47        48class EveryDayTimer(object):49    def __init__(self, hour, minute):50        t = now()51        self.hour = hour52        self.minute = minute        53        tnext = datetime(t.year, t.month, t.day) + timedelta(days=1)54        tnext += timedelta(hours=hour)55        tnext += timedelta(minutes=minute)56        self.next_time = tnext57        58    def shouldDo(self):59        t = now()60        if t >= self.next_time:61            tnext = datetime(t.year, t.month, t.day) + timedelta(days=1)62            tnext += timedelta(hours=self.hour)63            tnext += timedelta(minutes=self.minute)64            self.next_time = tnext65            return True66        else:67            return False    68    69class TickBuffer(object):70    def __init__(self, name):71        self.name = name72        self.buffer = []73        self.date = None74        75    def add(self, tick_list):76        if tick_list is None:77            print('error in add method')78            return None79        if len(tick_list) == 0:80            print('error in add method')81            return None82        83        tick = tick_list[-1]84        t = tick[0]85        out = None86        if self.date is None:87            self.date = datetime(t.year, t.month, 1)88        for tick in tick_list:89            [t, bid, ask] = tick90            if t.year > self.date.year or t.month > self.date.month:91                out = self.buffer.copy()92                self.buffer = []93                self.date = datetime(t.year, t.month, 1)94            self.buffer.append([t, bid, ask, (bid + ask) / 2, 0])95            96        return out97         98    def flush(self):99        out = self.buffer.copy()100        self.buffer = []101        self.date = None102        return out103    104def int2str(d, length):105    s = '0000' + str(d)106    n = len(s)107    return s[n - length: n]108def contractCode():109    t = Today()110    code = []111    for i in range(4):112        y = int2str(t.year, 4)113        m = int2str(t.month, 2)114        code.append(y + m)115        t += DeltaMonth(1)116            117    code.append('202075') # 11/20118    code.append('202076') # 11/27119    code.append('202077') # 12/6120    print(contractCode)121    return code 122def get225fPrice():123    codes = contractCode()124    month = codes[0]125    chrome1.clickButtonByName('reloadButton')126    parser = Nikkei225fParser.Nikkei225fParser(chrome1.html())127    nikkei225fPrices = parser.parse()128    if len(nikkei225fPrices) > 0:129        print(month, nikkei225fPrices[0])130        return nikkei225fPrices[0]131    else:132        return None133def getOptionPrices():134    codes = contractCode()135    for code in codes:136        try:137            chrome2.selectListByName('targetDeliveryMonth', code)138            chrome2.executeJS("changeDeliveryMonth('0')", [])139            getOptionPrice(code)140        except:141            continue142        143def getOptionPrice(theMonth):144    chrome2.clickButtonByName('reloadButton')145    parser = OptionParser.OptionParser(chrome2.html())146    prices = parser.parse(theMonth)147    db = OptionDb()148    for price in prices:149        price.description()   150    db.updatePrices(prices)151    return152    153   154def close():155    #chrome1.close()156    chrome2.close()157    pass158def login1():159    #chrome1 = ChromeHandler()160    url = account.URL161    userid = account.USERID162    password = account.PASSWORD163    chrome1.connect(url)164    time.sleep(5)165    chrome1.inputElement('j_username', userid)166    chrome1.inputElement('j_password', password)167    chrome1.clickButtonByName('LoginForm')168    chrome1.linkByClassName('js-fuop')169    #chrome1.linkByText('ãªãã·ã§ã³æ³¨æ')170    chrome1.linkByText('å
ç©æ³¨æ')171    return172def login2():173    #chrome2 = ChromeHandler()174    chrome2.connect(account.URL)175    time.sleep(5)176    chrome2.inputElement('j_username', account.USERID)177    chrome2.inputElement('j_password', account.PASSWORD)178    chrome2.clickButtonByName('LoginForm')179    chrome2.linkByClassName('js-fuop')180    chrome2.linkByText('ãªãã·ã§ã³æ³¨æ')181    return182def GMONavigator():183    scrape()184    185def scrape():186    #login1()187    #timer1 = Timer(0.1, get225fPrice)188    #timer1.run()189    190    login2()191    timer2 = Timer(2.0, getOptionPrices)192    timer2.run()193    194    pass195def test():196    login2()197    getOptionPrices()198    199if __name__ == "__main__":200    scrape()...test_links.py
Source:test_links.py  
...31def test_link_by_text(browser, page):32    '''Find web link elements by its href attribute.'''33    with Session(browser):34        Go(page)35        element = LinkByText('WebSmith')36        assert element.tag_name == 'a'...sample.py
Source:sample.py  
1#!/usr/bin/env python32# -*- coding: utf-8 -*-3"""4Created on Tue Jun 19 21:58:49 20185@author: iku6"""7import sys8sys.path.append("../common")9sys.path.append("../private")10import ChromeHandler as Chrome11chrome1 = Chrome.ChromeHandler()12def action():13    chrome1.clickButtonByName('reloadButton')14    try:15        chrome1.selectListByName('targetDeliveryMonth', '1234')16        chrome1.executeJS("changeDeliveryMonth('0')", [])17    except:18        print('error')19   20def close():21    chrome1.close()22    pass23def login():24    url = 'https://xxx.xxxx.xxxx.xxx.xxx'25    userid = 'id'26    password = 'pass'27    chrome1.connect(url)28    chrome1.inputElement('j_username', userid)29    chrome1.inputElement('j_password', password)30    chrome1.clickButtonByName('LoginForm')31    chrome1.linkByClassName('js-fuop')32    chrome1.linkByText('注æ')33    return34def test():35    login()36    action()37    close()38if __name__ == "__main__":...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
