python自动回复邮件 怎么用python做自动回复机器人( 二 )
重新分析网页XHR即可获取真正的访问连接
https://v2.jinrishici.com/one.json?client=browser-sdk/1.2&X-User-Token=xxxxxx,Token见下图:
![python自动回复邮件 怎么用python做自动回复机器人](http://img.jiangsulong.com/221112/0513235449-3.jpg)
文章插图
分析好原因后代码反而更加简单了:
import requestsurl = 'https://v2.jinrishici.com/one.json?client=browser-sdk/1.2&X-User-Token=xxxxxx'response = requests.get(url)print(response.json()['data']['content'])
![python自动回复邮件 怎么用python做自动回复机器人](http://img.jiangsulong.com/221112/0513232552-4.jpg)
文章插图
返回的诗句直接就可以作为函数结果返回,因此代码又可以写成:
import requestsdef get_verse():url = 'https://v2.jinrishici.com/one.json?client=browser-sdk/1.2&X-User-Token=xxxxxx'response = requests.get(url)return f'您要的每日诗句为:{response.json()["data"]["content"]}'
获取天气可以使用官方提供的 API 了,以广州为例:
import requestsurl = 'http://wthrcdn.etouch /weather_mini?city=广州'response = requests.get(url)print(response.json())
![python自动回复邮件 怎么用python做自动回复机器人](http://img.jiangsulong.com/221112/05132335F-5.jpg)
文章插图
根据返回的 json 数据很容易获取今日的天气情况和最高最低气温,组合成函数效果如下:
def get_weather(city):url = f'http://wthrcdn.etouch /weather_mini?city={city}'response = requests.get(url).json()results = response['data']['forecast'][0]return f'{city}今天的天气情况为{results["type"]},{results["high"][:-1]}度,{results["low"][:-1]}度'
至此,代码部分就写完了 。我们的自动回复机器人也就拥有了两个简单的功能,当然你可以结合自己的需求实现有意思的功能!最后附上完整代码供大家学习与交流
import keyringimport yagmailfrom imbox import Imboximport requestsimport timepassword = keyring.get_password('88mail', 'test88.com')def get_verse():url = 'https://v2.jinrishici.com/one.json?client=browser-sdk/1.2&X-User-Token=xxxxxx'response = requests.get(url)return f'您要的每日诗句为:{response.json()["data"]["content"]}'def get_weather(city):url = f'http://wthrcdn.etouch /weather_mini?city={city}'response = requests.get(url).json()results = response['data']['forecast'][0]return f'{city}今天的天气情况为{results["type"]},{results["high"][:-1]}度,{results["low"][:-1]}度'def send_mail(email, results):mail = yagmail.SMTP(user='test88.com', password=password, host='smtp.88.com')contents = [results]mail.send(email, '【自动回复】您要的信息见正文', contents)def main():with Imbox('imap.88.com', 'test88.com', password, ssl=True) as imbox:unread_inbox_messages = imbox.messages(unread=True)# 获取未读邮件for uid, message in unread_inbox_messages:title = message.subjectemail = message.sent_from[0]['email']results = ''if title == '来句诗':results = get_verse()if title[-2:] == '天气':results = get_weather(title[:-2])if results:send_mail(email, results)imbox.mark_seen(uid)while True:main()time.sleep(600)
【python自动回复邮件 怎么用python做自动回复机器人】Tags:
推荐阅读
- 拼多多商家怎么设置自动回复短语 拼多多常用回复的话术
- 支付宝森林能量自动收取 支付宝线上支付能获得蚂蚁森林能量吗
- 电脑设置自动关机的步骤 电脑自动关机设置
- 360浏览器如何设置自动清除历史记录 360浏览器怎么删除历史浏览记录
- 支付宝的余额如何取消自动转入余额宝 支付宝怎么设置关闭余额自动转入余额宝
- 全自动洗衣机进水口不出水怎么办
- pdf整篇自动翻译最好的软件 用什么软件翻译pdf最好
- 雷佳音|万茜觉得雷佳音很适合演宋金言, 直接打电话给他, 雷佳音回复超搞笑
- 自动挡汽车驾驶技巧! 自动挡驾驶技巧
- 自动档开车起步步骤 小车开车步骤