首页 > 代码库 > 双色球小助手

双色球小助手

500w.py

from pyCyp import *
from tkinter import *
from tkinter import ttk
#from tkinter import messagebox
import itertools

urlNewqi = http://kaijiang.500.com/
newqi = getNewqi(urlNewqi)
url = http://datachart.500.com/ssq/history/newinc/history.php?start=1&end=+str(newqi)
allDatalist = urlTolist(url)#获取历史数据列表


win = Tk()
win.title(中国福利彩票--双色球小助手)
win.geometry(620x520+400+200)
win.resizable(width=False,height=False)
#最近开奖信息开始--------------------------------------------------------------------------------
v = StringVar()
Label(win,textvariable=v,font=none,30,relief=GROOVE).grid(row=0,column=0,padx=10,pady=10)
v.set(开奖信息→)
h1 = StringVar()
Label(win,textvariable=h1,font=none,30,fg=red,relief=RIDGE).grid(row=0,column=1,padx=10,pady=10)
h1.set(allDatalist[0][5:7])
h2 = StringVar()
Label(win,textvariable=h2,font=none,30,fg=red,relief=RIDGE).grid(row=0,column=2,padx=10,pady=10)
h2.set(allDatalist[0][7:9])
h3 = StringVar()
Label(win,textvariable=h3,font=none,30,fg=red,relief=RIDGE).grid(row=0,column=3,padx=10,pady=10)
h3.set(allDatalist[0][9:11])
h4 = StringVar()
Label(win,textvariable=h4,font=none,30,fg=red,relief=RIDGE).grid(row=0,column=4,padx=10,pady=10)
h4.set(allDatalist[0][11:13])
h5 = StringVar()
Label(win,textvariable=h5,font=none,30,fg=red,relief=RIDGE).grid(row=0,column=5,padx=10,pady=10)
h5.set(allDatalist[0][13:15])
h6 = StringVar()
Label(win,textvariable=h6,font=none,30,fg=red,relief=RIDGE).grid(row=0,column=6,padx=10,pady=10)
h6.set(allDatalist[0][15:17])
lan = StringVar()
Label(win,textvariable=lan,font=none,30,fg=blue,relief=RIDGE).grid(row=0,column=7,padx=10,pady=10)
lan.set(allDatalist[0][17:19])
qi = StringVar(win,allDatalist[0][:5])
cha = ttk.Combobox(win,textvariable=qi,values=[allDatalist[0][:5],allDatalist[1][:5],allDatalist[2][:5],allDatalist[3][:5],                                               allDatalist[4][:5],allDatalist[5][:5],allDatalist[6][:5],allDatalist[7][:5],                                               allDatalist[8][:5],allDatalist[9][:5],allDatalist[10][:5],allDatalist[11][:5]],
                   state=readonly,width=8).grid(row=0,column=8)
#最近开奖信息结束--------------------------------------------------------------------------------

#机选结果开始------------------------------------------------------------------------------------
hj1 = StringVar()
Label(win,textvariable=hj1,font=none,30,fg=red,relief=RIDGE).grid(row=1,column=1,padx=10,pady=10)
hj1.set(allDatalist[0][5:7])
hj2 = StringVar()
Label(win,textvariable=hj2,font=none,30,fg=red,relief=RIDGE).grid(row=1,column=2,padx=10,pady=10)
hj2.set(allDatalist[0][7:9])
hj3 = StringVar()
Label(win,textvariable=hj3,font=none,30,fg=red,relief=RIDGE).grid(row=1,column=3,padx=10,pady=10)
hj3.set(allDatalist[0][9:11])
hj4 = StringVar()
Label(win,textvariable=hj4,font=none,30,fg=red,relief=RIDGE).grid(row=1,column=4,padx=10,pady=10)
hj4.set(allDatalist[0][11:13])
hj5 = StringVar()
Label(win,textvariable=hj5,font=none,30,fg=red,relief=RIDGE).grid(row=1,column=5,padx=10,pady=10)
hj5.set(allDatalist[0][13:15])
hj6 = StringVar()
Label(win,textvariable=hj6,font=none,30,fg=red,relief=RIDGE).grid(row=1,column=6,padx=10,pady=10)
hj6.set(allDatalist[0][15:17])
lanj = StringVar()
Label(win,textvariable=lanj,font=none,30,fg=blue,relief=RIDGE).grid(row=1,column=7,padx=10,pady=10)
lanj.set(allDatalist[0][17:19])

#机选结果结束------------------------------------------------------------------------------------
#列表部分开始------------------------------------------------------------------------------------

group3 = LabelFrame(win,text=数据统计列表,font=(None ,10),padx=5,pady=5)
group3.grid(row=3,column = 0,columnspan=10,padx=10,pady=1)

