def aClock():
    currentTime = time.strftime('%Y-%m-%d,%H:%M', time.localtime(time.time()))
    weatherInfo = WeatherHelper.getCityWeather_RealTime(
        ConfigHelper.GetIni("city"))

    SpeakHelper.Speak("zh-CN", ConfigHelper.GetWord("nowt"))  #现在时间是
    SpeakHelper.SpeakOneTime("zh-CN", currentTime + "," + weatherInfo)
Beispiel #2
0
def soundStart(talk, cnt = 3):
    dt = list(time.localtime())
    hour = dt[3]
            
    Speak("zh-CN", talk)
    
    count = 0

    if hour < int(ConfigHelper.GetIni("quiettime","6")):
        Speak("zh-CN",ConfigHelper.GetWord("toolate"))#太晚了
        return

    IsPlay = int(ConfigHelper.GetIni("isplay","0"))

    if IsPlay == 1:
        Speak("zh-CN","正在播放")#正在播放
        return
    else:
        while(count<cnt):
            try:
                ConfigHelper.SetValue("base","IsPlay","1")
                #获取音乐信息
                songInfo = (MusicLoader.GetMusic())
                song = songInfo.split("|")
        
                Speak("zh-CN",ConfigHelper.GetWord("exsonginfo"))#即将播放
            
                SpeakOneTime("zh-CN",song[0]+"。歌手:"+song[1])
                """
                rec = subprocess.call([player2, song[2]],
                                      shell=False,
                                      stdout=subprocess.PIPE,
                                      stderr=subprocess.PIPE)
                                      """
                
                rec = play(player2,song[2])
                if(rec == 1 or rec == 0):
                    count += 1
            except Exception,e:
                Speak("zh-CN",ConfigHelper.GetWord("musicerror"))#音乐播放异常
                print e
                pass
        Speak("zh-CN",ConfigHelper.GetWord("musicend"))#音乐结束
        ConfigHelper.SetValue("base","IsPlay","0")
Beispiel #3
0
    def run(self):
        while not self.thread_stop:
            try:
                rpm = "http://*****:*****@192.168.7.1/userRpm/WlanStationRpm.htm?Page=1 "
                mf = urllib.urlopen(rpm)
                html = mf.read()
                #html = html.decode('utf8')
                start = html.find("(", html.find("var hostList = new Array("))
                end = html.find(";", start)
                listjson = html[start:end].strip()

                listjson = listjson.replace("(\n",
                                            "").replace(",\n0,0 )",
                                                        "").replace(",", "")

                data = listjson.split("\n")

                count = 0
                listmac = []
                guests = ""
                isKnower = False
                for i in range(0, len(data) / 4):

                    listmac.append(data[i * 4].replace("\"", ""))

                if len(self.oldList) > 0 and len(listmac) > len(self.oldList):
                    newmac = set(self.oldList) ^ set(listmac)
                    for item in newmac:
                        if ConfigHelper.GetFamily(item) != "":
                            isKnower = True
                            guests += ConfigHelper.GetFamily(item) + ","
                        elif ConfigHelper.GetFriend(item) != "":
                            guests += ConfigHelper.GetFriend(item) + ","
                        elif ConfigHelper.GetNone(item) != "":
                            None
                        else:
                            guests += ConfigHelper.GetWord("myfriend")
                    if len(guests) > 0:
                        if isKnower:
                            SpeakHelper.Speak(
                                "zh-CN",
                                guests + ConfigHelper.GetWord("backhome"))
                            guests += ConfigHelper.GetWord("iwelcome")
                            InfraredHelper.CheckInfrared(guests, 3)
                        else:
                            if guests.find(
                                    ConfigHelper.GetWord("myfriend")) == -1:
                                time.sleep(20)
                            guests += ConfigHelper.GetWord("owelcome")
                            SpeakHelper.soundStart(guests, 1)

                        listmac = []

                self.oldList = listmac
            except Exception, e:
                SpeakHelper.Speak("zh-CN", ConfigHelper.GetWord("scanerror"))
                pass
            finally:
def CheckInfrared(talk, cnt=3):
    flag = True
    count = 0

    GPIO.output(16, GPIO.HIGH)
    while flag and count < int(ConfigHelper.GetIni("infrared", "60")):
        if (GPIO.input(12) == True):
            GPIO.output(16, GPIO.LOW)
            SpeakHelper.soundStart(talk, cnt)
            #time.sleep(3)
            flag = False
            count = int(ConfigHelper.GetIni("infrared", "60"))

        count += 1
        time.sleep(1)

    if flag:
        SpeakHelper.Speak("zh-CN", ConfigHelper.GetWord("unfind"))  #未扫描到对象
Beispiel #5
0
def SpeakOneTime(lan, words):
    
    param = {'q':words}

    data = urllib.urlencode(param)

    if(lan=="en"):
        """
        subprocess.call([player, (googleAPIurl%lan)+data],
                                  shell=False,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
                                  """
        play(player,(googleAPIurl%lan)+data)
    else:
        try:
            s = requests.Session()
            s.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0','Connection': 'Keep-Alive'})

            ret = s.post((googleAPIurl%lan)+data)
            ext = ret.headers["content-type"].split("/")[1]
            filename =("songinfo.%s" % ext)
        
            with open(filename, "wb") as f:
                f.write(ret.content)
                """
            log_file = "./mplayer.log"
            #with open(log_file, "w") as f:
                #subprocess.call([player, filename], stdout=f, stderr=f)
            subprocess.call([player, filename],
                            shell=False,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
            """
            play(player,filename)
        except Exception,e:
            Speak("zh-CN", ConfigHelper.GetWord("speakerror"))#语音异常
            pass
def main():
    threadWifiCheck = None
    #定义问候语
    jday = ConfigHelper.GetWord("jday")

    eday = ConfigHelper.GetWord("eday")

    vday = ConfigHelper.GetWord("vday")

    #aClock();
    SpeakHelper.Speak("zh-CN", ConfigHelper.GetWord("start"))

    #定义闹钟时间
    while (not_executed):
        try:
            dt = list(time.localtime())
            hour = dt[3]
            minute = dt[4]
            wday = dt[6]

            if (wday == 5 or wday == 6):
                if hour == 8 and minute == 00:
                    aClock()
                    SpeakHelper.soundStart(eday)

                if hour == 8 and minute == 30:
                    aClock()
                    SpeakHelper.soundStart(eday)

            else:
                if hour == 6 and minute == 40:
                    aClock()
                    SpeakHelper.soundStart(jday, 3)

                if hour == 7 and minute == 00:
                    aClock()
                    SpeakHelper.soundStart(jday)

                if hour == 7 and minute == 30:
                    aClock()
                    SpeakHelper.soundStart(ConfigHelper.GetWord("bcdl"), 3)

                if hour == 8 and minute == 00:
                    aClock()
                    SpeakHelper.soundStart(ConfigHelper.GetWord("bcdl"), 3)

            if hour == 22 and minute == 00:
                aClock()
                SpeakHelper.soundStart(ConfigHelper.GetWord("mlyt"))

            if hour == 20 and minute == 00:
                aClock()
                SpeakHelper.soundStart(ConfigHelper.GetWord("dsgb"))

            if (hour > int(ConfigHelper.GetIni("aclock", "8"))
                    and minute == 00):
                aClock()
                #避免同一分钟之内多次报时
                time.sleep(int(ConfigHelper.GetIni("smjg", "30")))

            if threadWifiCheck is None:
                print "thread begin"
                threadWifiCheck = CheckWifiGuest.CheckGuest()
                threadWifiCheck.start()

        except Exception, e:
            print e
            pass
        finally: