当前位置 : IT培训网 > IT培训 > 交流分享 > 如何用Python实现定时自动挂号

如何用Python实现定时自动挂号

时间:2019-01-30 13:21:29  来源:编程网  作者:IT培训网  已有:名学员访问该课程
现在去医院排队挂号太耽误时间,自动挂号程序省了很多事,可以让人们通过Charles抓包分析了医院的App的请求,这里是分析**一附属医院的App,然后用Python写了个脚本去模拟登录医院的App,然后去挂号,究竟用python如何实现呢?

现在去医院排队挂号太耽误时间,自动挂号程序省了很多事,可以让人们通过Charles抓包分析了医院的App的请求,这里是分析**一附属医院的App,然后用Python写了个脚本去模拟登录医院的App,然后去挂号,究竟用python如何实现呢?

如何用Python实现定时自动挂号_www.itpxw.cn

如何用Python实现定时自动挂号?

import requests

import json

import time

import datetime

from dateutil.relativedelta import relativedelta

# 登录获取session_id

def login(username,password):

url = "https://zyyy.zwjk.com/api/exec.htm"

data = {"api_Channel":"1",

"client_version":"3.6.6",

"app_id":"zyyy_android",

"app_key":"xxxx",

"user_type":"0",

"client_mobile":"863008041030718",

"api_name":"api.user.user.login.info",

"params":{"phone":username, # 账号

"psw":password}, # 密码

}

headers = {

'Content-Type': "application/x-www-form-urlencoded",

'User-Agent': "health",

'Host': "zyyy.zwjk.com",

'Connection': "Keep-Alive",

'Accept': "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",

'cache-control': "no-cache",

}

response = requests_session.post( url, data={"requestData":json.dumps(data)}, headers=headers)

if response.status_code != 200:

return False

resp_json = response.json()

session_id = resp_json['return_params']['user_model']['session_id']

return session_id

# 获取挂号信息

def get_doctor_info(session_id,appointment_date):

url = "https://zyyy.zwjk.com/api/exec.htm"

payload = {"api_Channel":"1",

"client_version":"3.6.6",

"app_id":"zyyy_android",

"app_key":"xxxx",

"user_type":"0",

"client_mobile":"863008041030718",

"api_name":"api.yygh.expert.schedule.list",

"params":{"type_id":1,

"source_id":"12",

"dept_id":26,

"page_no":1,

"page_size":2147483647

},

"session_id":session_id}

headers = {

'Content-Type': "application/x-www-form-urlencoded",

'User-Agent': "health",

'Host': "zyyy.zwjk.com",

'Connection': "Keep-Alive",

'Accept': "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",

'cache-control': "no-cache",

}

response = requests_session.post(url, data={"requestData":json.dumps(payload)}, headers=headers)

if response.status_code != 200:

return False

resp_json = response.json()

return_params = resp_json['return_params']['list']

for key in return_params:

if int(key['date']) == int(appointment_date):

doctor_info = key['doctor']

for i in doctor_info:

if i['id'] == 1960 and i['schedulList'][0]['am_pm_flag'] == "1":

return True

def get_time(session_id):

pre_date = (time_now + datetime.timedelta(days=7)).strftime("%Y-%m-%d")

url = "https://zyyy.zwjk.com/api/exec.htm"

payload = {

"api_Channel": "1",

"client_version": "3.6.6",

"app_id": "zyyy_android",

"app_key": "xxxx",

"user_type": "0",

"client_mobile": "863008041030718",

"api_name": "api.yygh.remain.num",

"params": {

"sourceId": "12",

"planId": 9759,

"orderDate": str(pre_date),

"ampmFlag": "1"

},

"session_id": session_id

}

headers = {

'Content-Type': "application/x-www-form-urlencoded",

'User-Agent': "health",

'Host': "zyyy.zwjk.com",

'Connection': "Keep-Alive",

'Accept': "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",

'cache-control': "no-cache",

}

response = requests_session.post(url, data={"requestData": json.dumps(payload)}, headers=headers)

if response.status_code != 200:

return False

resp_json = response.json()

regno = resp_json['return_params']['list'][0]['regno']

timespan = resp_json['return_params']['list'][0]['timespan']

return [regno,timespan]

# 在指定时间挂号

def set_doctor_number(session_id,pre_date,reg_no,timeregion):

url = "https://zyyy.zwjk.com/api/exec.htm"

payload = {

"api_Channel": "1",

"client_version": "3.6.6",

"app_id": "zyyy_android",

"app_key": "Zxxxx",

"user_type": "0",

"client_mobile": "863008041030718",

"api_name": "api.yygh.expert.reservation",

"params": {

"card_no": "x'x'x'x", # 社保卡号

"doct_name": "华佗", # 专家名称

"user_name": "xxx", # 你的姓名

"id_card": "xxxxx", # 身份证号

"phone": "xxxx", # 电话

"reg_id": "xxxx",

"reg_no": reg_no, # 预约号

"dept_name": "科室",

"yuanqu_type": "1",

"type": "1",

"dept_id": 103060302,

"pre_date": str(pre_date), #预约日期

"week_day": "3", # 预约日期是星期几

"plan_id": 9759,

"fee": "14",

"pre_time_type": "1",

"doct_id": "1960",

"clinic_fee": "",

"clinic_time":timeregion

},

"session_id": str(session_id)

}

headers = {

'Content-Type': "application/x-www-form-urlencoded",

'User-Agent': "health",

'Host': "zyyy.zwjk.com",

'Connection': "Keep-Alive",

'Accept': "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5",

'cache-control': "no-cache",

}

response = requests_session.post(url, data={"requestData": json.dumps(payload)}, headers=headers)

if response.status_code != 200:

return False

resp_json = response.json()

ret_info = resp_json['return_params']['ret_info']

send_message_wchat("浙一预约挂号结果",ret_info)

# 发送消息到微信

def send_message_wchat(title, content):

loging_datetime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

url = "https://sc.ftqq.com/SCU9051Tc94a746xxxf1d559xxx5a545ff.send"

querystring = {"text": title, "desp": str(loging_datetime) + str(content)}

response = requests.request("GET", url, params=querystring)

if response != 200:

return

return True

if __name__ == '__main__':

requests_session = requests.Session()

time_now = datetime.datetime.now()

pre_date = (time_now+datetime.timedelta(days=7)).strftime("%Y%m%d")

session_id = login('xxxx','xxxxxx')

if get_doctor_info(session_id,pre_date):

regno = get_time(session_id)[0]

timespan = get_time(session_id)[1]

set_doctor_number(session_id,pre_date,regno,timespan)

else:

send_message_wchat("浙一预约挂号结果","获取列表失败,可能原因:医生不在预约列表中或者医生门诊不在上午")

然后写个计划任务每个月的第一个周三去执行脚本:

0 15 1-7 * * if [ `date '+%w'` = "3" ]; then /usr/bin/python3 /opt/hospital/zheyi.py;fi

顶一下
(2)
100%
踩一下
(0)
0%

IT培训0元试听 每期开班座位有限.0元试听抢座开始! IT培训0元试听

  • 姓名 : *
  • 电话 : *
  • QQ : *
  • 留言 :
  • 验证码 : 看不清?点击更换请输入正确的验证码

在线咨询在线咨询

温馨提示 : 请保持手机畅通,咨询老师为您
提供专属一对一报名服务。

------分隔线----------------------------
------分隔线----------------------------

推荐内容

相关热点