定制自己的天氣預報小助手放坏。
想體驗一下智能家居的生活顾瞻,用python寫個腳本管引,每天早上獲取當?shù)靥鞖馇闆r佳晶,并自定義播報內(nèi)容。
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()