#!/usr/bin/env python
##encoding=utf-8
import MySQLdb
from MySQLdb.constants import FIELD_TYPE
import time,datetime
from xml.dom.minidom import Document
import hashlib
import json
import sys
import urllib
import urllib2
reload(sys)
sys.setdefaultencoding('utf8')
merchant_code=10027
typelist=[80,81,82,83,84,85]
count=1
key="1234567890ABCDEF"
orderlist=[]
lotterydict={80:'601',81:'601',82:'601',83:'601',84:'601',85:'601'}
weekdict={0:1,1:2,2:3,3:4,4:5,5:6,6:7}
tencentplay={80:'60105',81:'60103',82:'60102',83:'60104',84:'60101',85:'60109'}
bifendict={"1":"1:0","2":"2:0","3":"2:1","4":"3:0","5":"3:1","6":"3:2","7":"4:0","8":"4:1","9":"4:2","10":"5:0","11":"5:1","12":"5:2","13":"9:0","14":"0:0","15":"1:1","16":"2:2","17":"3:3","18":"9:9","19":"0:1","20":"0:2","21":"1:2","22":"0:3","23":"1:3","24":"2:3","25":"0:4","26":"1:4","27":"2:4","28":"0:5","29":"1:5","30":"2:5","31":"0:9"}
#bifendict={'1':'1:0','2':'2:0','3':'2:1','4','3:0','5':'3:1','6':'3:2','7':'4:0','8':'4:1','9':'4:2','10':'5:0','11':'5:1','12':'5:2','13':'9:0','14':'0:0','15':'1:1','16':'2:2','17':'3:3','18':'9:9','19':'0:1','20':'0:2','21':'1:2','22':'0:3','23':'1:3','24':'2:3','25':'0:4','26':'1:4','27':'2:4','28':'0:5','29':'1:5','30':'2:5','31':'0:9'}
bqcdict={'1':'3-3','2':'3-1','3':'3-0','4':'1-3','5':'1-1','6':'1-0','7':'0-3','8':'0-1','9':'0-0'}
jqsdict={'1':'0','2':'1','3':'2','4':'3','5':'4','6':'5','7':'6','8':'7'}
url='http://888.qq.com/tws/spnotice/DoTicketStatusNotice'
#url='http://118.26.65.147/test.php'
def md5(str):
m = hashlib.md5()
m.update(str)
return m.hexdigest()
def connect():
conn=MySQLdb.connect(host='172.16.3.10',user='lehecai',passwd='123456',db='v_ticket',port=1231)
conn.autocommit(1)
return conn
def gettencentvalue(lotterytype,value):
if lotterytype=='81':
return bifendict[value]
if lotterytype=='83':
return bqcdict[value]
if lotterytype=='82':
return jqsdict[value]
return value
def create_xml(lotterytype):
global count
#count=count+1
cmd='6103'
doc = Document()
bookstore = doc.createElement('message')
doc.appendChild(bookstore)
head=doc.createElement('head')
bookstore.appendChild(head)
command=doc.createElement('command')
command_text=doc.createTextNode(cmd)
command.appendChild(command_text)
head.appendChild(command)
agentid=doc.createElement('agentid')
agentid_text=doc.createTextNode(str(merchant_code))
agentid.appendChild(agentid_text)
head.appendChild(agentid)
messageid=doc.createElement('messageid')
messageid_text=doc.createTextNode(str(count))
messageid.appendChild(messageid_text)
head.appendChild(messageid)
timest=time.strftime('%Y-%m-%d %H:%M:%S')
timestamp=doc.createElement('timestamp')
timestamp_text=doc.createTextNode(timest)
timestamp.appendChild(timestamp_text)
head.appendChild(timestamp)
body=doc.createElement('body')
bookstore.appendChild(body)
lottype=doc.createElement('lottype')
lottype_text=doc.createTextNode(lotterydict[lotterytype])
lottype.appendChild(lottype_text)
body.appendChild(lottype)
datalist=doc.createElement('datalist')
body.appendChild(datalist)
conn=connect();
cursor = conn.cursor(MySQLdb.cursors.DictCursor)
sql="select * from lottery_order_notice where lottery_type =%s and merchant_code=%s and notice_status=2 limit 50"
param=(lotterytype,merchant_code)
n = cursor.execute(sql,param)
if (n==0):
cursor.close()
conn.close()
#print "%s is not have bet return"%lotterytype
return "No"
for row in cursor.fetchall():
orderid=row['id']
merchant_no=row['merchant_no']
status=row['order_status']
ordersql='select * from lottery_order where id=%s'
orderparam=(orderid,)
tor=cursor.execute(ordersql,orderparam)
order=cursor.fetchone()
if not order:
contine
dataitem=doc.createElement('dataitem')
datalist.appendChild(dataitem)
dataitem.setAttribute('ticketsn',order['merchant_no'])
dataitem.setAttribute('money',bytes(order['amount']))
dataitem.setAttribute('maxprizemoney','0')
dataitem.setAttribute('expand','')
orderlist.append(orderid)
if (status==3):
dataitem.setAttribute('status','200')
dataitem.setAttribute('message','成功')
ticketsql='select * from ticket where order_id =%s'
ticketparam=(orderid,)
tn=cursor.execute(ticketsql,ticketparam)
ticket=cursor.fetchone()
if not ticket:
contine
dataitem.setAttribute('playtype',tencentplay[ticket['lottery_type']])
dataitem.setAttribute('ticketcode',ticket['serial_id'])
ext=ticket['ext']
#print ext
dataitem.setAttribute('rateinfo',ext)
jsonstr=json.loads(ext)
peilv=''
rangqiu=''
lotteryType=ticket['lottery_type'];
for jsonkey in jsonstr.keys():
if jsonkey==jsonstr[jsonkey]['match_num']:
subtimestr=jsonkey[:8]
changci=jsonkey[-3:]
a=time.strptime(subtimestr,'%Y%m%d');
weekday=weekdict[a.tm_wday]
substart=bytes(weekday)+changci
peilv=peilv+substart+'→'+'['
sp_map=jsonstr[jsonkey]['sp_map'];
for inkey in sp_map:
if inkey.find('$')>0 :
ticketType=inkey.split('$')[1]
if bytes(ticketType)=='80':
racesql='select * from jczq_race where match_num='+jsonkey
jco=cursor.execute(racesql)
jczqrace=cursor.fetchone()
#print jczqrace['handicap']
rangqiu='('+jczqrace['handicap']+')'
tkey=inkey.split('$')[0]
peilv +=gettencentvalue(bytes(ticketType),bytes(tkey))+'#'+sp_map[inkey]+','
else:
if bytes(lotteryType)=='80':
racesql='select * from jczq_race where match_num='+jsonkey
jco=cursor.execute(racesql)
jczqrace=cursor.fetchone()
#print jczqrace['handicap']
rangqiu='('+jczqrace['handicap']+')'
peilv=peilv+gettencentvalue(bytes(lotteryType),bytes(inkey))+'#'+sp_map[inkey]+','
peilv=peilv[0:len(peilv)-1]+']'+rangqiu.replace('+','')+'/'
sp=peilv[0:len(peilv)-1]
#print ext
newsp=bytes(sp).strip()
dataitem.setAttribute('rateinfo',newsp)
suc=datetime.datetime.strftime(ticket['print_time'], '%Y-%m-%d %H:%M:%S')
dataitem.setAttribute('suctime',suc)
else:
dataitem.setAttribute('status','-200')
dataitem.setAttribute('message','超时未出')
#bodystr=body.toprettyxml(indent = '')
bodystr=body.toxml()
#print bodystr
md5str=cmd+str(merchant_code)+str(count)+timest+key+bodystr
# print md5str
md5num=md5(md5str)
count=count+1
keycode=doc.createElement('key')
keycode_text=doc.createTextNode(md5num.lower())
keycode.appendChild(keycode_text)
head.appendChild(keycode)
noticexml=doc.toxml(encoding='utf-8')
print time.strftime('%Y-%m-%d %H:%M:%S')
parameters='msg='+noticexml
print parameters
#data=urllib.urlencode(parameters)
request=urllib2.Request(url=url,data=parameters)
response=urllib2.urlopen(request).read()
print response
if response.find('<status>200</status>')>0:
updatesql='update lottery_order_notice set notice_status=1 where id in %s'
updateparam=(orderlist,)
cursor.execute(updatesql,updateparam)
cursor.close()
conn.close()
return "" #noticexml
if __name__=='__main__':
while True :
for lottype in typelist:
s=create_xml(lottype)
#print s
# break
time.sleep(10)
分享到:
相关推荐
标题中的"Amber Python Test.zip"表明这是一个使用Python语言进行测试的项目,被压缩成一个ZIP文件以便存储和传输。ZIP是一种常见的文件归档格式,它允许用户将多个文件和目录打包成一个单一的文件,方便管理和分享...
标题 "E:\My Documents\Visual Studio Projects\PythonTest\PythonTest.rar" 提示我们这是一个位于特定路径下的RAR压缩文件,通常用于存储多个文件或文件夹以便于传输或归档。RAR是一种流行的压缩格式,由RarLab开发...
"pythontest"和"python"标签进一步强调了这个文件与Python编程的关联,可能表明这是一个学习、实践或者调试Python代码的场景。 在Python编程中,`test.py`这样的文件通常包含了单元测试,这是一种软件开发的最佳...
标题中的"pythontest.zip"表明这是一个包含Python相关测试内容的压缩文件。描述中同样提到"pythontest.zip",暗示这个压缩包可能包含了用于学习、实践或测试Python编程的各种资源。标签"python"进一步确认了这个...
python test ''' Created on 2011-11-2 @author: ACER ''' import glob, os from testframe.TestSuite import * class PyTestRunner: @staticmethod def run(suite): TestSuite.run(suite) @staticmethod ...
"PythonTest"可能是一个与Python相关的项目或者教程,旨在帮助用户学习和实践Python编程。 在Python编程中,有几个关键知识点是所有初学者都应该掌握的: 1. **基础语法**:Python的语法规则非常直观,如缩进替代...
//传递参数时,每个参数中间要有一个空格 //Python接收参数的方法: //从1开始接收参数 //args1= sys.argv[1] //args2=sys.argv[2] //args2=sys.argv[3]
pythontest_8.30.py
python自动生成Verilog的testbench脚本。python自动生成Verilog的testbench脚本。python自动生成Verilog的testbench脚本。
标题“pythonTest”和描述“pythonTest”都比较简单,没有提供具体的Python知识点。但从标签“Python”我们可以推测,这个压缩包可能包含一个Python项目或学习资源。文件名称“pythonTest-master”暗示这是一个Git...
该项目为Python语言编写的学习型项目源码,总计包含61个文件,涵盖47个Python脚本文件、6个文本文件、2个图标文件、2个Markdown文件、1个Git忽略文件、1个CSV文件、1个许可证文件及1个特定目录。项目内容旨在帮助...
python test5
资源分类:Python库 所属语言:Python 资源全名:test_tube-0.6.7.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
爬取网站图片下载到本地文件夹
### Python TestSuite生成测试报告过程解析 #### 一、引言 在软件开发过程中,单元测试是确保代码质量的重要手段之一。随着项目规模的增长,单个测试用例的数量越来越多,如何管理和展示这些测试用例的结果变得尤为...
"pythontest"这个标题可能指的是一个与Python相关的测试项目或者教程,而描述中的"pythontest"同样没有提供具体信息,可能是项目的名称或者是对内容的概括。标签"Python"则明确了讨论的主题。 在Python的世界里,...
资源分类:Python库 所属语言:Python 资源全名:testtools-0.9.23.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:test_model_hv-0.0.21.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059