监控图书馆书籍状态并发送邮件提醒

监控图书馆书籍状态并发送邮件提醒

适用于心仪的图书被借光了的情况,当有人还书,该书的状态变为可借时自动发送邮件提醒。
tips:使用139邮箱还会有短信提醒,发件人和收件人可以相同。

#!coding=utf-8
import requests
import sys
import time
import smtplib
import email.mime.multipart
import email.mime.text
# reload(sys)
# sys.setdefaultencoding('utf8')

bookmysql="http://211.87.177.4/opac/item.php?marc_no=0000377401"
booklinux="http://211.87.177.4/opac/item.php?marc_no=0000387713"
booktest="http://211.87.177.4/opac/item.php?marc_no=0000312783"

while(1):
    time.sleep(600)#秒为单位
    r=requests.get(url=bookmysql)
    r2=requests.get(url=booklinux)
    #r=requests.get(url=booktest)
    text=r.content.decode(encoding="utf-8", errors="strict")
    text2=r2.content.decode(encoding="utf-8", errors="strict")
    if ("可借" in text or "可借" in text2):
        print("发现书籍!")
        ####发送邮件
        msg=email.mime.multipart.MIMEMultipart()
        msg['from']='xxxxxxxx@139.com'
        msg['to']='xxxxxxxx@139.com'
        msg['subject']='有书啦!'#主题
        content='''
            有人还书啦!快去借吧!
            详情请登录library.upc.edu.cn
        '''
        txt=email.mime.text.MIMEText(content)
        msg.attach(txt)
        smtp=smtplib
        smtp=smtplib.SMTP()
        smtp.connect('smtp.139.com','25')
        smtp.login('xxxxxxxxx@139.com','yourpassword')
        smtp.sendmail('xxxxxxxxxxx@139.com','xxxxxxxxxxx@139.com',str(msg))
        smtp.quit()
        print("邮件发送成功!")
        break
    else:
        print("未发现书籍!")
print("监控结束!")
# print(r.content.decode(encoding="utf-8", errors="strict"))

源码:https://github.com/wukuai/Interesting/blob/master/monitorTheBooks.py

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值