python get the winning Lotto results

Realization of ideas:

  1. urllib crawling through repository http://zx.500.com/dlt/ page, and filter information

  2. buy their lottery numbers and lottery numbers matching the query whether winning

  3. The winning results happen to your mailbox

 

caipiao.py # Get the latest results of a lottery

# -*- coding:utf-8 -*-
# @Time: 2019-08-05 9:48
import re
import urllib
import time
import sys
def get_winnum():
    datapath = sys.path[0]
    datasuffix = 'txt'
    if (len(sys.argv)>1):
        datapath = sys.argv[1]
        datasuffix = sys.argv[2]

    def getHtml(url):
        html = urllib.urlopen(url)
        return html.read()


    html = getHtml("http://zx.500.com/dlt/")


    reg =  ['<dt>([0-9]\d*).*</dt>']
    reg.append('<li class="redball">([0-9]\d*)</li>')
    reg.append('<li class="blueball">([0-9]\d*)</li>')

    outstr = "";
    for i in range(len(reg)):
        page = re.compile(reg[i])
        rs = re.findall(page,html)
        for j in range(len(rs)):
            outstr+= rs[j] + ","

    #print time.strftime('%Y-%m-%d',time.localtime(time.time()))+":"+outstr[:-1]

    with open(datapath+'/lot_500_dlt.'+datasuffix, 'a') as f:
        f.write(time.strftime('%Y-%m-%d',time.localtime(time.time()))+":"+outstr[:-1]+'\n')

if __name__ == '__main__':
    get_winnum()

sendmail.py # Send e-mail

# - * - Coding: UTF- 8 - * - 
# Author: xueminchao 
# @time: 2019 - 08 - 05  15 : 00 

Import smtplib 
from email.mime.text Import MimeText 

DEF mail (Sub, CONT): 
    SENDER = ' xxxx qq.com @ '    # sender mailbox 
    passwd = " xxxx " #-mail sender authorization code 
    Receivers = ' [email protected] ' # recipient mailboxes 

    Subject = Sub # topic 
    Content = CONT # text 

    msg= MIMEText(content,'plain','utf-8')
    msg['Subject'] = subject
    msg['From'] = sender
    msg['TO'] = receivers
    try:
        s = smtplib.SMTP_SSL('smtp.qq.com',465)
        s.login(sender,passwd)
        s.sendmail(sender,receivers,msg.as_string())
        print('发送成功')
    Exception the except: 
        Print ( ' transmission failure ' )
 IF the __name__ == ' __main__ ' : 
    mail (Subject, Content)

query_win.py # Query whether winning

# -*- coding:utf-8 -*-
# Author: 
# @Time: 2019-08-05 10:08
import os
import sys
import caipiao
import send_mail
def win_rules(num_list,last_results):
    my_blue =  num_list[0:5]
    my_red = num_list[5:]
    result_blue = last_results[0:5]
    result_red = last_results[5:]
    same_blue = [l for l in my_blue IF L in result_blue] 
    same_red   = [L for L in my_red IF L in result_red] 
    same_num_blue = len (same_blue) 
    same_num_red = len (same_red) 
    Subject = " Lotto jackpot query " 
    Content = " not winning " 
    
    # 9, etc. Awards 
    IF same_num_blue == 5 and same_num_red == 2 : 
        Print ( " \ 033 [1; 31; 0m that you have in the first prize, the winning number is% s \ 033 [0m" % Num_list) 
        Content = " You have the first prize, the winning number is " + str (num_list) 
    elif same_num_blue == 5 and same_num_red == 1 : 
        Print ( " \ 033 [1; 35; 0m that you have in the second prize, the winning numbers for the S% \ 033 [0m " % num_list) 

        Content = " you have the second prize, the winning number is " + str (num_list) 
    elif same_num_blue == 5 : 
        Print ( " \ 033 [1 ; 33; 0m you have in a prize, the winning numbers for S% \ 033 [0m " %  num_list)
        Content =" You have in the third place, the winning number is " + STR (num_list) 
    elif same_num_blue == . 4 and same_num_red == 2 : 
        Print ( " \ 033 [. 1; 32; 0m you have in a four prize, the winning numbers is S% \ 033 [0m " % num_list) 
        Content = " you have in the four prize, the winning number is " + STR (num_list) 
    elif same_num_blue == . 4 and same_num_red == . 1 : 
        Print ( " \ 033 [. 1; 32; 0m that you have in the fifth prize, the winning numbers for the S% \ 033 [0m " % num_list) 
        Content = "You have the first prize, the winning number is " + str (num_list) 
    elif same_num_blue == 3 and same_num_red == 2 : 
         Print ( " \ 033 [1; 34; 0m that you have in the Liu Dengjiang, winning numbers S% \ 033 [0m " % num_list) 
         Content = " you have in the Liu Dengjiang, the winning number is " + STR (num_list) 
    elif same_num_blue == . 4 : 
        Print ( " \ 033 [. 1; 34 is; you're in 0m seven other awards, winning numbers for the S% \ 033 [0m " % num_list) 
        Content = " you have in the seven prize, the winning number is "+ ):str (num_list) 
    elif (same_num_blue == 2 and same_num_red == 2 ) or (same_num_blue == 3 and same_num_red == 1 ): 
        Print ( " \ 033 [1; 34; 0m that you have in eight other awards, winning numbers S is% \ 033 [0m " % num_list) 
        Content = " you have the eight prize, the winning number is " + str (num_list) 
    elif (same_num_blue == 1 and same_num_red == 2 ) or (same_num_red == 2 ) or (same_num_blue == 2 and same_num_red == . 1
        Print ( " \ 033 [1; 36; 0m You have the nine prize, the winning number is% S \ 033 [0m " % num_list) 
        Content = " You have the nine prize, the winning number is " + str ( num_list)
     the else : 
        Print ( " Sorry, you did not win !!! " ) 
        Content = " not winning " + " The winning numbers for the " + str (last_results) 
    send_mail.mail (Subject, Content) 

IF __name__ == ' __main__ ' : 
    caipiao.get_winnum () 
    datepathDatapath the sys.path = = [ 0 ]
    fname = " lot_500_dlt.txt " 
    fmy_num = " my_num.txt " 
    with Open (Datapath + ' / ' + fname, ' R & lt ' ) AS F: 
        Lines = f.readlines () # read All lines 
        last_line = lines [- 1 ] .strip ( ' \ the n- ' ) 
    # get the latest lottery numbers 
    last_results = last_line.split ( " , " ) [ 1 :]
    # Query whether winning, get their number 
    with Open (Datapath + ' / ' + fmy_num, ' r ' ) AS f: 
        Lines = f.readlines ()
         for i in Lines: 
            i = i.strip ( ' \ the n- ' ) 
            NUM = i.split ( ' , ' ) 
            win_rules (NUM, last_results)

 

Set at scheduled time

30 21 * * 6 /usr/bin/python  /home/xmc/appl/caipiao/query_win.py  >  /dev/null 2>&1 &

Description:

  my_num.txt buy their own lottery numbers stored position, attention must be two-digit numbers, and separated by commas, each set in one row

11,16,20,27,34,03,09
06,14,18,22,23,10,12
09,14,18,33,34,03,12

 reference

https://www.jianshu.com/p/a3ddf9333b3f

https://www.cnblogs.com/lizhe860/p/9079234.html

  

 

Guess you like

Origin www.cnblogs.com/xmc2017/p/11303586.html