Best Python code snippet using PyHamcrest_python
web_crawler.py
Source:web_crawler.py
1def craw_new_data(year,month,date):2 import requests3 import pandas as pd4 from bs4 import BeautifulSoup5 import numpy6 import csv7 import time8 9 info = f'{year}/{month}/{date}'10 url = 'https://www.taifex.com.tw/cht/3/optDailyMarketReport'11 payload = {'queryType':'2',12 'marketCode':'0',13 'dateaddcnt':'',14 'commodity_id':'TXO',15 'commodity_id2':'',16 'MarketCode':'0',17 'commodity_idt':'TXO',18 'commodity_id2t':'',19 'commodity_id2t2':'',20 'queryDate':info21 }22 encoding = 'utf8'23 r = requests.post(url,data=payload)24 r.encoding = encoding25 soup = BeautifulSoup(r.content, 'html.parser')26 data = pd.DataFrame(columns=['å¥ç´','å°ææ份(é±å¥)','å±¥ç´å¹','è²·è³£æ¬','éç¤å¹','æé«å¹','æä½å¹','æå¾æ交å¹','çµç®å¹','ç¤å¾äº¤ææ段æ交é','ä¸è¬äº¤ææ段æ交é','åè¨æ交é','æªæ²é·å¥ç´é'])27 append_list = {}28 count = 029 for i in soup.find_all('tr'):30 for j in i.find_all('td',class_ = '12bk'):31 count+=132 if count > 18:33 if (count-18)%13 == 0:34 data = data.append(append_list, ignore_index=True)35 append_list = {}36 append_list['å¥ç´'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')37 elif (count-18)%13 == 1:38 append_list['å°ææ份(é±å¥)'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')39 elif (count-18)%13 == 2:40 append_list['å±¥ç´å¹'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')41 elif (count-18)%13 == 3:42 append_list['è²·è³£æ¬'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')43 elif (count-18)%13 == 4:44 append_list['éç¤å¹'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')45 elif (count-18)%13 == 5:46 append_list['æé«å¹'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')47 elif (count-18)%13 == 6:48 append_list['æä½å¹'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')49 elif (count-18)%13 == 7:50 append_list['æå¾æ交å¹'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')51 elif (count-18)%13 == 8:52 append_list['çµç®å¹'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')53 elif (count-18)%13 == 9:54 append_list['ç¤å¾äº¤ææ段æ交é'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')55 elif (count-18)%13 == 10:56 append_list['ä¸è¬äº¤ææ段æ交é'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')57 elif (count-18)%13 == 11:58 append_list['åè¨æ交é'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')59 elif (count-18)%13 == 12:60 append_list['æªæ²é·å¥ç´é'] = j.text.replace('\n','').replace(' ','').replace('\t','').replace('\r','')61 try:62 data.to_csv(f'./static/option_data/option_data_{year}_{month}_{date}.csv',index=False,encoding='cp950')63 except:64 data.to_csv(f'../static/option_data/option_data_{year}_{month}_{date}.csv',index=False,encoding='cp950')65 return data66if __name__ == "__main__":...
leaderboard.py
Source:leaderboard.py
12class Leaderboard:34 def __init__(self):5 self.leaders = []6 self.tank_leaders = []7 self.fighter_leaders = []8 self.assassin_leaders = []9 self.cleric_leaders = []10 self.artificer_leaders = []11 self.mage_leaders = []12 self.dark_druid_leaders = []13 self.monk_leaders = []1415 def check_leaderboard(self, raid, hero, time):1617 def class_checks(board, raid, hero_stats):18 if len(board) < 10:19 board.append(hero_stats)20 board.sort(key=lambda x: x[1], reverse=False)21 else:22 for hero in board:23 if raid.difficulty > hero.difficulty:24 board.append(hero_stats)25 board.sort(key=lambda x: x[1], reverse=False)26 return True27 return False2829 def chop_tail(board):30 board.remove(board[-1])3132 append_list = [hero.name, raid.difficulty, hero.class_]3334 if hero.class_ == "Tank":35 chop = class_checks(self.tank_leaders, raid, append_list)36 if chop:37 chop_tail(self.tank_leaders)3839 elif hero.class_ == "Fighter":40 chop = class_checks(self.fighter_leaders, raid, append_list)41 if chop:42 chop_tail(self.fighter_leaders)4344 elif hero.class_ == "Assassin":45 chop = class_checks(self.assassin_leaders, raid, append_list)46 if chop:47 chop_tail(self.assassin_leaders)4849 elif hero.class_ == "Cleric":50 chop = class_checks(self.cleric_leaders, raid, append_list)51 if chop:52 chop_tail(self.cleric_leaders)5354 elif hero.class_ == "Mage":55 chop = class_checks(self.mage_leaders, raid, append_list)56 if chop:57 chop_tail(self.mage_leaders)5859 elif hero.class_ == "Artificer":60 chop = class_checks(self.artificer_leaders, raid, append_list)61 if chop:62 chop_tail(self.artificer_leaders)6364 elif hero.class_ == "Dark Druid":65 chop = class_checks(self.dark_druid_leaders, raid, append_list)66 if chop:67 chop_tail(self.tank_leaders)6869 elif hero.class_ == "Monk":70 chop = class_checks(self.monk_leaders, raid, append_list)71 if chop:72 chop_tail(self.monk_leaders)7374 if len(self.leaders) < 10:75 self.leaders.append(append_list)76 self.leaders.sort(key=lambda x: x[1], reverse=False)77 else:78 for hero in self.leaders:79 if raid.difficulty > hero.difficulty:80 self.leaders.append(append_list)81 self.leaders.sort(key=lambda x: x[1], reverse=False)82 self.leaders.remove(self.leaders[-1])
...
s096011846.py
Source:s096011846.py
1def main():2 #import sys3 #input = sys.stdin.readline4 n,m = map(int,input().split())5 A = list(map(int,input().split()))6 BC = [list(map(int,input().split())) for _ in range(m)]7 BC = sorted(BC,key=lambda x:(x[1]),reverse=True)8 append_list = []9 for b,c in BC:10 if len(append_list)>=n:11 break12 append_list+=[c]*b13 A+=append_list14 A.sort(reverse=True)15 print(sum(A[:n]))16if __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!!