欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

双色球中奖邮件提醒

程序员文章站 2022-03-10 09:53:42
...
#-*-coding:utf8-*-
import requests
from lxml import etree
import smtplib
from email.mime.text import MIMEText


def get_latest_code():
    url = "http://datachart.500.com/ssq/history/newinc/history.php" #双色球开奖结果查询页面,start和end对应的是期数
    response = requests.get(url)
    response = response.text
    selector = etree.HTML(response)
    for i in selector.xpath('//tr[@class="t_tr1"]'):
        datetime = i.xpath('td/text()')[0] #期数
        a = i.xpath('td/text()')[1]#红球1
        b = i.xpath('td/text()')[2]#红球2
        c = i.xpath('td/text()')[3]#红球3
        d = i.xpath('td/text()')[4]#红球4
        e = i.xpath('td/text()')[5]#红球5
        f = i.xpath('td/text()')[6]#红球6
        red = i.xpath('td/text()')[7] #篮球
        break
    return datetime, "{0} {1} {2} {3} {4} {5}".format(a, b, c, d, e, f), red

def is_win(your_code):
    your_code = your_code.split("+")
    blue_ball, red_ball = your_code[0].split(" "), your_code[1].split(" ")
    win_ball = get_latest_code()
    win_blue_ball,  win_red_ball= win_ball[1].split(" "), win_ball[2]

    if win_red_ball in red_ball:
        return True
    elif len(set(win_blue_ball).intersection(blue_ball)) >= 4:
        return True
    else:
        return False


if __name__ == "__main__":
    balls = get_latest_code()
    win_code = "期数{0}:{1}+{2}".format(balls[0], balls[1], balls[2])
    your_code = "05 09 10 12 23 30+05 01 10"  # 配置你的号码

    mail_host = "smtp.qq.com"  #设置服务器
    mail_user = "********@qq.com"    #用户名
    mail_pass = "********"   #口令

    sender = 'wadedy'
    receivers = ['[email protected]']
    content = '中奖了,开奖号码:{0}, 你的号码:{1}'.format(win_code, your_code)
    title = '中奖啦!!!'  # 邮件主题
    message = MIMEText(content, 'plain', 'utf-8')  # 内容, 格式, 编码
    message['From'] = "{}".format(sender)
    message['To'] = ",".join(receivers)
    message['Subject'] = title

    if is_win(your_code):
        smtpObj = smtplib.SMTP_SSL(mail_host, 465)  # 启用SSL发信, 端口一般是465
        smtpObj.login(mail_user, mail_pass)  # 登录验证
        smtpObj.sendmail(mail_user, receivers, message.as_string())  # 发送

定时任务:
每周2、4、7的23:15执行python脚本,如果中奖,就会发送邮件到指定的邮箱

15 23 * * 0,2,4 /opt/balls/exec_py.sh >>/dev/null 2>&1
相关标签: 其他 其他