Best Python code snippet using localstack_python
base_judge.py
Source:base_judge.py
...5class BaseJudge(Base):6 def is_video(self, p):7 try:8 # 央广ç½ï¼ä¸å½å¹¿æç½ï¼9 if tools.judge_url_contained('cnr', p._url):10 p.set_website(cnr.CNR())11 result = p.is_video()12 if result:13 return True14 # ä¸å½ç½ç»çµè§å°ï¼CNTVï¼15 elif tools.judge_url_contained('cctv', p._url):16 p.set_website(cctv.CCTV())17 result = p.is_video()18 if result:19 return True20 # å½é
å¨çº¿21 elif tools.judge_url_contained('cri', p._url):22 p.set_website(cri.CRI())23 result = p.is_video()24 if result:25 return True26 # 人æ°ç½27 elif tools.judge_url_contained('people', p._url):28 p.set_website(people.People())29 result = p.is_video()30 if result:31 return True32 # æ°åç½33 elif tools.judge_url_contained('xinhuanet', p._url):34 p.set_website(xinhua.XinHua())35 result = p.is_video()36 if result:37 return True38 # ä¸å½åç½39 elif tools.judge_url_contained('81', p._url):40 p.set_website(military.Military())41 result = p.is_video()42 if result:43 return True44 # å
æç½45 elif tools.judge_url_contained('gmw', p._url):46 p.set_website(gmw.Gmw())47 result = p.is_video()48 if result:49 return True50 # ä¸å½ç»æµç½51 elif tools.judge_url_contained('ce', p._url):52 p.set_website(ce.Ce())53 result = p.is_video()54 if result:55 return True56 # ä¸å½æ¥æ¥ç½57 elif tools.judge_url_contained('chinadaily', p._url):58 pass59 # 人æ°æ¿åç½60 elif tools.judge_url_contained('rmzxb', p._url):61 pass62 # ç¯çç½63 elif tools.judge_url_contained('huanqiu', p._url):64 p.set_website(huanqiu.HuanQiu())65 result = p.is_video()66 if result:67 return True68 # ä¸å½éå¹´ç½69 elif tools.judge_url_contained('youth', p._url):70 p.set_website(youth.Youth())71 result = p.is_video()72 if result:73 return True74 # ä¸éå¨çº¿75 elif tools.judge_url_contained('cyol', p._url):76 p.set_website(cyol.Cyol())77 result = p.is_video()78 if result:79 return True80 # æ³å¶ç½81 elif tools.judge_url_contained('legaldaily', p._url):82 p.set_website(legaldaily.Legaldaily())83 result = p.is_video()84 if result:85 return True86 # ä¸å女æ§ç½(ææªåç°)87 elif tools.judge_url_contained('cnwomen', p._url):88 pass89 # ä¸å½åä¸æ°é»ç½90 elif tools.judge_url_contained('farmer', p._url):91 p.set_website(farmer.Farmer())92 result = p.is_video()93 if result:94 return True95 # ä¸å½ç§æç½96 elif tools.judge_url_contained('stdaily', p._url):97 p.set_website(stdaily.Stdaily())98 result = p.is_video()99 if result:100 return True101 # æµ·å¤ç½102 elif tools.judge_url_contained('haiwainet', p._url):103 p.set_website(haiwainet.HaiWai())104 result = p.is_video()105 if result:106 return True107 # ä¸å·¥ç½(ç½ç«è¿ç§»http://www.workercn.cn/)108 # è§é¢å°109 elif tools.judge_url_contained('workercn', p._url):110 pass111 # å
建ç½112 elif tools.judge_url_contained('dangjian', p._url):113 p.set_website(dangjian.DangJian())114 result = p.is_video()115 if result:116 return True117 # ä¸å½ç½118 elif tools.judge_url_contained('china', p._url):119 p.set_website(china.China())120 result = p.is_video()121 if result:122 return True123 # ä¸æ°ç½ï¼ä¸å½æ°é»ç½ï¼124 elif tools.judge_url_contained('chinanews', p._url):125 p.set_website(chinanews.ChinaNews())126 result = p.is_video()127 if result:128 return True129 # èå
ç½(è§é¢ææªåç°)130 elif tools.judge_url_contained('huxiu', p._url):131 pass132 # æªæ¥ç½133 elif tools.judge_url_contained('k618', p._url):134 p.set_website(weilai.WeiLai())135 result = p.is_video()136 if result:137 return True138 # å京æ¶é´(æ°é»æ°æ®åè§é¢é½ä¸å¨æºç ä¸)139 elif tools.judge_url_contained('brtn', p._url):140 pass141 # 驱å¨ä¸å½142 elif tools.judge_url_contained('qudong', p._url):143 p.set_website(qudong.QuDong())144 result = p.is_video()145 if result:146 return True147 # ä¸æµ·ç½148 elif tools.judge_url_contained('dhtv', p._url):149 p.set_website(dhtv.Dhtv())150 result = p.is_video()151 if result:152 return True153 # æ¯ç¹ç½(ææªæ¾å°è§é¢)154 elif tools.judge_url_contained('chinabyte', p._url):155 pass156 # æ¯ç»ç½(ææªæ¾å°è§é¢)157 elif tools.judge_url_contained('nbd', p._url):158 pass159 # ä¸å½ææç½160 elif tools.judge_url_contained('wenming', p._url):161 p.set_website(wenming.WenMing())162 result = p.is_video()163 if result:164 return True165 # å¤å°ç½166 elif tools.judge_url_contained('ifeng', p._url):167 p.set_website(fenghuang.Ifeng())168 result = p.is_video()169 if result:170 return True171 # æ°æµª172 elif tools.judge_url_contained('sina', p._url):173 p.set_website(sina.Sina())174 result = p.is_video()175 if result:176 return True177 # æç178 elif tools.judge_url_contained('sohu', p._url):179 p.set_website(souhu.SouHu())180 result = p.is_video()181 if result:182 return True183 # ç½æç½184 elif tools.judge_url_contained('163', p._url):185 p.set_website(wangyi.WangYi())186 result = p.is_video()187 if result:188 return True189 # ç¾åº¦æ°é»190 elif tools.judge_url_contained('baidu', p._url):191 pass192 # ç«æ193 elif tools.judge_url_contained('mop', p._url):194 pass195 # æ¾æ¹ç½196 elif tools.judge_url_contained('thepaper', p._url):197 p.set_website(thepaper.Thepaper())198 result = p.is_video()199 if result:200 return True201 # è
¾è®¯ç½202 elif tools.judge_url_contained('qq', p._url):203 p.set_website(qq.QQ())204 result = p.is_video()205 if result:206 return True207 # ä¸å½æ°é»åºç广çµç½208 elif tools.judge_url_contained("chinaxwcb", p._url):209 pass210 # å½å®¶å¹¿æçµè§æ»å±211 elif tools.judge_url_contained("nrta", p._url):212 pass213 # ä¸æ¹ç½214 elif tools.judge_url_contained("eastday", p._url):215 p.set_website(eastday.EastDay())216 result = p.is_video()217 if result:218 return True219 elif tools.judge_url_contained("cm3721", p._url):220 pass221 # ä¸è§ç½222 elif tools.judge_url_contained("shobserver", p._url):223 pass224 # æ°äº¬æ¥ç½225 elif tools.judge_url_contained("bjnews", p._url):226 p.set_website(bjnews.BjNews())227 result = p.is_video()228 if result:229 return True230 else:231 return False232 except Exception:...
judge_website_name.py
Source:judge_website_name.py
1import re2from urllib import parse3def judge_url_contained(keyword,url):4 '''5 :param keyword: åå6 :param url: ç½ç«å°å7 :return: å¤æè¿ä¸ªååæ¯å¦é¶å±äºè¿ä¸ªç½ç«8 '''9 result = parse.urlparse(url)[1]10 try:11 domain=re.search(r"\.(.*)\.",result).group(1)12 except Exception as e:13 end=result.rfind(".")14 domain=result[:end]15 if "." in domain:16 str_list=domain.split(".")17 for domain in str_list:18 if keyword in domain:19 if len(keyword)==len(domain):20 return True21 else:22 return False23 else:24 continue25 else:26 if keyword in domain:27 if len(keyword)==len(domain):28 return True29 else:30 return False31 else:32 return False33def get_website_name(root_url):34 try:35 #央广ç½ï¼ä¸å½å¹¿æç½ï¼36 if judge_url_contained('cnr',root_url):37 return '央广ç½'38 #ä¸å½ç½ç»çµè§å°ï¼CNTVï¼39 elif judge_url_contained('cctv',root_url):40 return 'ä¸å½ç½ç»çµè§å°'41 #å½é
å¨çº¿42 elif judge_url_contained('cri',root_url):43 return 'å½é
å¨çº¿'44 #人æ°ç½45 elif judge_url_contained('people',root_url):46 return '人æ°ç½'47 #æ°åç½48 elif judge_url_contained('xinhuanet',root_url):49 return 'æ°åç½'50 #æ±æ¯ç½51 elif judge_url_contained('qstheory',root_url):52 return 'æ±æ¯ç½'53 #ä¸å½åç½54 elif judge_url_contained('81',root_url):55 return 'ä¸å½åç½'56 #å
æç½57 elif judge_url_contained('gmw',root_url):58 return 'å
æç½'59 #ä¸å½ç»æµç½60 elif judge_url_contained('ce',root_url):61 return 'ä¸å½ç»æµç½'62 #ä¸å½æ¥æ¥ç½63 elif judge_url_contained('chinadaily',root_url):64 return 'ä¸å½æ¥æ¥ç½'65 #人æ°æ¿åç½66 elif judge_url_contained('rmzxb',root_url):67 return '人æ°æ¿åç½'68 #ç¯çç½69 elif judge_url_contained('huanqiu',root_url):70 return 'ç¯çç½'71 #ä¸å½éå¹´ç½ï¼ææªåç°ç¸å
³è§é¢æ¿åï¼72 elif judge_url_contained('youth',root_url):73 return 'ä¸å½éå¹´ç½'74 #ä¸éå¨çº¿75 elif judge_url_contained('cyol',root_url):76 return 'ä¸éå¨çº¿'77 #æ³å¶ç½78 elif judge_url_contained('legaldaily',root_url):79 return 'æ³å¶ç½'80 #ä¸å女æ§ç½(ææªåç°)81 elif judge_url_contained('cnwomen',root_url):82 return 'ä¸å女æ§ç½'83 #ä¸å½åä¸æ°é»ç½84 elif judge_url_contained('farmer',root_url):85 return 'ä¸å½åä¸æ°é»ç½'86 #ä¸å½ç§æç½87 elif judge_url_contained('stdaily',root_url):88 return 'ä¸å½ç§æç½'89 #æµ·å¤ç½90 elif judge_url_contained('haiwainet',root_url):91 return 'æµ·å¤ç½'92 #ä¸å·¥ç½(ç½ç«è¿ç§»http://www.workercn.cn/)93 #è§é¢å°94 elif judge_url_contained('workercn',root_url):95 return 'ä¸å·¥ç½'96 #å
建ç½97 elif judge_url_contained('dangjian',root_url):98 return 'å
建ç½'99 #ä¸åç½100 elif judge_url_contained('china',root_url):101 return 'ä¸åç½'102 #ä¸æ°ç½ï¼ä¸å½æ°é»ç½ï¼103 elif judge_url_contained('chinanews',root_url):104 return 'ä¸å½æ°é»ç½'105 #èå
ç½(è§é¢ææªåç°)106 elif judge_url_contained('huxiu',root_url):107 return 'èå
ç½'108 # #Techwebï¼å¤é¾ä¼é
·è§é¢ï¼109 elif judge_url_contained('techweb',root_url):110 return 'Techweb'111 #ä¸å
¬æè²(pass)112 elif judge_url_contained('offcn',root_url):113 return 'ä¸å
¬æè²'114 #æªæ¥ç½115 elif judge_url_contained('k618',root_url):116 return 'æªæ¥ç½'117 #å京æ¶é´(æ°é»æ°æ®åè§é¢é½ä¸å¨æºç ä¸)118 elif judge_url_contained('brtn',root_url):119 return 'å京æ¶é´'120 #驱å¨ä¸å½121 elif judge_url_contained('qudong',root_url):122 return '驱å¨ä¸å½'123 #è§å¯è
124 elif judge_url_contained('guancha',root_url):125 return 'è§å¯è
'126 #ä¸æµ·ç½127 elif judge_url_contained('dhtv',root_url):128 return 'ä¸æµ·ç½'129 #æ¯ç¹ç½(ææªæ¾å°è§é¢)130 elif judge_url_contained('chinabyte',root_url):131 return 'æ¯ç¹ç½'132 #æ¯ç»ç½(ææªæ¾å°è§é¢)133 elif judge_url_contained('nbd',root_url):134 return 'æ¯ç»ç½'135 #ä¸å½ææç½136 elif judge_url_contained('wenming',root_url):137 return 'ä¸å½ææç½'138 #å¤å°ç½139 elif judge_url_contained('ifeng',root_url):140 return 'å¤å°ç½'141 #æ°æµª142 elif judge_url_contained('sina',root_url):143 return 'æ°æµªç½'144 #æç145 elif judge_url_contained('sohu',root_url):146 return 'æçç½'147 #ç½æç½148 elif judge_url_contained('163',root_url):149 return 'ç½æç½'150 #ç¾åº¦æ°é»151 elif judge_url_contained('baidu',root_url):152 return 'ç¾åº¦æ°é»'153 #ç«æ154 elif judge_url_contained('mop',root_url):155 return 'ç«æ'156 #æçå客157 elif judge_url_contained('souhu',root_url):158 return 'æçç½'159 #æ¾æ¹ç½160 elif judge_url_contained('thepaper',root_url):161 return 'æ¾æ¹ç½'162 #è
¾è®¯ç½163 elif judge_url_contained('qq',root_url):164 return 'è
¾è®¯ç½'165 #ä¸å½æ°é»åºç广çµç½166 elif judge_url_contained("chinaxwcb",root_url):167 return 'ä¸å½æ°é»åºç广çµç½'168 #å½å®¶å¹¿æçµè§æ»å±169 elif judge_url_contained("nrta",root_url):170 return 'å½å®¶å¹¿æçµè§æ»å±'171 #ä¸æ¹ç½172 elif judge_url_contained("eastday", root_url):173 return 'å½å®¶å¹¿æçµè§æ»å±'174 elif judge_url_contained("cm3721", root_url):175 return ''176 #ä¸è§ç½177 elif judge_url_contained("jfdaily", root_url):178 return 'ä¸è§ç½'179 #æ°äº¬æ¥ç½180 elif judge_url_contained("bjnews", root_url):181 return 'æ°äº¬æ¥ç½'182 #天涯ç½183 elif judge_url_contained('tianya', root_url):184 return '天涯ç½'185 #çµååå¡ç 究ä¸å¿186 elif judge_url_contained('100ec',root_url):187 return 'çµååå¡ç 究ä¸å¿'188 else:189 return ''190 except Exception:191 return ''192if __name__ == '__main__':193 url = 'http://www.100ec.cn/detail--6258283.html%20'194 name = get_website_name(url)...
script.py
Source:script.py
1from random import randint2from Cores import cores3import pandas as pd4for j in range(800):5 df = pd.read_csv("coin_flip_results.csv")6 six = df['Times 6 streak appeared']7 seven = df['Times 7 streak appeared']8 eight = df['Times 8 streak appeared']9 nine = df['Times 9 streak appeared']10 ten = df['Times 10 streak appeared']11 coin_side = ['Heads', 'Tails']12 streak_count = 113 previous_flip = ' '14 def checking_streaks(number_of_streaks, number:int, streak_count,contained_six, count=0):15 if streak_count >= number:16 number_of_streaks += 1 17 count += 118 if count >0:19 contained_six += 120 return number_of_streaks, contained_six21 def applying_color(new_flip):22 if new_flip == 'Heads':23 color = '\033[31m'24 else:25 color = '\033[32m'26 return color27 def percentage_calculator(number_of_streaks,contained, total = df['Total games played']):28 if number_of_streaks > 0:29 contained += 130 percentage = ((contained/total) * 100).round(2)31 return percentage, contained32 # SCRIPT33 contained_six=contained_seven=contained_eight=contained_nine=contained_ten=0 #variable made to verify if a game contained a certain amount of streak34 # 200 coin toss sequence35 for i in range(200):36 new_flip = coin_side[randint(0,1)]37 color = applying_color(new_flip)38 if new_flip == previous_flip:39 streak_count += 140 else:41 streak_count = 142 print(f'{streak_count} {color}{new_flip}', cores('nula'))43 previous_flip = new_flip44 six, contained_six = checking_streaks(six, 6, streak_count, contained_six)45 seven, contained_seven = checking_streaks(seven, 7, streak_count, contained_seven)46 eight, contained_eight = checking_streaks(eight, 8, streak_count, contained_eight)47 nine, contained_nine = checking_streaks(nine, 9, streak_count, contained_nine)48 ten, contained_ten = checking_streaks(ten, 10, streak_count, contained_ten)49 df['Total games played'] += 150 # Calculating percentages and averages51 df['Contained a 6 streak %'], df['Contained a 6 streak'] = percentage_calculator(contained_six, df['Contained a 6 streak'])52 df['Contained a 7 streak %'], df['Contained a 7 streak'] = percentage_calculator(contained_seven, df['Contained a 7 streak'])53 df['Contained a 8 streak %'], df['Contained a 8 streak'] = percentage_calculator(contained_eight, df['Contained a 8 streak'])54 df['Contained a 9 streak %'], df['Contained a 9 streak'] = percentage_calculator(contained_nine, df['Contained a 9 streak'])55 df['Contained a 10 streak %'], df['Contained a 10 streak'] = percentage_calculator(contained_ten, df['Contained a 10 streak'])56 df["6 streak average"] = (df['Times 6 streak appeared'] / df ['Total games played']).round(2)57 df["7 streak average"] = (df['Times 7 streak appeared'] / df ['Total games played']).round(2)58 df["8 streak average"] = (df['Times 8 streak appeared'] / df ['Total games played']).round(2)59 df["9 streak average"] = (df['Times 9 streak appeared'] / df ['Total games played']).round(2)60 df["10 streak average"] = (df['Times 10 streak appeared'] / df ['Total games played']).round(2)61 df = df[["Times 6 streak appeared","Contained a 6 streak", "Contained a 6 streak %",'6 streak average','Times 7 streak appeared','Contained a 7 streak','Contained a 7 streak %','7 streak average','Times 8 streak appeared','Contained a 8 streak','Contained a 8 streak %','8 streak average','Times 9 streak appeared','Contained a 9 streak','Contained a 9 streak %','9 streak average','Times 10 streak appeared','Contained a 10 streak','Contained a 10 streak %','10 streak average','Total games played']]62 df.to_csv("coin_flip_results.csv", index=False)...
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!!