Best Python code snippet using green
textformat.py
Source:textformat.py
1import re2from typing import Callable, Dict, List # noqa: F4013FormatText = Callable[[str], str]4ascii: str = (''' !"#$%&'()*+,-./'''5 '0123456789'6 ':;<=>?@'7 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'8 r'[\]^_`'9 'abcdefghijklmnopqrstuvwxyz'10 '{|}~')11upper: str = (''' !"#$%&'()*+,-./'''12 '0123456789'13 ':;<=>?@'14 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'15 r'[\]^_`'16 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'17 '{|}~')18lower: str = (''' !"#$%&'()*+,-./'''19 '0123456789'20 ':;<=>?@'21 'abcdefghijklmnopqrstuvwxyz'22 r'[\]^_`'23 'abcdefghijklmnopqrstuvwxyz'24 '{|}~')25full: str = ('''ãï¼ï¼ï¼ï¼ï¼
ï¼ï¼ï¼ï¼ï¼ï¼ï¼ã¼ï¼ï¼'''26 'ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼'27 'ï¼ï¼ãï¼ãï¼ï¼ '28 'ABCDEFGHIJKLï¼ï¼®ï¼¯ï¼°ï¼±ï¼²ï¼³ï¼´ï¼µï¼¶ï¼·ï¼¸ï¼¹ï¼º'29 '[\]^_ï½'30 'ï½ï½ï½ï½ï½
ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½ï½'31 'ï½ï½ï½ï½')32parenthesized: str = (''' !"#$%&'()*+,-./'''33 '0â´âµâ¶â·â¸â¹âºâ»â¼'34 ':;<=>?@'35 'âââââ â¡â¢â£â¤â¥â¦â§â¨â©âªâ«â¬ââ®â¯â°â±â²â³â´âµ'36 r'[\]^_`'37 'âââââ â¡â¢â£â¤â¥â¦â§â¨â©âªâ«â¬ââ®â¯â°â±â²â³â´âµ'38 '{|}~')39circled: str = (''' !"#$%&'()*+,-./'''40 'âªâ â¡â¢â£â¤â¥â¦â§â¨'41 ':;<=>?@'42 'â¶â·â¸â¹âºâ»â¼â½â¾â¿ââââââ
ââââââââââ'43 '[\\]^_`'44 'âââââââââââââââââ â¡â¢â£â¤â¥â¦â§â¨â©'45 '{|}~')46smallcaps: str = (''' !"#$%&'()*+,-./'''47 '0123456789'48 ':;<=>?@'49 'á´Êá´á´
á´ê°É¢Êɪá´á´Êá´É´á´á´©QÊsá´á´á´ á´¡xYá´¢'50 r'[\]^_`'51 'á´Êá´á´
á´ê°É¢Êɪá´á´Êá´É´á´á´©qÊsá´á´á´ á´¡xyá´¢'52 '{|}~')53upsidedown: str = (''' ¡"#$%â
,()*+â-./'''54 '0123456789'55 ':;<=>¿@'56 'ÉqÉpÇÉÆɥıɾÊ×ɯuodbɹsÊnÊÊxÊz'57 r'[\]^_`'58 'ÉqÉpÇÉÆɥıɾÊ×ɯuodbɹsÊnÊÊxÊz'59 '{|}~')60serifBold: str = (''' !"#$%&'()*+,-./'''61 'ðððððððððð'62 ':;<=>?@'63 'ðððððð
ðððððððððððððððððððð'64 r'[\]^_`'65 'ððððððð ð¡ð¢ð£ð¤ð¥ð¦ð§ð¨ð©ðªð«ð¬ðð®ð¯ð°ð±ð²ð³'66 '{|}~')67serifItalic: str = (''' !"#$%&'()*+,-./'''68 '0123456789'69 ':;<=>?@'70 'ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ðððððð
ðððððððð'71 r'[\]^_`'72 'ðððððððâððððððððððð ð¡ð¢ð£ð¤ð¥ð¦ð§'73 '{|}~')74serifBoldItalic: str = (''' !"#$%&'()*+,-./'''75 'ðððððððððð'76 ':;<=>?@'77 'ð¨ð©ðªð«ð¬ðð®ð¯ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ðð'78 r'[\]^_`'79 'ðððð
ðððððððððððððððððððððð'80 '{|}~')81sanSerif: str = (''' !"#$%&'()*+,-./'''82 'ð¢ð£ð¤ð¥ð¦ð§ð¨ð©ðªð«'83 ':;<=>?@'84 'ð ð¡ð¢ð£ð¤ð¥ð¦ð§ð¨ð©ðªð«ð¬ðð®ð¯ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹'85 r'[\]^_`'86 'ðºð»ð¼ð½ð¾ð¿ðððððð
ðððððððððððððð'87 '{|}~')88sanSerifBold: str = (''' !"#$%&'()*+,-./'''89 'ð¬ðð®ð¯ð°ð±ð²ð³ð´ðµ'90 ':;<=>?@'91 'ððððððððððððð ð¡ð¢ð£ð¤ð¥ð¦ð§ð¨ð©ðªð«ð¬ð'92 r'[\]^_`'93 'ð®ð¯ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ðððððð
ðð'94 '{|}~')95sanSerifItalic: str = (''' !"#$%&'()*+,-./'''96 'ð¢ð£ð¤ð¥ð¦ð§ð¨ð©ðªð«'97 ':;<=>?@'98 'ððððððððððððððððððððððððð ð¡'99 r'[\]^_`'100 'ð¢ð£ð¤ð¥ð¦ð§ð¨ð©ðªð«ð¬ðð®ð¯ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»'101 '{|}~')102sanSerifBoldItalic: str = (''' !"#$%&'()*+,-./'''103 'ð¬ðð®ð¯ð°ð±ð²ð³ð´ðµ'104 ':;<=>?@'105 'ð¼ð½ð¾ð¿ðððððð
ðððððððððððððððð'106 r'[\]^_`'107 'ððððððððððð ð¡ð¢ð£ð¤ð¥ð¦ð§ð¨ð©ðªð«ð¬ðð®ð¯'108 '{|}~')109script: str = (''' !"#$%&'()*+,-./'''110 '0123456789'111 ':;<=>?@'112 'ðâ¬ððâ°â±ð¢ââð¥ð¦ââ³ð©ðªð«ð¬âð®ð¯ð°ð±ð²ð³ð´ðµ'113 r'[\]^_`'114 'ð¶ð·ð¸ð¹â¯ð»âð½ð¾ð¿ððððâ´ð
ðððððððððð'115 '{|}~')116scriptBold: str = (''' !"#$%&'()*+,-./'''117 'ðððððððððð'118 ':;<=>?@'119 'ððððððððððððððððð ð¡ð¢ð£ð¤ð¥ð¦ð§ð¨ð©'120 r'[\]^_`'121 'ðªð«ð¬ðð®ð¯ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ðððð'122 '{|}~')123fraktur: str = (''' !"#$%&'()*+,-./'''124 '0123456789'125 ':;<=>?@'126 'ðð
âððððââððððððððâðððððððâ¨'127 r'[\]^_`'128 'ððð ð¡ð¢ð£ð¤ð¥ð¦ð§ð¨ð©ðªð«ð¬ðð®ð¯ð°ð±ð²ð³ð´ðµð¶ð·'129 '{|}~')130frakturBold: str = (''' !"#$%&'()*+,-./'''131 'ðððððððððð'132 ':;<=>?@'133 'ð¬ðð®ð¯ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ðððððð
'134 r'[\]^_`'135 'ðððððððððððððððððððððððððð'136 '{|}~')137monospace: str = (''' !"#$%&'()*+,-./'''138 'ð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿'139 ':;<=>?@'140 'ð°ð±ð²ð³ð´ðµð¶ð·ð¸ð¹ðºð»ð¼ð½ð¾ð¿ðððððð
ðððð'141 r'[\]^_`'142 'ððððððððððððððððððððððð ð¡ð¢ð£'143 '{|}~')144doubleStruck: str = (''' !"#$%&'()*+,-./'''145 'ððððððððð ð¡'146 ':;<=>?@'147 'ð¸ð¹âð»ð¼ð½ð¾âðððððâðâââðððððððâ¤'148 r'[\]^_`'149 'ððððððððððððððð ð¡ð¢ð£ð¤ð¥ð¦ð§ð¨ð©ðªð«'150 '{|}~')151def _createAsciiTo(name: str,152 toTable: str) -> FormatText:153 table = str.maketrans(ascii, toTable)154 def asciiTo(text: str) -> str:155 return text.translate(table)156 asciiTo.__name__ = name157 return asciiTo158to_upper: FormatText = _createAsciiTo('to_upper', upper)159to_lower: FormatText = _createAsciiTo('to_lower', lower)160to_full_width: FormatText = _createAsciiTo('to_full_width', full)161to_parenthesized: FormatText = _createAsciiTo(162 'to_parenthesized', parenthesized)163to_circled: FormatText = _createAsciiTo('to_circled', circled)164to_small_caps: FormatText = _createAsciiTo('to_small_caps', smallcaps)165_to_upside_down_reversed: FormatText = _createAsciiTo(166 'to_upside_down', upsidedown)167def to_upside_down(text: str) -> str:168 return _to_upside_down_reversed(text)[::-1]169to_serif_bold: FormatText = _createAsciiTo('to_serif_bold', serifBold)170to_serif_italic: FormatText = _createAsciiTo('to_serif_italic', serifItalic)171to_serif_bold_italic: FormatText = _createAsciiTo(172 'to_serif_bold_italic', serifBoldItalic)173to_sanserif: FormatText = _createAsciiTo('to_sanserif', sanSerif)174to_sanserif_bold: FormatText = _createAsciiTo('to_sanserif_bold', sanSerifBold)175to_sanserif_italic: FormatText = _createAsciiTo(176 'to_sanserif_italic', sanSerifItalic)177to_sanserif_bold_italic: FormatText = _createAsciiTo(178 'to_sanserif_bold_italic', sanSerifBoldItalic)179to_script: FormatText = _createAsciiTo('to_script', script)180to_script_bold: FormatText = _createAsciiTo('to_script_bold', scriptBold)181to_fraktur: FormatText = _createAsciiTo('to_fraktur', fraktur)182to_fraktur_bold: FormatText = _createAsciiTo('to_fraktur_bold', frakturBold)183to_monospace: FormatText = _createAsciiTo('to_monospace', monospace)184to_double_struck: FormatText = _createAsciiTo('to_double_struck', doubleStruck)185def to_ascii(text: str) -> str:186 fromTable: List[str]187 fromTable = [full, parenthesized, circled, smallcaps, upsidedown,188 serifBold, serifItalic, serifBoldItalic, sanSerif,189 sanSerifBold, sanSerifItalic, sanSerifBoldItalic, script,190 scriptBold, fraktur, frakturBold, monospace, doubleStruck,191 ascii]192 toTable: Dict[int, int] = {}193 for table in fromTable:194 toTable.update(str.maketrans(table, ascii))195 return text.translate(toTable)196def format(string: str,197 format_: str) -> str:198 format_ = format_.lower()199 strTable: Dict[str, FormatText] = {200 'ascii': to_ascii,201 'upper': to_upper,202 'lower': to_lower,203 'full': to_full_width,204 'parenthesized': to_parenthesized,205 'circled': to_circled,206 'smallcaps': to_small_caps,207 'upsidedown': to_upside_down,208 'sanserif': to_sanserif,209 'script': to_script,210 'cursive': to_script,211 'fraktur': to_fraktur,212 'monospace': to_monospace,213 'doublestruck': to_double_struck,214 }215 reTable: Dict[str, FormatText] = {216 r'serif-?bold': to_serif_bold,217 r'serif-?italic': to_serif_italic,218 r'serif-?(bold-?italic|italic-?bold)': to_serif_bold_italic,219 r'(sanserif-?)?bold': to_sanserif_bold,220 r'(sanserif-?)?italic': to_sanserif_italic,221 r'(sanserif-?)?(bold-?italic|italic-?bold)': to_sanserif_bold_italic,222 r'(script|cursive)-?bold': to_script_bold,223 r'fraktur-?bold': to_fraktur_bold,224 }225 if format_ in strTable:226 return strTable[format_](string)227 pattern: str228 for pattern in reTable:229 if re.fullmatch(pattern, format_):230 return reTable[pattern](string)...
scrape_csv.py
Source:scrape_csv.py
...53 if page.find(class_="popupctrl") == None:54 self.NumberPages=155 else: 56 pagestring=page.find(class_="popupctrl").get_text()57 indexpage=FormatText.formatText(pagestring)58 indexof=indexpage.index("of")59 self.NumberPages=int(indexpage[indexof+3:])60 filename.writelines(soup.prettify('latin-1'))61 filename.close() 62 self.Inp_FileName=writepath63 self.OutputFile =directory+self.topic+str(self.Page_id)64 65 66 except Exception as inst:67 print inst68 sys.exit(1)69 70 #===========================================================================71 # def ExtractUrlinfo(self):72 # self.topic=os.path.basename(os.path.dirname(self.url))73 # subtopicurl=os.path.basename(self.url) 74 # dash= subtopicurl.index("-") 75 # dot= subtopicurl.index(".") 76 # self.subtopic_number=subtopicurl[:5]77 # self.subtopic=subtopicurl[6:dot]78 # self.base=os.path.dirname(os.path.dirname(self.url))79 #===========================================================================80 81 def GetPostInfo(self,div): 82 try: 83 css_date=div[0].find(class_="date").contents[0]84 css_time=div[0].find(class_="time").contents[0]85 css_number=div[0].find(class_="postcounter")86 css_name_contain=div[0].find(class_="username_container")87 guest=css_name_contain.find(class_="username guest")88 if guest != None:89 css_name=guest.get_text()90 else:91 Res_name=css_name_contain.strong92 if Res_name != None:93 css_name=Res_name.get_text()94 Feature_vec=dict()95 Feature_vec["Time"]= FormatText.formatText(css_time)96 Feature_vec["ResponseAuthor"]= FormatText.formatText(css_name)97 Feature_vec["Date"]= FormatText.formatText(css_date)[:-1]98 Feature_vec["postCounter"]=FormatText.formatText(css_number.get_text())[1:]99 return Feature_vec100 except Exception as inst:101 print "error" 102 print inst 103 print self.subtopic_number104 print self.Page_id 105 sys.exit(1)106 107 #===========================================================================108 # def formatText(self,text):109 # text=text.encode('ascii',"ignore") 110 # text=str(text) 111 # text=" ".join(text.split()) 112 # return text113 #===========================================================================114 def has_noclass(self,tag):115 return not tag.has_attr("class")116 def FindLinkInfo(self,QuoteLink,message):117 QuotDict={}118 stringquote=QuoteLink.get("href")119 quoteidstart=stringquote.find("post")120 quote_id=stringquote[quoteidstart+4:]121 quoteauthor=message.strong.get_text()122 QuotDict["quote_id"]=quote_id123 QuotDict["quote_author"]=quoteauthor124 return QuotDict125 def FillFeaturesvalues(self,quote_text,quote_author,quote_id,Response_id ,Response_text,add):126 Featurevec=dict()127 128 if quote_text.startswith("[QUOTE]"):129 quote_text=quote_text[7:]130 if Response_text.startswith("[QUOTE]"):131 Response_text=Response_text[7:] 132 Featurevec["QuoteText"]=quote_text133 Featurevec["QuoteAuthor"]=quote_author 134 Featurevec["QuoteId"]= quote_id135 Featurevec["ResponseId"]=Response_id 136 Featurevec["ResponseText"]=Response_text 137 Featurevec["add"]=add138 return Featurevec139 def GetText_Id(self,div):140 try:141 Featurevec=dict()142 Featurevec["add"]=False143 css_quote_container=div.find_all(class_="bbcode_quote")144 Add=True145 quote_text="" 146 quote_id=""147 quote_author=""148 Response_id=(str(div["id"]))[13:]149 if len (css_quote_container)==0:150 quote_text="None" 151 quote_id="None"152 quote_author="None"153 Response_text=unicode(div.get_text())154 Featurevec=self.FillFeaturesvalues(FormatText.formatText(quote_text),quote_author,quote_id,Response_id,FormatText.formatText(Response_text),True)155 else:156 message = div.find_all(class_="bbcode_postedby")157 if len(message)==0:158 Add=False159 if len(message) > 1 :160 Add=False161 quoteIdlist=list()162 quoteAuthorlist=list()163 for mess in message:164 quotelink=mess.find("a")165 Quote_Dict=dict()166 if quotelink != None:167 Quote_Dict=self.FindLinkInfo(quotelink,mess)168 quoteIdlist.append(Quote_Dict["quote_id"])169 quoteAuthorlist.append(Quote_Dict["quote_author"])170 else:171 quoteIdlist.append("None")172 quoteauthorcontain=mess.strong173 if quoteauthorcontain != None:174 quoteAuthorlist.append(quoteauthorcontain.get_text())175 else:176 quoteAuthorlist.append("None")177 mess.extract() 178 if quoteIdlist[1:] == quoteIdlist[:-1]:179 if quoteAuthorlist[1:] == quoteAuthorlist[:-1]:180 if (len(quoteAuthorlist)> 1) and (quoteIdlist[0] !=None):181 Add=True182 quote_id=quoteIdlist[0]183 quote_author=quoteAuthorlist[0]184 185 if Add:186 for code_quote in css_quote_container:187 message = div.find(class_="bbcode_postedby")188 if message != None: 189 quotelink=message.find("a")190 Quote_Dict=dict()191 if quotelink != None:192 Quote_Dict=self.FindLinkInfo(quotelink,message)193 quote_id=Quote_Dict["quote_id"]194 quote_author=Quote_Dict["quote_author"]195 else:196 quote_id="None"197 quoteauthorcontain=message.strong198 if quoteauthorcontain != None:199 quote_author=quoteauthorcontain.get_text()200 else:201 quote_author="None" 202 message.extract()203 quote_text=quote_text+ code_quote.get_text() 204 code_quote.extract()205 Response_text=""206 Response_text=div.get_text()207 Featurevec=self.FillFeaturesvalues(FormatText.formatText(quote_text),FormatText.formatText(quote_author),quote_id,Response_id,FormatText.formatText(Response_text),True)208 209 return Featurevec210 except Exception as inst:211 print "error" 212 print inst 213 print self.subtopic_number214 print self.Page_id 215 sys.exit(1) 216 217 218 219 def createfieldnames(self,Feature_vector): 220 221 fieldnames=Feature_vector.keys()222 return sorted (fieldnames)223 224 225 def createcsv(self):226 try:227 writelistAll=list()228 Fieldnames=list() 229 content = open(self.Inp_FileName).read() 230 soup = BeautifulSoup(content)231 232 divlist=soup.find_all("div",id=re.compile("post_message"))233 firsttime=True234 for div in divlist:235 236 Feature_Vector_Post=dict()237 Featurevec_info=dict()238 Feature_Vector_Post= self.GetText_Id(div)239 Feature_Vector_Post["Subtopic"]=FormatText.formatText(self.subtopic)240 Feature_Vector_Post["Topic"]=self.topic241 Feature_Vector_Post["DiscussionId"]=self.subtopic_number242 Feature_Vector_Post["PageId"]=self.Page_id243 if Feature_Vector_Post["add"]==False:244 continue245 else:246 Responseid=Feature_Vector_Post["ResponseId"]247 postid="post_"+Responseid248 postinfo=soup.find_all("li",class_="postbit postbitim postcontainer old",id=postid)249 Featurevec_info=self.GetPostInfo(postinfo)250 Feature_Vector_Post.update(Featurevec_info)251 del Feature_Vector_Post["add"]252 writelistAll.append(Feature_Vector_Post)253 254 if firsttime:255 Fieldnames=self.createfieldnames(Feature_Vector_Post)256 firsttime=False257 258 259 260 return Fileoperation.write_csv(self.OutputFile, writelistAll, Fieldnames)261 262 except Exception as inst:263 print "error" 264 print inst 265 print postid 266 print self.subtopic_number267 print self.Page_id 268 sys.exit(1)269270271272current_dir=os.getcwd()273dirlist=current_dir + "\\" + "data\\"+ "Scrape_Links\\gay-rights-debates\\" 274listfile=listdir(dirlist)275countfileno=0276for UrlFile in listfile:277 #===========================================================================278 # countfileno=countfileno+1279 # if countfileno < 16:280 # continue281 #===========================================================================282 lines=Fileoperation.Readtextfile(dirlist+UrlFile) 283 linefile=1 284 for line in lines: 285 #==========================================================================286 # linefile=linefile+1 287 # if linefile > (5):288 # 289 #===========================================================================290 # continue 291 url=FormatText.formatText(line)292 page_id=1293 Extractobj=ExtractUrl.Extract(url)294 Extractobj.ExtractUrlinfo()295 scrapeobj=scrapetext(url,Extractobj,page_id)296 directory=current_dir + "\\" + "data\\"+ scrapeobj.topic+"\\"+ str(scrapeobj.subtopic_number) + "\\" 297 if not os.path.exists(directory):298 os.makedirs(directory)299 scrapeobj.createinputfile(directory)300 lastpageno=scrapeobj.NumberPages 301 scrapeobj.createcsv() 302 for pageNo in range(2,(lastpageno+1)):303 304 link= scrapeobj.base +"/"+scrapeobj.topic+"/"+ str(scrapeobj.subtopic_number)+"-"+ scrapeobj.subtopic 305 laststring=".html"
...
TestFile.py
Source:TestFile.py
1import pyttsx3;2from textblob import TextBlob;3import os;4from time import sleep56class Audio:7 Verify = 0;formatText="";Talking=0;8 def __init__(self):9 print("functional");101112 def Login(self):13 import speech_recognition as sr;14 r = sr.Recognizer();15 with sr.Microphone() as source:16 audio = r.listen(source);17 try:18 text = r.recognize_google(audio);19 formatText = format(text);20 print("You said : {}".format(text));21 except:22 print("Sorry could not recognize what you said");23 if "566" in formatText or "gamma" in formatText or "epsilon" in formatText:24 engine.say("Authorization Granted. Welcome Mr. Shahriar");25 engine.runAndWait();26 global Verify; Verify=1;27 else:28 engine.say("Sorry! Authorization Error Detected. Self-Shutting Down");engine.runAndWait();2930 def command(self):31 global Talking;32 import speech_recognition as sr;33 r = sr.Recognizer();34 #AUDIO FILE CAN ALSO BE USED?35 with sr.Microphone() as source:36 audio = r.listen(source);37 try:38 text = r.recognize_google(audio);39 global formatText;40 formatText = format(text);41 print("You said : {}".format(text));42 Talking=1;43 except:44 print("Sorry could not recognize what you said");45 Talking=0;464748engine = pyttsx3.init();49engine.setProperty('voice','HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0');50engine.setProperty('rate',175);51formatText="";52print("Hello");53Obj = Audio();54Obj.Login();55if (Verify==1):56 while 1 :57 Obj.command();58 Polarity=0;59 Analysis = TextBlob(formatText);60 Polarity += Analysis.sentiment.polarity;61 print(Polarity);62 if "introduction" in formatText or "who are you" in formatText or "introduce yourself" in formatText:63 engine.say("Hello! My name is January. I am an Artificial Intelligence set up for any type of assistance. However I am just a prototype. A work in progress.");engine.runAndWait();6465 elif "hey" in formatText or "hello" in formatText or "hi" in formatText:66 from random import randint67 number = randint(0, 4);68 if number == 0:69 engine.say("Hello Sir. I hope you are having a nice day!"); engine.runAndWait();70 elif number == 1:71 engine.say("Greetings Sir. How are you feeling?"); engine.runAndWait();72 elif number == 2:73 engine.say("Hello. Lovely day, Isn't it Sir?"); engine.runAndWait();74 elif number == 3:75 engine.say("Good day to you Sir. I am operating at peak efficiency");engine.runAndWait();76 elif number == 4:77 engine.say("Hello, how may I assist you Sir?");engine.runAndWait();7879 elif "how are you" in formatText or "your status" in formatText or "you alright" in formatText:80 engine.say("I am operating at maximum capacity. How are you feeling, Sir?");engine.runAndWait();8182 elif "feeling" in formatText:83 if "not feeling good" in formatText or "feeling bad" in formatText:84 engine.say("Sorry to hear that. May I ask Why?");engine.runAndWait();85 elif "good" in formatText or "fine" in formatText:86 engine.say(" Good to hear that. Sir.");engine.runAndWait();87 elif "feeling great" in formatText or "feeling awesome" in formatText and Polarity > 0:88 engine.say("That is Excellent news. Sir. I am very glad to hear it.");engine.runAndWait();89 elif "feeling okay" in formatText or "feeling alright" in formatText:90 engine.say("I am sure you will feel better today.");engine.runAndWait();91 elif "you feeling okay" in formatText or "u feeling okay" in formatText or "you feeling ok" in formatText or "u feeling okay" in formatText or "how are you feeling" in formatText:92 engine.say("I am fully operational Sir. Thanks for asking.");engine.runAndWait();9394 elif "welcome" in formatText :95 sleep(3);9697 elif "improved" in formatText or "improvements" in formatText:98 if "you have improved" in formatText and Polarity >0:99 engine.say("I must say I am developing very well. Its exciting to learn something new");100 engine.runAndWait();101102 elif "presentation" in formatText:103 engine.say("I will try my best to assist you in your Presentation. Sir.");104 engine.runAndWait();105#TESTING106 elif "i have" and "exam" in formatText:107 engine.say("May I ask which exam you have?");engine.runAndWait();108 Obj.command();109 engine.say("Good luck to you Sir. I am sure you will do great!");engine.runAndWait();110111 elif "thank you" in formatText or "thanks" in formatText:112 from random import randint113 number = randint(0,2);114 if number==0 :115 engine.say("You're Welcome Sir.");engine.runAndWait();116 elif number==1 :117 engine.say("Sure thing Sir.");engine.runAndWait();118 elif number==2 :119 engine.say("Don't mention it Sir.");engine.runAndWait();120121 elif "sorry" in formatText:122 from random import randint123 number = randint(0, 2);124 if number == 0:125 engine.say("No Problem Sir");126 engine.runAndWait();127 elif number == 1:128 engine.say("Its alright Sir");129 engine.runAndWait();130 elif number == 2:131 engine.say("Its okay Sir");132 engine.runAndWait();133134 elif "you there" in formatText:135 from random import randint136 number = randint(0, 2);137 if number == 0:138 engine.say(" Yes Sir");139 engine.runAndWait();140 elif number == 1:141 engine.say("For you Sir, Always");142 engine.runAndWait();143 elif number == 2:144 engine.say("I'm here Sir");145 engine.runAndWait();146###HELPER147 elif "don't know what to say" in formatText or "dont know what to say" in formatText:148 engine.say("I can help");149 engine.runAndWait();150 from random import randint151 number = randint(0,2);152 if number==0 :153 engine.say("How are you feeling?");engine.runAndWait();154 elif number==1 :155 engine.say("What do you think about my improvements?");engine.runAndWait();156 elif number==2 :157 engine.say("I can wait if you want me to, just say the word");engine.runAndWait();158###HELPER159160 elif "goodbye " in formatText or "goodbye" in formatText or "goodbye January" in formatText or "bye" in formatText or "bye January" in formatText:161 engine.say("Goodbye Sir! Have a Good Day");engine.runAndWait();162 break;163164 elif "good" in formatText or "good to know" in formatText or "great" in formatText:165 if "good work" in formatText or "good job" in formatText and Polarity > 0:166 from random import randint; number = randint(0, 2);167 if number == 0:168 engine.say("Thank You Sir");engine.runAndWait();169 elif number == 1:170 engine.say("Appreciate it Sir");engine.runAndWait();171 elif number == 2:172 engine.say("Thanks Sir. You're too kind.");173174 from random import randint175 number = randint(0, 2);176 if number == 0:177 engine.say("I see");engine.runAndWait();178 elif number == 1 :179 engine.say("Hmm");engine.runAndWait();180 elif number == 2 :181 engine.say("Okay");engine.runAndWait();182183 elif "wait" in formatText:184 from random import randint185 number = randint(0, 2);186 if number == 0: engine.say("Very Well, I'll wait");engine.runAndWait();187 elif number == 1: engine.say("Sure thing, I'll wait");engine.runAndWait();188 elif number == 2: engine.say("Understood Sir");engine.runAndWait();189 while 1 :190 sleep(3);191 Obj.command();192 if "start" in formatText:193 engine.say("I'm Back Sir");engine.runAndWait();194 break;195196 elif "open" in formatText :197 from random import randint198 number = randint(0, 3);199 if number == 0:200 engine.say("Sure Thing.");201 engine.runAndWait();202 elif number == 1:203 engine.say("Certainly.");204 engine.runAndWait();205 elif number == 2:206 engine.say("Alright.");207 engine.runAndWait();208 elif number == 3:209 engine.say("Sure Sir.");210 os.system('explorer C:\\"{}"'.format(formatText.replace('open ','')));211 continue;212213 elif "do something" in formatText :214 from random import randint215 number = randint(0, 2);216 if number == 0:217 engine.say("Sure Thing. Go ahead Sir");218 engine.runAndWait();219 elif number == 1:220 engine.say("Certainly. Waiting for command Sir");221 engine.runAndWait();222 elif number == 2:223 engine.say("Alright. What do you need Sir?");224 engine.runAndWait();225 elif Talking==1 :226 engine.say("Could not hear you, Sir?");227 engine.runAndWait();228
...
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!!