本帖最后由 从零学习的歪经小 于 2021-4-29 12:21 编辑
看了 医生 发表的 女朋友要我每天给她报天气,这不耽误我打游戏嘛 也来搞个玩玩
[Python] 纯文本查看 复制代码 # -*- coding: utf-8 -*-
import requests
def post_data(data):
qmsg_url = 'https://qmsg.zendee.cn/send/key' #填你的key
res = requests.post(qmsg_url, data=data).json()
print(res['reason'])
def morning():
url = 'http://api.tianapi.com/txapi/zaoan/index?key=???'#从这自己申请https://www.tianapi.com/apiview/143
res = requests.get(url).json()
content = res['newslist'][0]['content']
data = {
'msg': "早上好呀,老公大人@face=2@@face=49@@face=109@\n%s@face=175@" % content
}
post_data(data)
def weather(code):
url = 'http://t.weather.itboy.net/api/weather/city/%d' % code
res = requests.get(url, headers=headers).json()
city = res['cityInfo']['city'] # 地区
forecast = res['data']['forecast'] # 具体天气
quality = res['data']['quality']
pm25 = res['data']['pm25']
pm10 = res['data']['pm10']
ganmao = res['data']['ganmao'] # ganmao: "各类人群可自由活动"
shidu = res['data']['shidu']
wendu = res['data']['wendu'] + '℃'
for lmaki_data, lmaki in zip(forecast, ['今天', '明天']):
ymd = lmaki_data['ymd'] # 时间
week = lmaki_data['week'] # 星期几
sunrise = lmaki_data['sunrise'] # 日出
sunset = lmaki_data['sunset'] # 日落
high = lmaki_data['high'] # 最高温
low = lmaki_data['low'] # 最低温
fx = lmaki_data['fx'] # 风向
fl = lmaki_data['fl'] # 几级风
type_we = lmaki_data['type'] # 天气
notice = lmaki_data['notice'] # 提示语
total = f'@face=6@{lmaki}是{week},天气是 {type_we} 哦,温度为{wendu},湿度为{shidu}\npm2.5的值为{pm25},pm1.0的值是{pm10},{ganmao}\n{high},{low},{notice},吹的是{fx},风速达到了{fl}了。\n太阳将在 {sunrise} 升起,{sunset} 落下\n天气质量为 {quality}@face=13@ {ymd} {city}'
data = {
'msg': total
}
post_data(data)
def main():
morning()
weather(101210805) #城市代码
if __name__ == '__main__':
headers = {
'User - Agent': 'Mozilla / 5.0(Windows NT 10.0;WOW64) AppleWebKit / 537.36(KHTML, likeGecko) Chrome / 86.0.4240.198Safari / 537.36'
}
main()
实际是来水的
这个是那个早安的api申请地址,每天100次,别把我的用完了。https://www.tianapi.com/apiview/143
没想到这么快,100次直接用超了200多次。。。。。你们自己申请一个吧。 |