Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #50 #49 #52

Merged
merged 3 commits into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
'days': ['am','pm'],
'unit_name': '',
'dep_name': '',
'doctor_name': ''
'doctor_name': '',
'user_key': ''
}

print("您的useragent临时文件夹为,有需要请复制它:%s" % tempfile.gettempdir())
Expand Down Expand Up @@ -252,15 +253,11 @@ def brush_ticket(unit_id, dep_id, weeks, days) -> list:
return [element for element in result if element["y_state"] == "1"]


def brush_ticket_new(doc_id, dep_id, weeks, days) -> list:
def brush_ticket_new(user_key, unit_id, doc_id, dep_id, weeks, days) -> list:
now_date = datetime.date.today().strftime("%Y-%m-%d")
url = "https://www.91160.com/doctors/ajaxgetclass.html"
data = {
"docid": doc_id,
"date": now_date,
"days": 6
}
r = session.post(url, headers=get_headers(), data=data)
url = "https://gate.91160.com/guahao/v1/pc/sch/doctor?user_key={}&docid={}&doc_id={}&unit_id={}&dep_id={}&date={}&days=6".format(
user_key, doc_id, doc_id, unit_id, dep_id, now_date)
r = session.get(url, headers=get_headers())
json_obj = r.json()

if "dates" not in json_obj:
Expand Down Expand Up @@ -311,10 +308,10 @@ def get_ticket(ticket, unit_id, dep_id):
data = {
"sch_data": soup.find(attrs={"name": "sch_data"}).attrs["value"],
"mid": soup.find(attrs={"name": "mid"}).attrs["value"],
"hisMemId": "",
"addressId": "3317",
"address": "China",
"disease_input": "",
"order_no": "",
"disease_content": "",
"accept": "1",
"unit_id": ticket["unit_id"],
"schedule_id": ticket["schedule_id"],
Expand All @@ -328,9 +325,6 @@ def get_ticket(ticket, unit_id, dep_id):
"detlid_realtime": soup.find("input", id="detlid_realtime").attrs["value"],
"level_code": ticket["level_code"],
"is_hot": "",
"addressId": "3317",
"address": "China",
"buyinsurance": 1
}
url = "https://www.91160.com/guahao/ysubmit.html"
logging.error("准备提交++++URL: {}".format(url))
Expand Down Expand Up @@ -442,6 +436,8 @@ def set_department_configs():
"keyValue": configs["unit_id"]
}
r = session.post(url, headers=get_headers(), data=data)
configs['user_key'] = session.cookies.get_dict()["access_hash"]

departments = r.json()
if configs['dep_id'] == "":
print("=====请选择科室=====\n")
Expand Down Expand Up @@ -471,10 +467,11 @@ def set_doctor_configs():
now_date = datetime.date.today().strftime("%Y-%m-%d")
unit_id = configs["unit_id"]
dep_id = configs["dep_id"]
url = "https://www.91160.com/dep/getschmast/uid-{}/depid-{}/date-{}/p-0.html".format(
unit_id, dep_id, now_date)
user_key = configs["user_key"]
url = "https://gate.91160.com/guahao/v1/pc/sch/dep?unit_id={}&dep_id={}" \
"&date={}&p=0&user_key={}".format(unit_id, dep_id, now_date, user_key)
r = session.get(url, headers=get_headers())
doctors = r.json()["doc"]
doctors = r.json()["data"]["doc"]
doc_id_arr = []
doc_name = {}
if configs["doc_id"] == "":
Expand Down Expand Up @@ -559,6 +556,7 @@ def run():
doc_id = configs["doc_id"]
weeks = configs["weeks"]
days = configs["days"]
user_key = configs["user_key"]
# 刷票休眠时间,频率过高会导致刷票接口拒绝请求
sleep_time = 15

Expand All @@ -568,7 +566,7 @@ def run():
while True:
try:
# tickets = brush_ticket(unit_id, dep_id, weeks, days)
tickets = brush_ticket_new(doc_id, dep_id, weeks, days)
tickets = brush_ticket_new(user_key, unit_id, doc_id, dep_id, weeks, days)
except Exception as e:
logging.error(e)
break
Expand Down