tree = ttk.Treeview(group3,show=headings,columns=(tongji,h1,h2,h3,h4,h5,h6,lan))
tree.column(tongji,width=70,anchor=center)
tree.heading(tongji,text=统计)
tree.column(h1,width=70,anchor=center)
tree.heading(h1,text=红球一号)
tree.column(h2,width=70,anchor=center)
tree.heading(h2,text=红球二号)
tree.column(h3,width=70,anchor=center)
tree.heading(h3,text=红球三号)
tree.column(h4,width=70,anchor=center)
tree.heading(h4,text=红球四号)
tree.column(h5,width=70,anchor=center)
tree.heading(h5,text=红球五号)
tree.column(h6,width=70,anchor=center)
tree.heading(h6,text=红球六号)
tree.column(lan,width=70,anchor=center)
tree.heading(lan,text=蓝球号码)



#加滚动条
vbar = Scrollbar(group3, orient=VERTICAL)
vbar.config(command = tree.yview)
tree.configure(yscrollcommand=vbar.set)
tree.grid(row=3)
vbar.grid(row=3, column=1,sticky=NS)

tree.grid()


#列表部分开始------------------------------------------------------------------------------------

#统计分析开始--------------------------------------------------------------------------
group = LabelFrame(win,text=统计分析,结果将会在下面列表中显示,font=(None ,10),padx=5,pady=5)
group.grid(row=2,column = 0,columnspan=10,padx=10,pady=3)

#清除列表中的内容
def deltree():
    items = tree.get_children()
    for item in items:
        tree.delete(item)
#查询彩票历史数据
def cha(a):
    deltree()
    k = 0
    for i in allDatalist:
        tree.insert(‘‘,k,values=(i[0:5],i[5:7],i[7:9],i[9:11],i[11:13],i[13:15],i[15:17],i[17:19]))
        k+=1
        if k == a:
            break
cha(30)
#奇偶分析
def jioufenxi():
    ji=[]
    ou=[]
    for i in range(1,8):
        jishu = jiou(allDatalist,i,1)
        ji.append(jishu)
    for i in range(1,8):
        oushu = jiou(allDatalist,i,0)
        ou.append(oushu)
    deltree()
    tree.insert(‘‘,0,values=(奇数,ji[0],ji[1],ji[2],ji[3],ji[4],ji[5],ji[6]))
    tree.insert(‘‘,1,values=(偶数,ou[0],ou[1],ou[2],ou[3],ou[4],ou[5],ou[6]))    

#大小分析
def daxiaofenxi():
    da=[]
    xiao=[]
    for i in range(1,8):
        dashu = daxiao(allDatalist,i,1)
        da.append(dashu)
    for i in range(1,8):
        xiaoshu = daxiao(allDatalist,i,0)
        xiao.append(xiaoshu)
    #print(xiao)
    
    deltree()
    tree.insert(‘‘,0,values=(大于8,da[0],da[1],da[2],da[3],da[4],da[5],da[6]))
    tree.insert(‘‘,1,values=(小于9,xiao[0],xiao[1],xiao[2],xiao[3],xiao[4],xiao[5],xiao[6]))   
#次数分析
def cishufenxi():
    deltree()
    ciList = []
    k = 0
    H = [01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33]
    for s in range(1,8):
        t = geRelist(allDatalist,s)
        ciList.append(t)
    for j in H:
        tree.insert(‘‘,k,values=(j+出现次数,sumChu(ciList[0],j),sumChu(ciList[1],j),sumChu(ciList[2],j),                                 sumChu(ciList[3],j),sumChu(ciList[4],j),sumChu(ciList[5],j),sumChu(ciList[6],j)))
        k+=1
#和值分析
def hezhifenxi():
    deltree()
    k = 0
    for i in allDatalist:
        m = int(i[5:7])+int(i[7:9])+int(i[9:11])+int(i[11:13])+int(i[13:15])+int(i[15:17])+int(i[17:19])
        tree.insert(‘‘,k,values=(和=+str(m),i[5:7],i[7:9],i[9:11],i[11:13],i[13:15],i[15:17],i[17:19]))
        k+=1



