コード例 #1
0
def askForMonth(recognizer, button):
    month = None
    while month is None:
        print('Which month are you intrested in?')
        aiy.audio.say('Which month are you intrested in?')
        text = speechToTextConverter(button, recognizer)
        month = helper.getMonth(text)
        print(month)
    return month
コード例 #2
0
def main():
    button = aiy.voicehat.get_button()
    led = aiy.voicehat.get_led()
    aiy.audio.get_recorder().start()
    connectPhone.init()
    assistant = aiy.assistant.grpc.get_assistant()
    while True:
        text = speechToTextConverter(button, assistant)
        print(text)
        stationName = ""
        typeOfData = ""
        year = ""
        month = ""
        answered = False
        temperature = ['temperature', 'temp', 'hot', 'cold']
        for temp in temperature:
            if not answered:
                if temp in text:
                    typeOfData = temp
                    stationName, stationID = helper.getStationName(text)
                    connectPhone.setIntent(stationID)
                    if stationName == None:
                        stationName = askForStationName(assistant, button)
                    result = owm.request(stationName) - 273.15
                    aiy.audio.say("The temperature at " + stationName +
                                  " is " + str(round(result, 2)) + 'celsius')
                    answered = True
                    print("The temperature at " + stationName + " is " +
                          str(result))
        rainfall = ['rain', 'rainfall', 'rainy']
        for rain in rainfall:
            if not answered:
                if rain in text:
                    stationName, stationID = helper.getStationName(text)
                    connectPhone.setIntent(stationID)
                    if stationName == None:
                        stationName = askForStationName(assistant, button)
                    year = helper.getYear(text)
                    if year == None:
                        year = askForYear(assistant, button)
                    month = helper.getMonth(text)
                    if month == None:
                        month = askForMonth(assistant, button)
                    result = qerry.getResult(stationName, 0, year, month,
                                             helper.getDeafultPath())
                    if year == 2018:
                        result = "The rainfall at " + stationName + " is predicted to be " + str(
                            result) + 'mm'
                    else:
                        result = "The rainfall was " + stationName + " is " + str(
                            result) + 'mm'
                    aiy.audio.say(result)
                    answered = True
                    print("The rainfall at " + stationName + " is " +
                          str(result))
        if 'today' in text or 'clouds' in text or 'cloud' in text:
            if not answered:
                stationName = helper.getStationName(text)
                if stationName == None:
                    stationName = askForStationName(assistant, button)
                result = owm.cloudsToday(stationName)
                aiy.audio.say("The weather is " + str(result))
                print("The weather is " + result)
                answered = True

        rainfall = ['Thank you', 'Thanks', 'Thank', 'Bye']
        for rain in rainfall:
            if not answered:
                if rain.lower() in text.lower():
                    result = "My developers are keen at teaching me farming and I'm consistently learning"
                    aiy.audio.say(result)
                    time.sleep(0.3)
                    result = "Thank you"
                    aiy.audio.say(result)
                    answered = True
                    exit(0)
        if (not answered):
            aiy.audio.say("Sorry the question is not properly audible!")
            connectPhone.updateQuestion(text)
