美文网首页思科DevNet
python定制私有的天气助手

python定制私有的天气助手

作者: 哩白 | 来源:发表于2020-10-07 13:20 被阅读0次

    定制自己的天气预报小助手。

    想体验一下智能家居的生活,用python写个脚本,每天早上获取当地天气情况,并自定义播报内容。

    import requests

    import pyttsx3

    import json

    url = "http://www.weather.com.cn/data/sk/101010300.html"

    #查询当前天气朝阳id101010300

    cur_tq = requests.get(url)

    cur_tq.encoding = "utf-8"

    curtqjson = json.loads(cur_tq.text)

    #str 转json

    local = curtqjson['weatherinfo']['city']

    temp = curtqjson['weatherinfo']['temp']

    weath = curtqjson['weatherinfo']['WD']

    #语音转文字

    e = pyttsx3.init()

    e.say("主人您好,您当前所处的位置是"+local+"温度"+temp+"天气"+weath)

    e.runAndWait()

    相关文章

      网友评论

        本文标题:python定制私有的天气助手

        本文链接:https://www.haomeiwen.com/subject/ljrtpktx.html