示例#1
0
 def rem(self):
     print self.what
     count = 0
     time = nt.to_natural_day_and_time(self.when_epoch)
     # ny.show(self.what,time)
     while count != 2:
         tts.speak("Sir,reminding you to {}".format(self.what))
         time.sleep(2)
         count += 1
示例#2
0
 def on_event(self, message):
     self.message = message
     print self.message
     m = re.match(self.regex, self.message["text"], re.DOTALL)
     if m:
         self.what = m.group("reminder_text")
         self.when = m.group("remind_time")
         self.when_epoch = nt.parse_natural_time(self.when)
         print self.when_epoch
         try:
             self.remainder = SCHEDULER.add_job(self.rem, "date", name="test", run_date=self.when_epoch)
             print self.remainder
         except ValueError:
             tts.speak("Could not schedule this remainder")
             print "error"
示例#3
0
 def on_event(self,event,sender):
     print event
     if self.match(event):
         req='http://api.openweathermap.org/data/2.5/weather?lat={0}&lon={1}'.format(coordinates['LAT'],coordinates['LONG'])
         weather=requests.get(req,timeout=5)
         if weather.status_code==200:
             wdata=json.loads(weather.text)
             condition=wdata["weather"][0]["description"]
             temp=wdata["main"]["temp_max"]-273
             location=wdata["name"]
             print '{1} in {0} with temperature of {2} degree celcius'.format(location,condition,int(temp))
             # speech.say('{1} in {0} with temperature of {2} degree celcius'.format(location,condition,int(temp)))
             weather_data["location"]=location
             weather_data["condition"]=condition
             weather_data["temp"]=int(temp)
             speak('{1} in {0} with temperature of {2} degree celcius'.format(location,condition,int(temp)))
         else:
             speak('Could not fetch weather')
             return 'Could not fetch weather'
         return True
示例#4
0
    def online_recognition(self):
        r=self.r
        speak(random.choice(self.randomresp))
        try:
            with sr.Microphone() as source:
                audi1 = r.adjust_for_ambient_noise(source)
                print "----------Listening-------"
                audi1 = r.listen(source)
                print "----------Recognizing-------"
                try:
                    data=r.recognize_google(audi1,key=GOOGLE_API_KEY,language="en-US",show_all=False)
                    voice_queue.put(data.lower())
                    return True
                except IndexError:
                    # the API key didn't work
                    speak("I am sorry sir, could not connect to the internet")
                    print("No internet connection")
                except KeyError:
                    speak("I am afraid,your API key is invalid")
                    print("Invalid API key or quota maxed out")
                except LookupError:
                    print("Could not understand audio")
                except sr.UnknownValueError:
                    pass

        except KeyboardInterrupt:
            sys.exit(0)
示例#5
0
def handle_sleep(*args):
    global suspend_time,awake_time
    if str(args[0])=='1':
        speak("See you soon,sir!")
        suspend_time=time.time()
        dtime=GetTime(awake_time-suspend_time)
        print dtime
        speak("sir!,you were logged in for {}".format(dtime))
    elif str(args[0])=='0':
        awake_time=time.time()
        dtime=GetTime(awake_time-suspend_time)
        print dtime
        speak("sir!, welcome back, you are back after {}".format(dtime))
示例#6
0
    def on_event(self, event, sender):
        m=self.match(event)
        if m:
            if m.group("time"):
                self.when=m.group("time")
                self.when_epoch=nt.parse_natural_time(self.when)
                tts.speak("sir, please enter the full command you wish to execute?")
                self.what=enterbox("command to run at {}".format(self.when_epoch))
                print self.when_epoch
                try:
                    self.remainder=SCHEDULER.add_job(self.runat,'date',run_date=self.when_epoch)

                except ValueError:
                    tts.speak("Could not schedule this run")
            else:
                tts.speak("sir, please enter the full command you wish to execute?")
                self.what=enterbox("command to run")
                comm="gnome-terminal --tab -e {0}".format(self.what)
                self.command(comm)
            return True
示例#7
0
 def runat(self):
     tts.speak("Sir,running your specified command")
     self.command(comm)
示例#8
0
 def answer(self, event, sender):
     reply=self.bot.reply("localuser", event)
     speak(str(reply))
     ny.show(reply)
     return True