コード例 #3
0
ファイル: vivthomas.py プロジェクト: balletootu/photosets
def fetch_model(url, name, head_img):
    '''fetch model'''
    model_dir = os.path.join('vivthomas', 'model')
    helper.mkDir(model_dir)
    helper.mkDir(os.path.join('vivthomas', 'photo'))
    # 下载头像先
    helper.downloadImg(head_img, os.path.join(
        model_dir, '%s.jpg' % name))
    if os.path.exists(os.path.join('vivthomas', 'model', '%s.json' % (name))):
        return
    # 然后去抓取详细数据
    model_info = {
        'name': name,
        'photos': []
    }
    pyquery = helper.get(url)
    country_span = pyquery('.custom-country')
    model_info['country'] = country_span.text() if country_span else 'unknow'

    # 获取照片数据
    custom_content_list = pyquery('.custom-content-list')
    custom_content = None
    for item in custom_content_list:
        if item.getchildren()[0].getchildren()[0].text.startswith('Photos with'):
            custom_content = item
            break
        # if item.getchildren()[0].getchildren()[0].text:
        #     pass
    if custom_content is None:
        helper.writeFile(json.dumps(model_info), os.path.join(
            'vivthomas', 'model', '%s.json' % (name)))
        return
    # if len(custom_content_list) == 3:
    #     custom_content = custom_content_list[1]
    # else:
    #     custom_content = custom_content_list[0]
    list_group_item_list = custom_content.getchildren()[2].findall('li')
    for list_group_item in list_group_item_list:
        custom_list_item_detailed = list_group_item.getchildren()[1]
        img = custom_list_item_detailed.getchildren()[0].getchildren()[
            0].getchildren()[0]
        # custom_list_item_detailed.getchildren()[1].getchildren()[0].getchildren()[0].text
        photo_name = img.get('alt')
        # Released: Feb 26, 2016
        date_str = custom_list_item_detailed.getchildren()[1].getchildren()[
            1].text_content().split(': ')[1]
        date_str = '%s-%d-%s' % (date_str.split(', ')[1], helper.getMonth(
            date_str.split(' ')[0]), date_str.split(' ')[1].replace(',', ''))
        # 模特名
        arr = custom_list_item_detailed.getchildren()[1].getchildren()[
            2].getchildren()
        model_name_arr = []
        for i in xrange(1, len(arr)):
            model_name_arr.append(arr[i].text)
        # model_name = custom_list_item_detailed.getchildren()[1].getchildren()[2].getchildren()[1].text
        # print(model_name_arr)
        # date = datetime.datetime(int(date_str.split(', ')[1]), helper.getMonth(date_str.split(' ')[0]), int(date_str.split(' ')[1].replace(',', '')))
        # print date
        # 下载照片的封面
        photo_path = os.path.join('vivthomas', 'photo', '%s_%s' % (date_str, photo_name.replace(
            '/', ' ')), '%s_%s.jpg' % (date_str, photo_name.replace('/', ' ')))
        helper.downloadImg(img.get('src'), photo_path)
        # 存到数据库
        # mongo.newAlbun(photo_name, date)
        photo_json = {
            'date': date_str,
            'name': photo_name,
            'model': model_name_arr
        }
        photo_json_str = json.dumps(photo_json)
        model_info.get('photos').append(photo_json)
        helper.writeFile(photo_json_str, os.path.join(
            'vivthomas', 'photo', '%s_%s' % (date_str, photo_name), '%s_%s.json' % (date_str, photo_name)))
    helper.writeFile(json.dumps(model_info), os.path.join(
        'vivthomas', 'model', '%s.json' % (name)))
コード例 #4
0
    photo_dir = '/Users/eddie104/Documents/hongjie/photosets/femjoy/photo'
    helper.mkDir(photo_dir)
    for model in modelArr:
        page = 1
        while True:
            url = 'https://www.femjoy.com/api/v2/actors/%s/galleries?thumb_size=481x642&limit=20&page=%d' % (
                model.get('slug'), page)
            txt = helper.get(url, returnText=True)
            jsonData = json.loads(txt)
            total_pages = jsonData.get('pagination').get('total_pages')

            for photoData in jsonData.get('results'):
                dateArr = photoData.get('release_date').split(' ')
                dateStr = '%s-%s-%s' % (
                    dateArr[2], helper.getMonth(dateArr[0].replace(
                        ',', '')), dateArr[1].replace(',', ''))
                modelNameArr = []
                for actor in photoData.get('actors'):
                    modelNameArr.append(actor.get('name'))
                photo = {
                    'id': photoData.get('id'),
                    'img': photoData.get('thumb').get('image'),
                    'model': modelNameArr,
                    'name': photoData.get('title'),
                    'date': dateStr
                }
                album_dir = os.path.join(
                    photo_dir, '%s_%s' % (dateStr, photo.get('name')))
                helper.mkDir(album_dir)
                helper.downloadImg(
                    photo.get('img'),