Last active
February 19, 2018 11:23
-
-
Save menyf/4208d86f9685df141d71a0754b584bb3 to your computer and use it in GitHub Desktop.
byrbt的free种子通知脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests, re, time, smtplib | |
from email.mime.text import MIMEText | |
from email.utils import formataddr | |
def mail(Subject): | |
my_sender='[email protected]' # 发件人邮箱账号 | |
my_pass = 'your_pwd' # 发件人邮箱密码(当时申请smtp给的口令) | |
my_user='[email protected]' # 收件人邮箱账号,我这边发送给自己 | |
ret=True | |
try: | |
msg=MIMEText('Have a good day.','plain','utf-8') | |
msg['From']=formataddr(["BYR机器人",my_sender]) # 括号里的对应发件人邮箱昵称、发件人邮箱账号 | |
msg['To']=formataddr(["主人",my_user]) # 括号里的对应收件人邮箱昵称、收件人邮箱账号 | |
msg['Subject']=Subject # 邮件的主题,也可以说是标题 | |
server=smtplib.SMTP_SSL("smtp.qq.com", 465) # 发件人邮箱中的SMTP服务器,端口是465 | |
server.login(my_sender, my_pass) # 括号中对应的是发件人邮箱账号、邮箱密码 | |
server.sendmail(my_sender,[my_user,],msg.as_string()) # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件 | |
server.quit()# 关闭连接 | |
except Exception:# 如果 try 中的语句没有执行,则会执行下面的 ret=False | |
ret=False | |
if ret: | |
print("邮件发送成功") | |
else: | |
print("邮件发送失败") | |
return | |
def notifyGoodTorrent(timeInterval, minTorrentSize, maxTorrentSize): | |
hd={ | |
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36", | |
"Cookie": "Your_cookie" | |
} | |
req = requests.get('http://bt.byr.cn/torrents.php?spstate=2', headers=hd) | |
html = req.text | |
re_title = re.compile('<a title="(.*?)" href="details.') | |
re_time = re.compile('<span title="(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})">.*?rowfollow">(.*?)</td') | |
data = [] # data of free list | |
for a, b in zip(re_title.findall(html), re_time.findall(html)): | |
uptime = time.strptime(b[0],"%Y-%m-%d %H:%M:%S") | |
filesize = b[1].replace('<br />', "") | |
if filesize[-2] == 'G': | |
filesize = float(filesize[:-2])*1024 | |
elif filesize[-2] == 'M': | |
filesize = float(filesize[:-2]) | |
elif filesize[-2] == 'T': | |
filesize = float(filesize[:-2])*1024*1024 | |
else: | |
continue | |
title = a | |
data.append((uptime, filesize, title)) | |
for item in data: | |
distance = time.time() - time.mktime(item[0]) | |
if distance < timeInterval and item[1] > minTorrentSize and item[1] < maxTorrentSize: | |
mail("【BYR】[" + str(item[1]/1024) + "GB]"+ item[2]) | |
def main(): | |
timeInterval = (2 * 24 * 60 + 0) * 60 # in sec | |
minTorrentSize = 2 * 1024 # in MB | |
maxTorrentSize = 10 * 1024 # in MB | |
notifyGoodTorrent(timeInterval, minTorrentSize, maxTorrentSize) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment