Best Python code snippet using robotframework-appiumlibrary_python
kyabetsu.py
Source:kyabetsu.py
...48 await bot.send(ev, 'ä»å¤©å·²ç»é¢åè¿manaäº', at_sender=True)49 return50 db = UMSDao(uid)51 mana = 100052 storemana = int(db._find_by_id(uid))53 storemana += mana54 db._update_by_id(uid, storemana)55 lmt.increase(uid)56 await bot.send(ev, f'ç¾å°æåï¼é¢åäº{mana}ï¼å½åmanaæ°ä¸º{storemana}', at_sender=True)57 except Exception as e:58 await bot.send(ev, f'æ¥è¯¢å¤±è´¥ï¼è¯·è系维æ¤ç»è¿è¡è°æ{e}', at_sender=True)59@sv.on_fullmatch(('æ¥çå½åmana', 'æ¥çå½åçé£', 'ççè¿æå¤å°é±'))60async def viewMana(bot, ev: CQEvent):61 try:62 db = UMSDao(ev.user_id)63 mana = db._find_by_id(ev.user_id)64 await bot.send(ev, f'å½åmanaçæ°é为ï¼{mana}', at_sender=True)65 print(f'å½åmanaçæ°é为ï¼{mana}')66 except:67 await bot.send(ev, 'æ¥è¯¢å¤±è´¥ï¼è¯·è系维æ¤ç»è¿è¡è°æ', at_sender=True)68# typeï¼0为年å¨ï¼1为ç§åï¼2为æ°é²å¤§å¤´èæ°éï¼3为çèæ°é69@sv.on_fullmatch(('æ¥çå½å大头è', 'æ¥è¯¢å½å大头è', 'æ¥ç大头è', 'æ¥è¯¢å¤§å¤´è', 'ççè¿æå¤å°è', 'ççæå¤å°è', 'ççè'))70async def viewKyabetsu(bot, ev: CQEvent):71 try:72 db = KISDao(ev.user_id)73 freshNum = db._find_by_id(ev.user_id, 2)[0]74 rottenNum = db._find_by_id(ev.user_id, 3)[0]75 await bot.send(ev, f'\næ¨å½åçæ°é²å¤§å¤´èæ{freshNum}é¢ï¼\nè
çç大头èæ{rottenNum}é¢', at_sender=True)76 except:77 await bot.send(ev, 'æ¥è¯¢å¤±è´¥ï¼è¯·è系维æ¤ç»è¿è¡è°æ', at_sender=True)78@sv.on_prefix(('æ¥ç大头èä»·æ ¼', 'æ¥çä»·æ ¼', 'æ¥çå½åä»·æ ¼', 'ççç°å¨å¤å°é±', 'ççä»·æ ¼', 'ççèä»·', 'æ¥çèä»·'))79async def viewPrice(bot, ev: CQEvent):80 try:81 uid = ev.user_id82 for m in ev.message:83 if m.type == 'at' and m.data['qq'] != 'all':84 uid = int(m.data['qq'])85 db = KISDao(uid)86 pattern, seed = db._find_by_id(uid, 1)87 freshNum = db._find_by_id(ev.user_id, 2)[0]88 price, isBuy, isDisable, isShopClose = getCurPrice(pattern, seed)89 msg = f'å½åçä»·æ ¼ä¸º:{price}'90 if int(freshNum) == 0:91 msg += 'ï¼ä¸è¿ä½ æé没æ大头èå¦ï½'92 else:93 msg += f'ï¼ä½ æ{freshNum}棵大头èå¯ä»¥è¿è¡å®å'94 if isShopClose:95 msg = 'ååºå
³é¨äºï¼è¯·çå¾
è¥ä¸æ¶é´8:00 - 22:00åæ¥å
顾'96 if isDisable:97 msg = 'å½åæ¶é´ä¸å¯ä¹°å
¥åååº'98 if isBuy:99 msg = f'ä»å¤©æ¹åæ¥äºï¼å¯ä»¥ä»¥{price}çä»·æ ¼è´ä¹°å¤§å¤´èï¼æ¹åä¸å12ç¹å°±èµ°ï¼è¦æç´§æ¶é´å¦ï½'100 await bot.send(ev, msg, at_sender=True)101 except Exception as e:102 await bot.send(ev, 'æ¥è¯¢å¤±è´¥ï¼è¯·è系维æ¤ç»è¿è¡è°æ', at_sender=True)103@sv.on_prefix(('ä¹°å
¥å¤§å¤´è', 'ä¹°å
¥', 'è´ä¹°'))104async def buyKyabetsu(bot, ev: CQEvent):105 try:106 num = ev.message.extract_plain_text()107 num = f'{num}'.strip()108 if not num:109 await bot.send(ev, '请填åä¹°å
¥æ°é', at_sender=True)110 return111 if num.isdigit():112 num = math.floor(int(num))113 else:114 await bot.send(ev, '请填åæ°å', at_sender=True)115 return116 umdb = UMSDao(ev.user_id)117 if umdb.isInit == False:118 await bot.send(ev, '请åå§åmanaåå°è¯äº¤æ', at_sender=True)119 return120 # is_Friend = False121 uid = ev.user_id122 for m in ev.message:123 if m.type == 'at' and m.data['qq'] != 'all':124 uid = int(m.data['qq'])125 # is_Friend = True126 kidb = KISDao(uid)127 pattern, seed = kidb._find_by_id(uid, 1)128 price, isBuy, isDisable, isShopClose = getCurPrice(pattern, seed)129 if isBuy:130 mana = int(price) * num131 storemana = int(umdb._find_by_id(ev.user_id))132 if storemana < mana:133 msg = 'ä½ çmanaä¸å¤ä¹°è¿äºè'134 else:135 surplusmana = storemana - mana136 storenum = int(kidb._find_by_id(ev.user_id, 2)[0])137 newnum = storenum + num138 kidb._update_by_id(ev.user_id, 1, newnum)139 umdb._update_by_id(ev.user_id, surplusmana)140 msg = f'è±è´¹äº{mana}manaè´ä¹°äº{num}é¢å¤§å¤´èï¼å¤§å¤´èç°æ°é为{newnum}ï¼manaå©ä½{surplusmana}'141 else:142 msg = 'å½åæ¶é´ä¸å¯ä¹°å
¥'143 await bot.send(ev, msg, at_sender=True)144 except:145 await bot.send(ev, 'ä¹°å
¥å¤±è´¥ï¼è¯·è系维æ¤ç»è¿è¡è°æ', at_sender=True)146@sv.on_fullmatch(('all in', 'allin', 'èåå
¨ä¹°äº', 'ä¹°å
¥å
¨é¨'))147async def buyAllKyabetsu(bot, ev: CQEvent):148 try:149 umdb = UMSDao(ev.user_id)150 if umdb.isInit == False:151 await bot.send(ev, '请åå§åmanaåå°è¯äº¤æ', at_sender=True)152 return153 uid = ev.user_id154 for m in ev.message:155 if m.type == 'at' and m.data['qq'] != 'all':156 uid = int(m.data['qq'])157 kidb = KISDao(uid)158 pattern, seed = kidb._find_by_id(uid, 1)159 price, isBuy, isDisable, isShopClose = getCurPrice(pattern, seed)160 if isBuy:161 storemana = int(umdb._find_by_id(ev.user_id))162 num = math.floor(storemana / int(price))163 mana = int(price) * num164 surplusmana = storemana - mana165 storenum = int(kidb._find_by_id(ev.user_id, 2)[0])166 newnum = storenum + num167 kidb._update_by_id(ev.user_id, 1, newnum)168 umdb._update_by_id(ev.user_id, surplusmana)169 msg = f'è±è´¹äº{mana}manaè´ä¹°äº{num}é¢å¤§å¤´èï¼å¤§å¤´èç°æ°é为{newnum}ï¼manaå©ä½{surplusmana}'170 else:171 msg = 'å½åæ¶é´ä¸å¯ä¹°å
¥'172 await bot.send(ev, msg, at_sender=True)173 except:174 await bot.send(ev, 'ä¹°å
¥å¤±è´¥ï¼è¯·è系维æ¤ç»è¿è¡è°æ', at_sender=True)175@sv.on_prefix(('ååºå¤§å¤´è', 'ååº', 'åºå®'))176async def soldKyabetsu(bot, ev: CQEvent):177 try:178 num = ev.message.extract_plain_text()179 num = f'{num}'.strip()180 if not num:181 await bot.send(ev, '请填åååºæ°é', at_sender=True)182 return183 if num.isdigit():184 num = math.floor(int(num))185 else:186 await bot.send(ev, '请填åæ°å', at_sender=True)187 return188 umdb = UMSDao(ev.user_id)189 if umdb.isInit == False:190 await bot.send(ev, '请åå§åmanaåå°è¯äº¤æ', at_sender=True)191 return192 uid = ev.user_id193 for m in ev.message:194 if m.type == 'at' and m.data['qq'] != 'all':195 uid = int(m.data['qq'])196 kidb = KISDao(uid)197 storenum = int(kidb._find_by_id(ev.user_id, 2)[0])198 if storenum < num:199 await bot.send(ev, 'ååºçæ°é大äºæææ°', at_sender=True)200 return201 pattern, seed = kidb._find_by_id(uid, 1)202 price, isBuy, isDisable, isShopClose = getCurPrice(pattern, seed)203 if isShopClose:204 bot.send(ev, 'ååºå
³é¨äºï¼è¯·çå¾
è¥ä¸æ¶é´8:00 - 22:00åæ¥å
顾', at_sender=True)205 return206 if not isBuy and not isDisable:207 mana = int(price) * num208 storemana = int(umdb._find_by_id(ev.user_id))209 surplusmana = storemana + mana210 newnum = storenum - num211 kidb._update_by_id(ev.user_id, 1, newnum)212 umdb._update_by_id(ev.user_id, surplusmana)213 msg = f'ååºäº{num}棵大头èè·åäº{mana}manaï¼manaç°æ¥æ{surplusmana}ï¼å¤§å¤´èå©ä½æ°é为{newnum}'214 else:215 msg = 'å½åæ¶é´ä¸å¯ååº'216 await bot.send(ev, msg, at_sender=True)217 except:218 await bot.send(ev, 'æ¥è¯¢å¤±è´¥ï¼è¯·è系维æ¤ç»è¿è¡è°æ', at_sender=True)219@sv.on_prefix(('æäº', 'èåå
¨åäº', 'ååºå
¨é¨'))220async def soldAllKyabetsu(bot, ev: CQEvent):221 try:222 umdb = UMSDao(ev.user_id)223 if umdb.isInit == False:224 await bot.send(ev, '请åå§åmanaåå°è¯äº¤æ', at_sender=True)225 return226 uid = ev.user_id227 for m in ev.message:228 if m.type == 'at' and m.data['qq'] != 'all':229 uid = int(m.data['qq'])230 kidb = KISDao(uid)231 storenum = int(kidb._find_by_id(ev.user_id, 2)[0])232 pattern, seed = kidb._find_by_id(uid, 1)233 price, isBuy, isDisable, isShopClose = getCurPrice(pattern, seed)234 if isShopClose:235 bot.send(ev, 'ååºå
³é¨äºï¼è¯·çå¾
è¥ä¸æ¶é´8:00 - 22:00åæ¥å
顾', at_sender=True)236 return237 if not isBuy and not isDisable:238 mana = int(price) * storenum239 storemana = int(umdb._find_by_id(ev.user_id))240 newmana = storemana + mana241 newnum = 0242 kidb._update_by_id(ev.user_id, 1, newnum)243 umdb._update_by_id(ev.user_id, newmana)244 msg = f'ååºäº{storenum}棵大头èè·åäº{mana}manaï¼manaç°æ¥æ{newmana}ï¼å¤§å¤´èå©ä½æ°é为{newnum}'245 else:246 msg = 'å½åæ¶é´ä¸å¯ååº'247 await bot.send(ev, msg, at_sender=True)248 except:249 await bot.send(ev, 'æ¥è¯¢å¤±è´¥ï¼è¯·è系维æ¤ç»è¿è¡è°æ', at_sender=True)250days_list = ["æ¥", "ä¸", "äº", "ä¸", "å", "äº", "å
"]251@sv.on_prefix(('æ¥ç大头èè¶å¿'))252async def viewPlot(bot, ev: CQEvent):253 try:254 db = KISDao(ev.user_id)255 year_week = db._find_by_id(ev.user_id, 0)[0]256 pattern, seed = db._find_by_id(ev.user_id, 1)257 year = str(year_week)[0:4]258 week = str(year_week)[4:]259 price = getPrice(pattern, seed)260 days_index = getCurType()261 if days_index == 0:262 await bot.send(ev, 'ååºè¿æ²¡åï¼æ²¡æä»·æ ¼å¯æ¥è¯¢', at_sender=True)263 return264 else:265 price = price[0 : days_index + 1]266 x, y = {}, {}267 buyPrice = ''268 for key, value in enumerate(price):269 days = days_list[math.floor((key + 1) / 2)]270 time = 'ä¸å' if math.floor(key % 2) == 1 else 'ä¸å'...
chase_scraper.py
Source:chase_scraper.py
...24 options.add_argument("--disable-extensions")25 self.driver = webdriver.Chrome(options=options, executable_path=driver_path)26 def logon(self, username, password, wait_seconds=3):27 self.driver.get(CHASE_LOGIN_URL)28 # self._find_by_id(INPUT_LOGON_USERNAME_ID).send_keys(username)29 if password:30 self._find_by_id(INPUT_LOGON_PASSWORD_ID).send_keys(password)31 self._find_by_id(INPUT_LOGON_PASSWORD_ID).submit()32 time.sleep(wait_seconds)33 def quit(self, wait_seconds=5):34 time.sleep(wait_seconds) # give time to finish last action35 if self.driver:36 self.driver.quit()37 self.driver = None38 def download_statement(self, account: cfg.Account, date_from, date_to):39 logging.info(f"Retrieving statement for account {account.alias} from {date_from} to {date_to}")40 self.driver.get(CHASE_STATEMENTS_URL + account.url_param)41 time.sleep(1)42 activity_element = self._find_by_id(account.div_id)43 activity_element.click()44 time.sleep(.5)45 date_link_element = self._find_by_xpath(DROPDOWN_DATE_RANGE_XPATH)46 date_link_element.click()47 self._find_by_id(INPUT_DATE_FROM_ID).send_keys(date_from)48 self._find_by_id(INPUT_DATE_TO_ID).send_keys(date_to)49 self._find_by_id(BUTTON_DOWNLOAD_ID).click()50 self._find_by_id(BUTTON_DOWNLOAD_OTHER_ID).click()51 time.sleep(1)52 def _find_by_id(self, elt_id, timeout_s=10):53 return self._find(self.driver.find_element_by_id, [elt_id], timeout_s)54 def _find_by_ids(self, elt_id_list, timeout_s=10):55 return self._find(self.driver.find_element_by_id, elt_id_list, timeout_s)56 def _find_by_xpath(self, xpath, timeout_s=10):57 return self._find(self.driver.find_element_by_xpath, [xpath], timeout_s)58 @staticmethod59 def _find(finder, elt_id_list, timeout_s):60 max_time = time.time() + timeout_s61 item = None62 while not item and time.time() < max_time:63 for elt_id in elt_id_list:64 try:65 item = finder(elt_id)66 except Exception as e:...
database.py
Source:database.py
...16orders.append({'id':4, 'customerId': 0, 'productId':1, 'date':"2017-09-01"})17orders.append({'id':5, 'customerId': 1, 'productId':2, 'date':"2020-12-17"})18################################################################################19# The following three functions are only for mocking data - they should be removed,20def _find_by_id(things, id):21 results = [thing for thing in things if thing['id'] == id]22 if ( len(results) > 0 ): 23 return results[0]24 else:25 return None26def _upsert_by_id(things, thing):27 if 'id' in thing:28 index = [i for i, c in enumerate(things) if c['id'] == thing['id']]29 if ( len(index) > 0 ) :30 del things[index[0]]31 things.append(thing)32 else:33 thing['id'] = len(things)34 things.append(thing)35def _delete_by_id(things, id):36 index = [i for i, c in enumerate(things) if c['id'] == id]37 if ( len(index) > 0 ) :38 del things[index[0]]39# The following functions are REQUIRED - you should REPLACE their implementation40# with the appropriate code to interact with your PostgreSQL database.41def initialize():42 # this function will get called once, when the application starts.43 # this would be a good place to initalize your connection and create44 # any tables that should exist, but do not yet exist in the database.45 print('Nothing to do here...')46def get_customers():47 return customers48def get_customer(id):49 return _find_by_id(customers, id)50def upsert_customer(customer):51 _upsert_by_id(customers, customer)52def delete_customer(id):53 _delete_by_id(customers, id)54 55def get_products():56 return products57def get_product(id):58 return _find_by_id(products, id)59def upsert_product(product):60 _upsert_by_id(products, product)61def delete_product(id):62 _delete_by_id(products, id)63def get_orders():64 for order in orders:65 order['product'] = _find_by_id(products, order['productId'])66 order['customer'] = _find_by_id(customers, order['customerId'])67 return orders68def get_order(id):69 return _find_by_id(orders, id)70def upsert_order(order):71 _upsert_by_id(orders, order)72def delete_order(id):73 _delete_by_id(orders, id)74# Return a list of products. For each product, build75# create and populate a last_order_date, total_sales, and76# gross_revenue property. Use JOIN and aggregation to avoid77# accessing the database more than once, and retrieving unnecessary78# information79def sales_report():80 products = get_products()81 for product in products:82 orders = [o for o in get_orders() if o['productId'] == product['id']] 83 orders = sorted(orders, key=lambda k: k['date']) ...
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!!