Button(group,text=最近30期,width = 12,command=lambda:cha(30)).grid(row=0,column=0,padx=10,pady=5)
Button(group,text=最近50期,width = 12,command=lambda:cha(50)).grid(row=0,column=1,padx=10,pady=5)
Button(group,text=最近100期,width = 12,command=lambda:cha(100)).grid(row=0,column=2,padx=10,pady=5)
Button(group,text=最近500期,width = 12,command=lambda:cha(500)).grid(row=0,column=3,padx=10,pady=5)
Button(group,text=所有历史数据,width = 14,command=lambda:cha(len(allDatalist))).grid(row=0,column=4,padx=10,pady=5)
Button(group,text=奇偶分析,width = 12,command=jioufenxi).grid(row=1,column=0,padx=10,pady=5)
Button(group,text=大小分析,width = 12,command=daxiaofenxi).grid(row=1,column=1,padx=10,pady=5)
Button(group,text=次数分析,width = 12,command=cishufenxi).grid(row=1,column=2,padx=10,pady=5)
Button(group,text=和值分析,width = 12,command=hezhifenxi).grid(row=1,column=3,padx=10,pady=5)
zhi = StringVar(win,蓝色球)
cihong = ttk.Combobox(group,textvariable=zhi,values=[红一球,红二球,红三球,红四球,红五球,红六球,蓝色球],
                   state=readonly,width=10).grid(row=2,column=0)
#Button(group,text=‘次期分析‘,width = 14,command=ciqifenxi).grid(row=1,column=4,padx=10,pady=5)
hao = StringVar(win,01)
cihao = ttk.Combobox(group,textvariable=hao,values=[01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33],
                   state=readonly,width=10).grid(row=2,column=1)


#次期分析
def ciqifenxi():
    a = zhi.get()
    d = {红一球:0,红二球:1,红三球:2,红四球:3,红五球:4,红六球:5,蓝色球:6}
    b = hao.get()
    #print(d[a])
    deltree()
    cilist = []#每一个球组成一个列表,一共七个元素
    for s in range(1,8):
        t = geRelist(allDatalist,s)
        cilist.append(t)   
    t = reNext(cilist[d[a]],b)
    k = 0
    H = [01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33]
    for j in H:
        h = sumChu(t,j)
        tree.insert(‘‘,k,values=(b+出现后,下期+j+出现,str(h)+))
        k+=1
#复式选号
def fushi():
    deltree()
    v = fushixuanhao()
    for i in range(len(v)):
        tree.insert(‘‘,i,values=(+str(i+1)+,v[i][0],v[i][1],v[i][2],v[i][3],v[i][4],v[i][5],v[i][6]))
        
Button(group,text=复式选号,width = 14,command=fushi).grid(row=1,column=4,padx=10,pady=5)
Button(group,text=点击统计分析出下一次出现数字的概率,width = 30,command=ciqifenxi).grid(row=2,column=3,columnspan=3,padx=10,pady=8)
#统计分析结束--------------------------------------------------------------------------




def diJichaxun():
    for i in allDatalist:
        if i[:5]==qi.get():
            h1.set(i[5:7])
            h2.set(i[7:9])
            h3.set(i[9:11])
            h4.set(i[11:13])
            h5.set(i[13:15])
            h6.set(i[15:17])
            lan.set(i[17:19])
def jiXuan():
    L = reJixuan()
    hj1.set(L[0])
    hj2.set(L[1])
    hj3.set(L[2])
    hj4.set(L[3])
    hj5.set(L[4])
    hj6.set(L[5])
    lanj.set(L[6][0])
jiXuan()
#推荐号码
def tuijian(a):
    L = tuijianhao(a)
    hj1.set(L[0])
    hj2.set(L[1])
    hj3.set(L[2])
    hj4.set(L[3])
    hj5.set(L[4])
    hj6.set(L[5])
    lanj.set(L[6])




Button(win,text=点击查询,width = 10,command = diJichaxun).grid(row=0,column=9,padx=10,pady=10)
Button(win,text=热号推荐,width = 10,command = lambda:tuijian(0)).grid(row=1,column=8,padx=10,pady=10)
Button(win,text=顺号推荐,width = 10,command = lambda:tuijian(1)).grid(row=1,column=9,padx=10,pady=10)
Button(win,text=机选号码,width = 13,command = jiXuan).grid(row=1,column=0,padx=10,pady=10)





mainloop()

pyCyp.py

import urllib.request
import re
import itertools
import random

#获取500W彩票网站从2003至今的所有双色球数据,返回一个列表
def urlTolist(url):
    html = urllib.request.urlopen(url).read()
    html = html.decode(utf-8)
    s1 = r\d{5}</td><td class="t_cfont2">\d\d</td><td class="t_cfont2">\d\d</td><td class="t_cfont2">\d\d</td><td class="t_cfont2">\d\d</td><td class="t_cfont2">\d\d</td><td class="t_cfont2">\d\d</td><td class="t_cfont4">\d\d</td><td
    s2 = r(.*?)</td><td class="t_cfont2">(.*?)</td><td class="t_cfont2">(.*?)</td><td class="t_cfont2">(.*?)</td><td class="t_cfont2">(.*?)</td><td class="t_cfont2">(.*?)</td><td class="t_cfont2">(.*?)</td><td class="t_cfont4">(.*?)</td><td
    pat1 = re.compile(s1)

    t1 = pat1.findall(html)
    allDatalist = []
    str1 = ‘‘
    for i in t1:
        pat2 = re.compile(s2)
        t2 = pat2.findall(i)
        s = ‘‘.join(itertools.chain(*t2))  
        allDatalist.append(s)
    return allDatalist

