欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 创投人物 > 医院预约挂号

医院预约挂号

2025/11/25 22:02:35 来源:https://blog.csdn.net/q2642346535/article/details/148800116  浏览:    关键词:医院预约挂号

医院预约挂号脚本

功能介绍

本脚本是一个用 Python 编写的医院预约挂号程序,支持以下功能:

  1. 自动预约:通过api交互选择医院、科室、医生和时间段。
  2. 自动监控:持续检查指定医生的号源状态,发现可预约时段时自动尝试预约。

在这里插入图片描述

核心代码解析

1. 主程序 (main.py)

# -*- coding: utf-8 -*-
import time
from schema import AddRegArgs, DeptSchForDocArgs, DocSchArgs, NumberSourceArgs
from api import Apidef appointment():"""预约程序入口,通过命令行交互完成挂号"""api = Api()hospitals = api.get_hospital()print("请选择院区,输入院区前方序号")for index, hospital in enumerate(hospitals):print("{}):{}".format(index, hospital["aliasName"]))hospital_index = int(input("请输入院区序号:"))hospital = hospitals[hospital_index]# 后续科室、医生、时间选择逻辑...# 完整代码见 a.txtdef monitor():"""每10秒检查一次号源状态,发现可预约时段时自动尝试预约"""while True:try:# 检查号源状态doc_schDate = api.get_doc_sch(args)if len(doc_schDate) > 0:# 尝试自动预约response = api.add_reg(args)if response["code"] == "0":print("预约成功!")except Exception as e:print(f"程序异常:{e}")time.sleep(10)if __name__ == "__main__":monitor()

2. 数据模型 (schema.py)

# -*- coding: utf-8 -*-
from pydantic import BaseModel
from typing import Unionclass HospitalArgs(BaseModel):sysCode: Union[str, int] = "1001035"class DeptListArgs(BaseModel):clinicalType: str = 1hosId: intsysCode: Union[str, int] = "1001035"class DeptSchForDocArgs(BaseModel):clinicalType: str = 1deptCode: str = NonedeptId: str = deptCodespecialtyId: str = NonedeptName: strvisitingArea: strhosId: intrecommendation: str = ""type: str = "order"source: int = 22sysCode: Union[str, int] = "1001035"def update(self):self.deptId = self.deptCodeclass DocSchArgs(BaseModel):deptId: strdeptName: strdocId: strdocName: strdocTitle: strdocPhoto: strhosId: inthosName: strtype: str = "order"visitingArea: str = ""clinicalType: str = 1source: int = 22sysCode: Union[str, int] = "1001035"class NumberSourceArgs(BaseModel):sysCode: Union[str, int] = "1001035"ampm: strcategor: strdocId: strdeptId: strhosId: Union[str, int]schDate: strschId: strclass AddRegArgs(BaseModel):# key不一致参数disNo: str = NoneschDate: str = NonepatienId: str = None# 必须参数clinicalType: str = 1visitingArea: str = ""ampm: strappointmentNumber: str = disNocategor: strcategorName: strdeptId: strdeptName: strdocId: strdocName: strendTime: str = ""extend: str = ""fee: strhosId: Union[str, int]hosName: strisFlexible: str = ""numId: str = ""patientId: str = patienIdresDate: str = schDateschId: strsource: int = 22startTime: str = ""sysCode: Union[str, int] = "1001035"thirdUserId: str = ""timeDesc: strtimePoint: str = ""schQukCategor: strdef update(self):self.appointmentNumber = self.disNoself.resDate = self.schDateself.patientId = self.patienId

3. 配置文件 (conf.ini)

[**省中医院]
host = https://www.rjh.com.cn/
deskey = wewerwe
username = 你的账号
password = 你的密码
token = token

使用说明

  1. 运行环境

    • Python 3.6+
    • 依赖库:pydanticrequests
  2. 启动方式

    python main.py
    
  3. 配置说明

    • 修改 conf.ini 中的账号和医院配置
    • 支持直接使用 token 登录

实现细节

  1. 字典展开语法

    all_args = {**dept, **hospital}
    args = DeptSchForDocArgs(**all_args)
    
  2. 异常处理

    • 捕获网络请求异常
    • 支持 Ctrl+C 中断程序
  3. 定时检测

    • 每10秒检测一次号源
    • 预约成功后等待10分钟

提示:部分代码,已脱敏,本脚本仅用于学习交流,请勿滥用。欢迎感兴趣的同学一起交流!

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词