python test

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/fengqinyun168/article/details/84801952

#!/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)

展开阅读全文

TEST

06-08

#include rn#include rn#pragma pack(2)rnrn/*定义WORD为两个字节的类型*/rntypedef unsigned short WORD;rn/*定义DWORD为e四个字节的类型*/rntypedef unsigned long DWORD;rnrn/*位图文件头*/rntypedef struct BMP_FILE_HEADERrnrn WORD bType; /* 文件标识符 */rn DWORD bSize; /* 文件的大小 */rn WORD bReserved1; /* 保留值,必须设置为0 */ rn WORD bReserved2; /* 保留值,必须设置为0 */rn DWORD bOffset; /* 文件头的最后到图像数据位开始的偏移量 */rn BMPFILEHEADER;rnrn/*位图信息头*/rntypedef struct BMP_INFOrnrn DWORD bInfoSize; /* 信息头的大小 */rn DWORD bWidth; /* 图像的宽度 */rn DWORD bHeight; /* 图像的高度 */rn WORD bPlanes; /* 图像的位面数 */rn WORD bBitCount; /* 每个像素的位数 */rn DWORD bCompression; /* 压缩类型 */rn DWORD bmpImageSize; /* 图像的大小,以字节为单位 */rn DWORD bXPelsPerMeter; /* 水平分辨率 */rn DWORD bYPelsPerMeter; /* 垂直分辨率 */rn DWORD bClrUsed; /* 使用的色彩数 */rn DWORD bClrImportant; /* 重要的颜色数 */rn BMPINF;rnrn/*彩色表*/rntypedef struct RGB_QUAD rnrn WORD rgbBlue; /* 蓝色强度 */rn WORD rgbGreen; /* 绿色强度 */rn WORD rgbRed; /* 红色强度 */rn WORD rgbReversed; /* 保留值 */rn RGBQUAD;rnrnint main()rnrn long i=0;rn WORD array[1024]=0xff;rn FILE *fp;rn BMPFILEHEADER fileHeader;rn BMPINF infoHeader;rn long offset, bmpImageSize, width, height, bytesPerPixel, size, bitCount;rn WORD c;rn rn if((fp = fopen("image1.bmp", "rb")) == NULL)rn rn printf("Cann't open the file!\n");rn exit(0);rn rnrn fseek(fp, 0, 0);rn fread(&fileHeader, sizeof(fileHeader), 1, fp);rn fread(&infoHeader, sizeof(infoHeader), 1, fp);rnrn //计算并输出位图数据的偏移量,图像的大小,宽度和高度,每个像素点所占的字节rn size = fileHeader.bSize;rn offset = fileHeader.bOffset;rn bmpImageSize = infoHeader.bmpImageSize;rn width = infoHeader.bWidth;rn height = infoHeader.bHeight;rn bitCount = infoHeader.bBitCount;rn bytesPerPixel = infoHeader.bBitCount / 8;rn rn printf("%d %d %d %d %d %d\n", size, offset, bmpImageSize, width, height, bitCount, bytesPerPixel);rnrn //输出每个像素点所占字节中的内容rn c = fgetc(fp);rn while (!feof(fp))rn rn i++;rn if(i>8)rn array[i-9]=c;rn rn printf("%x ", c);rn c = fgetc(fp);rn rn printf("\n");rn fclose(fp);rn if((fp=fopen("dio.txt","wb"))==NULL)rn printf("Cann't open the file!\n");rn exit(0);rn rn i=0;rn while(i!=1024)rn fprintf(fp,"0x%X,",array[i]);rn i++;rn rn fclose(fp);rn return 0;rn 论坛

没有更多推荐了,返回首页