def handleResponse(text): def extractOrdinals(text): output = [] service = NumberService() for w in text.split(): if w in service.__ordinals__: output.append(service.__ordinals__[w]) return [service.parse(w) for w in output] chosen_articles = extractOrdinals(text) send_all = not chosen_articles and app_utils.isPositive(text) if send_all or chosen_articles: mic.say("Sure, just give me a moment") if profile['prefers_email']: body = "<ul>" def formatArticle(article): tiny_url = app_utils.generateTinyURL(article.URL) if profile['prefers_email']: return "<li><a href=\'%s\'>%s</a></li>" % (tiny_url, article.title) else: return article.title + " -- " + tiny_url for idx, article in enumerate(stories): if send_all or (idx + 1) in chosen_articles: article_link = formatArticle(article) if profile['prefers_email']: body += article_link else: if not app_utils.emailUser(profile, SUBJECT="", BODY=article_link): mic.say("I'm having trouble sending you these " + "articles. Please make sure that your " + "phone number and carrier are correct " + "on the dashboard.") return # if prefers email, we send once, at the end if profile['prefers_email']: body += "</ul>" if not app_utils.emailUser(profile, SUBJECT="From the Front Page of " + "Hacker News", BODY=body): mic.say("I'm having trouble sending you these articles. " + "Please make sure that your phone number and " + "carrier are correct on the dashboard.") return mic.say("All done.") else: mic.say("OK I will not send any articles")
def handle(text, mic, profile, wxbot=None): """ Reports the current time based on the user's timezone. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) wxbot -- wechat bot instance """ if 'wechat' not in profile or not profile['wechat'] or wxbot is None: mic.say(u'请先在配置文件中开启微信接入功能', cache=True) return if 'email' not in profile or ('enable' in profile['email'] and not profile['email']): mic.say(u'请先配置好邮箱功能', cache=True) return sys.path.append(mic.kairpath.LIB_PATH) from app_utils import emailUser dest_file = os.path.join(mic.kairpath.TEMP_PATH, 'wxqr.png') wxbot.get_uuid() wxbot.gen_qr_code(dest_file) if os.path.exists(dest_file): mic.say(u'正在发送微信登录二维码到您的邮箱', cache=True) if emailUser(profile, u"这是您的微信登录二维码", "", [dest_file]): mic.say(u'发送成功', cache=True) else: mic.say(u'发送失败', cache=True) else: mic.say(u"微信接入失败", cache=True)
def handle(text, mic, profile, wxbot=None): """ Reports the current time based on the user's timezone. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) wxbot -- wechat bot instance """ if 'wechat' not in profile or not profile['wechat'] or wxbot is None: mic.say(u'请先在配置文件中开启微信接入功能', cache=True) return if 'email' not in profile or ('enable' in profile['email'] and not profile['email']): mic.say(u'请先配置好邮箱功能', cache=True) return sys.path.append(mic.dingdangpath.LIB_PATH) from app_utils import emailUser dest_file = os.path.join(mic.dingdangpath.TEMP_PATH, 'wxqr.png') wxbot.get_uuid() wxbot.gen_qr_code(dest_file) if os.path.exists(dest_file): mic.say(u'正在发送微信登录二维码到您的邮箱', cache=True) if emailUser(profile, u"这是您的微信登录二维码", "", [dest_file]): mic.say(u'发送成功', cache=True) else: mic.say(u'发送失败', cache=True) else: mic.say(u"微信接入失败", cache=True)
def handle(text, mic, profile, wxbot=None): """ Reports the current time based on the user's timezone. Arguments: text -- user-input, typically transcribed speech mic -- used to interact with the user (for both input and output) profile -- contains information related to the user (e.g., phone number) wxbot -- wechat bot instance """ if 'wechat' not in profile or not profile['wechat']: mic.say(u'请先在配置文件中开启微信接入功能') return if 'email' not in profile or ('enable' in profile['email'] and not profile['email']): mic.say(u'请先配置好邮箱功能') return sys.path.append(mic.dingdangpath.LIB_PATH) from app_utils import emailUser # dest_file = os.path.join(mic.dingdangpath.TEMP_PATH, 'wxqr.png') app = config.get_uni_obj('app') wxbot = app.start_wxbot() mic.say("正在获取微信二维码") tryTimes = 30 while tryTimes > 0: tryTimes = tryTimes - 1 if wxbot.qr_file == None: time.sleep(0.1) continue with wxbot.qr_lock: if os.path.exists(wxbot.qr_file): t = mic.asyncSay(u'正在发送微信登录二维码到您的邮箱') if emailUser(profile, u"这是您的微信登录二维码", "", [wxbot.qr_file]): t.join() mic.say(u'发送成功') return else: t.join() mic.say(u'发送失败') return time.sleep(0.1) mic.say(u"获取登录二维码失败,请重新尝试")
def handleResponse(text): def extractOrdinals(text): output = [] service = NumberService() # convert to lower case for the ordinal function text = text.lower() for w in text.split(): #print (w + "inside extract Ordinals") if w in service.__ordinals__: print(w + " is a n ordinal") output.append(service.__ordinals__[w]) return [service.parse(w) for w in output] chosen_articles = extractOrdinals(text) send_all = chosen_articles == [] and app_utils.isPositive(text) if send_all or chosen_articles: mic.say("Sure, just give me a moment") if profile['prefers_email']: body = "<ul>" def formatArticle(article): tiny_url = app_utils.generateTinyURL(article.link) if profile['prefers_email']: return "<li><a href=\'%s\'>%s</a></li>" % ( tiny_url, article.description) else: return article.description + " -- " + tiny_url for idx, article in enumerate(healthreports): if send_all or (idx + 1) in chosen_articles: article_link = formatArticle(article) if profile['prefers_email']: body += article_link else: if not app_utils.emailUser( profile, SUBJECT="", BODY=article_link): mic.say( "I'm having trouble sending you these articles. Please make sure that your phone number and carrier are correct on the dashboard." ) return # if prefers email, we send once, at the end if profile['prefers_email']: body += "</ul>" if not app_utils.emailUser( profile, SUBJECT="From the Front Page of Health News", BODY=body): mic.say( "I'm having trouble sending you these articles. Please make sure that your phone number and carrier are correct on the dashboard." ) return mic.say("All done.") else: mic.say("OK I will not send any articles")
def handleResponse(text): def extractOrdinals(text): output = [] if 'pierwszy' in text or 'pierwsza' in text or 'pierwszą' in text: output.append(1) if 'drugi' in text or 'druga' in text or 'drugą' in text: output.append(2) if 'trzeci' in text or 'trzecia' in text or 'trzecią' in text: output.append(3) if 'czwarty' in text or 'czwarta' in text or 'czwartą' in text: output.append(4) if 'piąty' in text or 'piąta' in text or 'piątą' in text: output.append(5) return output #output = [] #service = NumberService() #if text: # for w in text.split(): # if w in service.__ordinals__: # output.append(service.__ordinals__[w]) #return [service.parse(w) for w in output] chosen_articles = extractOrdinals(text) send_all = not chosen_articles and app_utils.isPositive(text) if send_all or chosen_articles: mic.say("Już się robi, proszę o jedną chwilę") if profile['prefers_email']: body = "<ul>" def formatArticle(article): tiny_url = app_utils.generateTinyURL(article.URL) if profile['prefers_email']: return "<li><a href=\'%s\'>%s</a></li>" % (tiny_url, article.title) else: return article.title + " -- " + tiny_url for idx, article in enumerate(articles): if send_all or (idx + 1) in chosen_articles: article_link = formatArticle(article) if profile['prefers_email']: body += article_link else: if not app_utils.emailUser(profile, logger, SUBJECT="", BODY=article_link): mic.say( "Wybacz, ale mam problem z wysłaniem wiadomości.| Sprawdź proszę podany numer telefonu i operatora.") return # if prefers email, we send once, at the end if profile['prefers_email']: body += "</ul>" if not app_utils.emailUser(profile, logger, SUBJECT="Twoje wiadomości", BODY=body): mic.say( "Wybacz, ale mam problem z wysłaniem wiadomości.| Sprawdź proszę podany numer telefonu i operatora.") return mic.say("Gotowe") else: mic.say("W porządku, nie wysyłam wiadomości")
def handleResponse(text): def extractOrdinals(text): output = [] if 'pierwszy' in text or 'pierwsza' in text or 'pierwszą' in text: output.append(1) if 'drugi' in text or 'druga' in text or 'drugą' in text: output.append(2) if 'trzeci' in text or 'trzecia' in text or 'trzecią' in text: output.append(3) if 'czwarty' in text or 'czwarta' in text or 'czwartą' in text: output.append(4) if 'piąty' in text or 'piąta' in text or 'piątą' in text: output.append(5) return output #output = [] #service = NumberService() #if text: # for w in text.split(): # if w in service.__ordinals__: # output.append(service.__ordinals__[w]) #return [service.parse(w) for w in output] chosen_articles = extractOrdinals(text) send_all = not chosen_articles and app_utils.isPositive(text) if send_all or chosen_articles: mic.say("Już się robi, proszę o jedną chwilę") if profile['prefers_email']: body = "<ul>" def formatArticle(article): tiny_url = app_utils.generateTinyURL(article.URL) if profile['prefers_email']: return "<li><a href=\'%s\'>%s</a></li>" % (tiny_url, article.title) else: return article.title + " -- " + tiny_url for idx, article in enumerate(articles): if send_all or (idx + 1) in chosen_articles: article_link = formatArticle(article) if profile['prefers_email']: body += article_link else: if not app_utils.emailUser( profile, logger, SUBJECT="", BODY=article_link): mic.say( "Wybacz, ale mam problem z wysłaniem wiadomości.| Sprawdź proszę podany numer telefonu i operatora." ) return # if prefers email, we send once, at the end if profile['prefers_email']: body += "</ul>" if not app_utils.emailUser( profile, logger, SUBJECT="Twoje wiadomości", BODY=body): mic.say( "Wybacz, ale mam problem z wysłaniem wiadomości.| Sprawdź proszę podany numer telefonu i operatora." ) return mic.say("Gotowe") else: mic.say("W porządku, nie wysyłam wiadomości")
def get_mail(old_profile=None, first_name="", last_name=""): if not old_profile: old_profile = { 'address': '', 'user': '', 'server': '', 'password': '', 'recipient': '' } print "IRIS uses your Gmail to send notifications" success = False mp = {} mp['address'] = user_input("Email address", default=old_profile['address']) default_user = mp['address'] if re.findall("(g(oogle)?mail)", mp['address']): user, host = tuple(mp['address'].split('@')) sug = user + "+IRIS@" + host print """You have a gmail account. I can change your address to %s. This won't stop you from receiving emails but allow you to filter for my notifications easily!""" % sug if yn_input(query="Do you want me to do that", default=False): mp['address'] = sug while not success: mp['user'] = user_input( "SMTP User", default=old_profile['user'] or default_user ) pw = user_input(password=True) mp['server'] = user_input( "SMTP Server", default=old_profile['server'] or "smtp.gmail.com" ) if mp['user']: print("\nI will now connect to SMTP...") try: session = app_utils.smtp_login(mp['server'], mp['user'], pw) session.quit() success = True except app_utils.SMTPAuthenticationError: print("\nYour credentials are wrong. Please check them") else: print("\nYou will not be able to use SMTP") success = True return {} mp['password'] = base64.b64encode(pw) if first_name and last_name: mp['recipient'] = "%s %s <%s>" % (first_name, last_name, mp['address']) else: mp['recipient'] = mp['address'] if yn_input("Do you want me to send a test mail", default=False): app_utils.emailUser( {'mail': mp}, subject="IRIS TEST MAIL", body="Test" ) return mp