How to use _find_by_id method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

kyabetsu.py

Source:kyabetsu.py Github

copy

Full Screen

...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 '下午'...

Full Screen

Full Screen

chase_scraper.py

Source:chase_scraper.py Github

copy

Full Screen

...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:...

Full Screen

Full Screen

database.py

Source:database.py Github

copy

Full Screen

...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']) ...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run robotframework-appiumlibrary automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful