抢场地

import requests
import json
import ddddocr
import random
import datedays

def get_yzm():
    url=' http://202.117.17.144:8080/web/login/yzm.html?'+str(random.random())
    headers = {
        'Accept': 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
        'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        'X-Requested-With': 'synjones.commerce.xjtu',
        'Connection': 'keep-alive',
        'Referer': 'http://202.117.17.144:8080/web/product/show.html?id=101',
        'User-Agent': 'Mozilla/5.0 (Linux; Android 12; 22041216C Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/105.0.5195.79 Mobile Safari/537.36 toon/2122313098 toonType/150 toonVersion/6.3.0 toongine/1.0.12 toongineBuild/12 platform/android language/zh skin/white fontIndex/0',
        'Cookie':cookie
        }
    responsepdf = requests.get(url,headers=headers)
    name='2'+".jfif"
    if responsepdf.status_code == 200:
        with open(name , "wb") as code:
            code.write(responsepdf.content)

def get_okarea():
    url='http://202.117.17.144:8080/web/product/findOkArea.html?s_date='+str(datedays.gettomorrow())+'&serviceid='+sport_id
    headers = {
        'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        'X-Requested-With': 'XMLHttpRequest',
        'Connection': 'keep-alive',
        'Referer': 'http://202.117.17.144:8080/web/product/show.html?id=102',
        'User-Agent': 'Mozilla/5.0 (Linux; Android 12; 22041216C Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/105.0.5195.79 Mobile Safari/537.36 toon/2122313098 toonType/150 toonVersion/6.3.0 toongine/1.0.12 toongineBuild/12 platform/android language/zh skin/white fontIndex/0',
        'Cookie':cookie
        }
    res_okarea= requests.get(url,headers=headers)
    return res_okarea.text
    
def list_print(ls,ncd):
    #这里分析场地有几个+1 设为ncd

    #这里分析场地时间段有几个 nsj
    k=1
    for i in ls:
        #判断 计数到第几个了,开始换行.
        if k%ncd==0:
            #换行
            print(i)
            k=k+1
        else:
            print(i,end="----")
            k=k+1

def xie_liebiao(res_okarea):
    list_a=list()
    global json_d
    json_d=json.loads(res_okarea)
    #存数据
    #创建列表
    for i in range(len(json_d['object'])):
        name=json_d['object'][i]['name']
        sname=json_d['object'][i]['sname']
        status=json_d['object'][i]['status']
        time_no=json_d['object'][i]['stock']['time_no']
        #为1时 可以选 为2时 已被选 0为预定
        stock=json_d['object'][i]['stock']['all_count']
        #写入时间段
        if i%stock==0:
            list_a.append(json_d['object'][i]['stock']['time_no'])
        if status==1:
            list_a.append(""+"("+str(i)+")"+sname)
        else:
            list_a.append("----"+"("+str(i)+")"+sname)
    list_print(list_a,stock+1)        

def post_order(stockid,id,yzm):
    url='http://202.117.17.144:8080/web/order/tobook.html'
    data='param={\'stockdetail\': {\''+stockid+'\':\''+id+'\'}, \'yzm\': \''+yzm+'\', \'venueReason\': \'\', \'fileUrl\': \'\', \'address\': \''+sport_id+'\'}&json=true'
    print(data)
    headers={
        'Accept': 'application/json, text/javascript, */*;q=0.01',
        'Accept-Encoding': 'gzip, deflate',
        'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7',
        'X-Requested-With': 'XMLHttpRequest',
        'Connection': 'keep-alive',
        'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
        'Referer': 'http://202.117.17.144:8080/web/product/show.html?id=102',
        'User-Agent': 'Mozilla/5.0 (Linux; Android 12; 22041216C Build/SP1A.210812.016; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/105.0.5195.79 Mobile Safari/537.36 toon/2122313098 toonType/150 toonVersion/6.3.0 toongine/1.0.12 toongineBuild/12 platform/android language/zh skin/white fontIndex/0',
        'Cookie':cookie
        }
    rep_order = requests.post(url=url, data=data, headers=headers)
    print(rep_order.text)





#输入cookie,选择体育项目,获取场地信息
json_d=''
#创新港一号巨构坡屋顶羽毛球场
sport_id='101'
cookie=input("请输入coockie值")
try:
   res_okarea=get_okarea()
   #print(res_okarea)
except Exception as e:
    print("函数okarea:",e)
#已经获得了场地信息,打印出来
xie_liebiao(res_okarea)
#输出数组形式
# 1 1 1
# 1 1 1   
xz=int(input("输入场地序号"))
stockid=str(json_d['object'][xz]['stockid'])
id=str(json_d['object'][xz]['id'])
get_yzm()
ocr = ddddocr.DdddOcr(beta=True)
with open('2.jfif', 'rb') as f:
    img_bytes = f.read()
    result = ocr.classification(img_bytes)
    yzm=result
print(stockid+'-----'+id+'-----'+yzm)
post_order(stockid,id,yzm)

 

posted @ 2022-10-17 20:35  安之立吖  阅读(81)  评论(0编辑  收藏  举报