美文网首页
Python工具:双色球中奖邮件通知

Python工具:双色球中奖邮件通知

作者: 海阔天空的博客 | 来源:发表于2021-12-03 23:57 被阅读0次

名称:

双色球中奖邮件通知

功能:

1、每个开奖日后第二天以邮件方式通知是否中奖。

思路:

1、使用Python,跨平台,三方库功能强大

2、从网页上爬取当前的开奖号码 http://cp.360.cn/kj/ssq.html?agent=700007

3、与自己填写的号码检测是否匹配中奖

4、判断后发送邮件通知

5、每周2、4、7开奖,则每周3、5、1凌晨1点(可修改为上午十点最好)判断并发送。

# -*- coding: UTF-8 -*-
import smtplib  
import urllib2
import string
import datetime
import time
 
#from email.mime.text import MIMEText 
from email.MIMEText import MIMEText
from email.Header import Header 
 
 
#我的号码
my_code_six = [1, 4, 8, 15, 17, 28]
my_code_one = 3
 
#网页地址
web_url = "http://cp.360.cn/kj/ssq.html?agent=700007"
 
#彩票开奖内容
lottery_date = ""
lottery_code_six = []
lottery_code_one = 0
 
#号码匹配
winning_red_count = 0;
winning_blue_count = 0;
 
mailto_list=";"
mail_host=""  #设置服务器
mail_user=""    #用户名
mail_pass=""   #口令 
mail_postfix="163.com"  #发件箱的后缀
   
def send_mail(to_list,sub,content):  
    global mailto_list
    global mail_host
    global mail_user
    global mail_pass
    global mail_postfix
         
    me="中大奖"+"<"+mail_user+"@"+mail_postfix+">" 
    msg = MIMEText(content,_subtype='plain',_charset='gb2312')  
    msg['Subject'] = sub  
    msg['From'] = me  
    msg['To'] = to_list
    try:  
        server = smtplib.SMTP()  
        server.connect(mail_host)  
        server.login(mail_user,mail_pass)  
        server.sendmail(me, to_list, msg.as_string())  
        server.close()  
        return True 
    except Exception, e:  
        print str(e)  
        return False 
 
 
def check_lottery():  
    global lottery_date
    global winning_red_count
    global winning_blue_count
    global lottery_code_six
    global lottery_code_one
    global my_code_one
    global my_code_six
    global web_url
     
    winning_red_count = 0
    winning_blue_count = 0
     
    response = urllib2.urlopen(web_url)
    html = response.read()
    #print html
     
    #date
    key = "option value='"
    nPos = html.index(key)
    if nPos <= 0:
        return 0
    html = html[nPos + len(key) : nPos + len(key) + 37]
    print 'GET NEW RESULT:   ' + html
    nPos = html.index("'")
    if nPos <= 0:
        return 0
         
    lottery_date = html[0 : nPos]
    #print lottery_date
     
    #first code
    key = "code='"
    nPos = html.index(key)
    if nPos <= 0:
        return 0
    html = html[nPos + len(key) : ]
    nPos = html.index(" ")
    if nPos <= 0:
        return 0
    first_code = html[0 : nPos]
    #print first_code
    html = html[3 : ]
    #print html
     
    #second code
    key = " "
    nPos = html.index(key)
    if nPos <= 0:
        return 0
     
    second_code = html[0 : nPos]
    #print second_code
    html = html[3 : ]
    #print html
     
    #three code
    key = " "
    nPos = html.index(key)
    if nPos <= 0:
        return 0
     
    three_code = html[0 : nPos]
    #print three_code
    html = html[3 : ]
     
    #four code
    key = " "
    nPos = html.index(key)
    if nPos <= 0:
        return 0
     
    four_code = html[0 : nPos]
    #print four_code
    html = html[3 : ]
     
    #five code
    key = " "
    nPos = html.index(key)
    if nPos <= 0:
        return 0
     
    five_code = html[0 : nPos]
    #print five_code
    html = html[3 : ]
     
    #six code
    key = "+"
    nPos = html.index(key)
    if nPos <= 0:
        return 0
     
    six_code = html[0 : nPos]
    #print six_code
    html = html[3 : ]
     
    #one code
    key = "'"
    nPos = html.index(key)
    if nPos <= 0:
        return 0
     
    one_code = html[0 : nPos]
     
    lottery_code_six.append(first_code)
    lottery_code_six.append(second_code)
    lottery_code_six.append(three_code)
    lottery_code_six.append(four_code)
    lottery_code_six.append(five_code)
    lottery_code_six.append(six_code)
     
    lottery_code_one = string.atoi(one_code)
     
    for lottry_code in lottery_code_six:
        for my_code in my_code_six:
            if string.atoi(lottry_code) == my_code:
                winning_red_count = winning_red_count + 1
                break
    if my_code_one == lottery_code_one:
        winning_blue_count = 1
        print "ok"
     
    print my_code_one
    print one_code
     
    need_send_email = 0;
    #blue more than 1
    if winning_blue_count >= 1 :
        need_send_email = 1
         
    #red more than 4
    if winning_red_count >= 4:
        need_send_email = 1
         
    print need_send_email
    return need_send_email
 
