TA的每日心情 | 奋斗 6 小时前 |
---|
签到天数: 533 天 [LV.9]以坛为家II
版主
- 积分
- 1216
|
- import requests
- import json
- spkey ='888888888888888888888888888888'
- def Get_iciba_everyday():#通过爱词霸的接口 获取每日的句子 进行推送
- iciba = "http://open.iciba.com/dsapi/"
- res = requests.get(url=iciba)
- res = json.loads(res.content.decode('utf-8'))
- English = res['content']
- Chinese = res['note']
- str = '小陈的奇怪知识\n'+English+'\n'+Chinese
- return str
- def send(*args):
- try:
- api = 'http://t.weather.itboy.net/api/weather/city/+城市代码'
- res = requests.get(api)
- d = res.json()
- if(d['status'] == 200):
- parent = d['cityInfo']['parent']#省份
- city = d['cityInfo']['city']#城市
- update_time = d['time']#更新的时间
- date = d["data"]["forecast"][0]["ymd"] # 日期
- week = d["data"]["forecast"][0]["week"] # 星期
- weather_type = d["data"]["forecast"][0]["type"] # 天气
- wendu_high = d["data"]["forecast"][0]["high"] # 最高温度
- wendu_low = d["data"]["forecast"][0]["low"] # 最低温度
- shidu = d["data"]["shidu"] # 湿度
- shidu = d["data"]["shidu"] # 湿度
- pm25 = str(d["data"]["pm25"]) # PM2.5
- pm10 = str(d["data"]["pm10"]) # PM10
- quality = d["data"]["quality"] # 天气质量
- fx = d["data"]["forecast"][0]["fx"] # 风向
- fl = d["data"]["forecast"][0]["fl"] # 风力
- ganmao = d["data"]["ganmao"] # 感冒指数
- tips = d["data"]["forecast"][0]["notice"] # 温馨提示
- cpurl = '酷推链接' + spkey#通过酷推 推送到目标群
- tdwt = Get_iciba_everyday() + "\n-----------------------------------------" + "\n【今日份天气】\n城市: " + parent + city + \
- "\n日期: " + date + "\n星期: " + week + "\n天气: " + weather_type + "\n温度: " + wendu_high + " / " + wendu_low + "\n湿度: " + \
- shidu + "\nPM25: " + pm25 + "\nPM10: " + pm10 + "\n空气质量: " + quality + \
- "\n风力风向: " + fx + fl + "\n感冒指数: " + ganmao + "\n温馨提示: " + tips + "\n更新时间: " + update_time
- requests.post(cpurl, tdwt.encode('utf-8'))
- except:
- error = '【出现错误】\n 今日天气推送错误,请联系小陈检查服务或网络状态!'
- print(error)
- if __name__== '__main__':
- send()
复制代码
|
-
查看全部评分
总评分:好评 +1
贡献 +1
|