def parrotlet_time(): _time = str(datetime.datetime.now()).split()[1].split('.')[0] reply = f'The Time is {_time}' if config.lang_code != 'en': reply = trans_.translate_sentence_code(reply, config.lang_code) config.lang_code = 'en' return reply
def rihanna_time(): global clock_ _time = str(datetime.datetime.now()).split()[1].split('.')[0] reply = f'The Time is {_time}' if config.lang_code != 'en': reply = trans_.translate_sentence_code(reply, config.lang_code) config.lang_code = 'en' return {'display': clock(), 'say': reply}
def bbc(): # BBC news api main_url = f" https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey={config.news_key}" # fetching data in json format open_bbc_page = requests.get(main_url).json() # getting all articles in a string article article = open_bbc_page["articles"] if config.lang_code == 'en': display = "Top 5 BBC News :" say = "Top 5 BBC News :" nos = 1 for ar in article[:5]: news = ar["title"] url = ar["url"] display += f'<br>{nos}. {news} <a href={url} target="_blank">Read</a></br>' say += f'\n{nos}. {news}' nos += 1 reply_ = {'display': display, 'say': say} else: ans = trans_.translate_sentence_code("Top 5 BBC News", config.lang_code) display = ans['display'] + ':' say = "Top 5 BBC News" nos = 1 for ar in article[:5]: news = trans_.translate_sentence_code(ar["title"], config.lang_code)['display'] url = ar["url"] read = trans_.translate_sentence_code("Read", config.lang_code)['display'] display += f'<br>{nos}. {news} <a href={url} target="_blank">{read}</a></br>' say += f'\n{nos}. {news}' nos += 1 say = trans_.translate_sentence_code(say, config.lang_code)['say'] reply_ = {'display': display, 'say': say} config.lang_code = 'en' return reply_
def show_picture(self): if self.name.lower() in con.friends: p_id = con.friends[self.name.lower()] picture = f'<img src="https://avatar.skype.com/v1/avatars/{p_id}/public">' return picture elif self.name == 'me': path = "C:/Users/Timothy Lam/Documents/Pycharm Projects/Chatbot/img/me.png" # path = r"E:/deadlock files/img/public.png" # return f'<img src="{path}" alt="HTML5 Icon" width="128" height="128">' display = f'<img src="{path}" alt="Test image" width="65%" height="65%">' say = f'find picture of {self.name}' reply = {'display': display, 'say': say} if con.lang_code != 'en': reply['say'] = trans_.translate_sentence_code(reply['say'], con.lang_code) con.lang_code = 'en' return reply else: return f"Sorry I do not know {self.name}"
def product_min_price(query): try: item_dict, item_link = search_amazon(query) if len(item_dict) == 0: item_dict, item_link = search_amazon(query.split()[0]) if len(item_dict) == 0: if config.lang_code == 'en': reply = "I am not in the mood to search for that query" return {'display': reply, 'say': reply} else: reply = trans_.translate_sentence_code( "I am not in the mood to search for that query", config.lang_code) config.lang_code = 'en' return reply min_price = min(item_dict, key=item_dict.get) reply = "<table id='t01'>\ <tr>\ <th>Image</th>\ <th>Product Name</th>\ <th>Price</th>\ <th>Rating</th>\ </tr>\ " reply += f"<tr>\ <td><img src='{item_link[min_price][1]}' alt='{query} image' width='40%' height='40%'></td>\ <td><a href='https://www.amazon.co.uk{item_link[min_price][0]}' target='_blank'>{min_price}</a></td>\ <td>£{item_dict[min_price]}</td>\ <td>{item_link[min_price][2]}</td>\ </tr>" say = f'Find below the item with the least price for {query}' return {'display': reply, 'say': say} except Exception as e: reply = f'Error in product_min_price: {e}' return {'display': reply, 'say': reply}