def check_date():
    date_vaule = datetime.datetime.now().weekday() + 1
    print 'date_vaule:' + str(date_vaule)
    if ((date_vaule != 1) and (date_vaule != 3) and (date_vaule != 5)):
        return 0
         
    hour = time.strftime("{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}H", time.localtime()) 
    minute = time.strftime("{b75a474a571334bb08f4db31fa80d7688c6401b1dcf97fb55e06ed241b59472c}M", time.localtime()) 
    print 'hour:' + hour + '. minute:' + minute
    if string.atoi(hour) != 1 or string.atoi(minute) != 0:
        return 0
     
    print 'date_vaule:' + str(date_vaule) + '.hour:' + hour + '.minute:' + minute
    return 1
     
if __name__ == '__main__':  
    
    while True:
        if check_date() <= 0:
            print 'do noting'
            time.sleep(40)
             
        else:
            print "It's time to check lottery!!"
            result = check_lottery()
            print result
             
            send_message = "您的号码:"
            for my in my_code_six:
                send_message += str(my) + ","
            send_message += ":" + str(my_code_one) + "    "
             
            send_message += "开奖号码:"
             
            for lottery in lottery_code_six:
                send_message += str(lottery) + ','
            send_message += ":" + str(lottery_code_one)
             
            print send_message
 
            head = ""
 
            if  result > 0:
                head = "恭喜您中奖了,去看看吧"
                 
            else :
                head = "下次一定能中的"
            print head
 
            if send_mail(mailto_list,head, send_message):  
                    print "Send email ok" 
            else:  
                print "Send email faile"
            time.sleep(70)

本文摘录于海阔天空的博客,作者: zjg555543,发布时间: 2015-09-16

相关文章

  • Python工具:双色球中奖邮件通知

    名称: 双色球中奖邮件通知 功能: 1、每个开奖日后第二天以邮件方式通知是否中奖。 思路: 1、使用Python,...

  • 5700亿,16227注!15年来,双色球一等奖中奖占比率几乎不

    源 / 恋习Python 双色球一等奖中奖占比率一直徘徊在7%左右 去年,我曾写过一篇文章《我用Python爬取了...

  • 放假于我并不开心

    今天衡水的新闻主要有两条,一条是深州市有一位买双色球中奖千万的彩票客。另一个就是关于寄宿学校放假的通知。 中奖的奖...

  • 中奖通知

    本期《Redis实战-恒宇少年签名版》中奖人为:“多捞啊”今天会通过快递发出,注意查收。活动还会持续进行,请大家多...

  • 水电费刚刚

    双色球偏度走势图 双色球的偏度和散度 本期的中奖号码是多少 偏度分析是什么意思 偏度在投资中的意义 新浪双色球走势...

  • 双色球开奖号码

    文档整理了中国福彩双色球,从第一期(20130101)到20190516,所有开奖号码,中奖人数、中奖金额和销售额...

  • 《Flask Web Development》第6章-邮件

    当某些事件被触发,应用程序通常需要通过邮件方式通知用户。Python的原生包smtplib能够被用于发送邮件,但是...

  • 今天双色球开奖日,祝大家中千万大奖

    中奖彩吧推荐双色球069期 (上期红球中4个) 围14红:01.03.04.06.08.12.14.18.20.2...

  • 腾讯企业邮箱smtp发邮件

    MGXJMWJDEMNVUGQN 腾讯企业邮箱发邮件通知(python脚本): 可读文件的版本 原版 未测试版本

  • Python更新通知器(邮件实现)

    缘起 原来做出个什么小东西后总是喜欢用Github或者码云(Gitee)来分享。 可是着实的不方便,说实话,Git...

网友评论

      本文标题:Python工具:双色球中奖邮件通知

      本文链接:https://www.haomeiwen.com/subject/xsudaltx.html