#获取双色球最近一期的期数
def getNewqi(url):
    html = urllib.request.urlopen(url).read()
    html = html.decode(gbk)
    s1 = r<a target="_blank" href="http://www.mamicode.com/shtml/ssq/(.*?).shtml">
    pat = re.compile(s1)
    t1 = pat.findall(html)
    return t1[0]

#机选号码,返回一个字符串
def reJixuan():
    reList=[]
    H = [01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,         17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33]
    L = [01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16]
    hong = random.sample(H,6)
    lan = random.sample(L,1)
    hong.sort()
    reList=hong
    reList.append(lan)
    return reList


#求奇偶参数一:数据列表;参数二:号码位置;参数三:1为求奇数和 0为求偶数和
def jiou(L,g,t):
    x = g*2+3
    y = x + 2
    j = 0
    o = 0
    for i in L:
        if int(i[x:y])%2!=0:
            j+=1
        else:
            o+=1
    if t:
        return j
    else:
        return o
#求大小参数一:数据列表;参数二:号码位置;参数三:1为大数和 0为小数和
def daxiao(L,g,t):
    x = g*2+3
    y = x + 2
    da = 0
    xiao = 0
    for i in L:
        if int(i[x:y]) > 8:
            da+=1
        else:
            xiao+=1
    if t:
        return da
    else:
        return xiao

            
#把各个位上的数,返回一个列表
def geRelist(L,g):
    reList = []
    x = g*2+3
    y = x + 2
    for i in L:
        reList.append(i[x:y])
    return reList

#某个字符在列表中出现的次数
def sumChu(L,a):
    s = 0
    for i in L:
        if i==a:
            s+=1
    return s

#根据上期出现的结果把下期出现的数放入列表
#参数L是同一个位置上的号组成的列表 a为本次出现的数
def reNext(L,a):
    reList = []
    t = 1
    for i in L:
        if t >= len(L):
            break
        if i==a:
            reList.append(L[t])
        
        t+=1
    return reList

#复式选号
def fushixuanhao():
    urlNewqi = http://kaijiang.500.com/
    newqi = getNewqi(urlNewqi)
    url = http://datachart.500.com/ssq/history/newinc/history.php?start=1&end=+str(newqi)
    allDatalist=urlTolist(url)
    H = [01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33]
    #deltree()
    dou = [0,0,0,0,0,0,0]#每个位上出现最多的号
    ndou = [0,0,0,0,0,0,0]#每个位下一次出现最多的号
    lan = []
    hong = []
    #m = 0     #次数
    cilist = []#每一个球组成一个列表,一共七个元素
    for s in range(1,8):
        m = 0
        m2 = 0
        g = geRelist(allDatalist,s)#g为红1的列表
        
        for i in H:
            t = sumChu(g,i)
            if t > m:
                m = t
                dou[s-1]=i
        n = reNext(g,dou[s-1])
        for i in H:
            t2 = sumChu(n,i)
            if t2 > m2:
                m2 = t2
                ndou[s-1]=i
    lan.append(dou[6])
    lan.append(ndou[6])
    hong = dou[:6]+ndou[:6]
    hong = list(set(hong))
    hong.sort()
##    a = [1,2,4,5,6,7,8,9,10]
##    b = [11,12]
    v = []
    t = list(itertools.combinations(hong,6))

    for i in t:
        i = list(i)
        for j in lan:
            i.append(j)
            v.append(i)
            i=i[:6]

##    for i in v:
##        print(i)
    
    return v

#推荐号码
def tuijianhao(a):
    urlNewqi = http://kaijiang.500.com/
    newqi = getNewqi(urlNewqi)
    url = http://datachart.500.com/ssq/history/newinc/history.php?start=1&end=+str(newqi)
    allDatalist=urlTolist(url)
    H = [01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33]
    #deltree()
    dou = [0,0,0,0,0,0,0]#每个位上出现最多的号
    ndou = [0,0,0,0,0,0,0]#每个位下一次出现最多的号
    lan = []
    hong = []
    #m = 0     #次数
    cilist = []#每一个球组成一个列表,一共七个元素
    for s in range(1,8):
        m = 0
        m2 = 0
        g = geRelist(allDatalist,s)#g为红1的列表
        
        for i in H:
            t = sumChu(g,i)
            if t > m:
                m = t
                dou[s-1]=i
        n = reNext(g,dou[s-1])
        for i in H:
            t2 = sumChu(n,i)
            if t2 > m2:
                m2 = t2
                ndou[s-1]=i

    if a==0:
        return dou
    else:
        return ndou

        

 

双色球小助手