医院预约挂号

医院预约挂号脚本

功能介绍

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

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

核心代码解析

1. 主程序 (main.py)

python 复制代码
# -*- coding: utf-8 -*-
import time
from schema import AddRegArgs, DeptSchForDocArgs, DocSchArgs, NumberSourceArgs
from api import Api


def 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.txt


def 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)

python 复制代码
# -*- coding: utf-8 -*-
from pydantic import BaseModel
from typing import Union


class HospitalArgs(BaseModel):
    sysCode: Union[str, int] = "1001035"


class DeptListArgs(BaseModel):
    clinicalType: str = 1
    hosId: int
    sysCode: Union[str, int] = "1001035"


class DeptSchForDocArgs(BaseModel):
    clinicalType: str = 1
    deptCode: str = None
    deptId: str = deptCode
    specialtyId: str = None
    deptName: str
    visitingArea: str
    hosId: int
    recommendation: str = ""
    type: str = "order"
    source: int = 22
    sysCode: Union[str, int] = "1001035"

    def update(self):
        self.deptId = self.deptCode


class DocSchArgs(BaseModel):
    deptId: str
    deptName: str
    docId: str
    docName: str
    docTitle: str
    docPhoto: str
    hosId: int
    hosName: str
    type: str = "order"
    visitingArea: str = ""
    clinicalType: str = 1
    source: int = 22
    sysCode: Union[str, int] = "1001035"


class NumberSourceArgs(BaseModel):
    sysCode: Union[str, int] = "1001035"
    ampm: str
    categor: str
    docId: str
    deptId: str
    hosId: Union[str, int]
    schDate: str
    schId: str


class AddRegArgs(BaseModel):
    # key不一致参数
    disNo: str = None
    schDate: str = None
    patienId: str = None

    # 必须参数
    clinicalType: str = 1
    visitingArea: str = ""
    ampm: str
    appointmentNumber: str = disNo
    categor: str
    categorName: str
    deptId: str
    deptName: str
    docId: str
    docName: str
    endTime: str = ""
    extend: str = ""
    fee: str
    hosId: Union[str, int]
    hosName: str
    isFlexible: str = ""
    numId: str = ""
    patientId: str = patienId
    resDate: str = schDate
    schId: str
    source: int = 22
    startTime: str = ""
    sysCode: Union[str, int] = "1001035"
    thirdUserId: str = ""
    timeDesc: str
    timePoint: str = ""
    schQukCategor: str

    def update(self):
        self.appointmentNumber = self.disNo
        self.resDate = self.schDate
        self.patientId = self.patienId

3. 配置文件 (conf.ini)

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

使用说明

  1. 运行环境

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

    bash 复制代码
    python main.py
  3. 配置说明

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

实现细节

  1. 字典展开语法

    python 复制代码
    all_args = {**dept, **hospital}
    args = DeptSchForDocArgs(**all_args)
  2. 异常处理

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

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

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

相关推荐
AI营销干货站10 小时前
原圈科技AI市场分析:洞察全球消费,决胜2026出海
人工智能·microsoft
张人玉10 小时前
C#WinFrom中show和ShowDialog的区别
开发语言·microsoft·c#
m0_7482331710 小时前
C#:微软的现代编程利器
开发语言·microsoft·c#
百***78751 天前
Kimi K2.5开源模型实战指南:核心能力拆解+一步API接入(Python版,避坑全覆盖)
python·microsoft·开源
qq_12498707531 天前
基于Srpingboot心晴疗愈社平台的设计与实现(源码+论文+部署+安装)
java·数据库·spring boot·spring·microsoft·毕业设计·计算机毕业设计
Access开发易登软件1 天前
Access 窗体中实现数字滚动动画:Timer + Easing 的技术实现
运维·数据库·nginx·microsoft·access
hunteritself1 天前
反击 OpenAI!谷歌史诗级更新:Gemini in Chrome 正式上线,免费用
人工智能·深度学习·microsoft·机器学习·chatgpt
Blossom.1181 天前
从视觉理解到自主决策:多模态大模型与AI Agent融合架构实战解析
数据库·人工智能·python·深度学习·microsoft·机器学习·架构
Studying 开龙wu2 天前
争对C++开发VS2022安装——Microsoft Visual Studio2022从下载到安装步骤教程(超详细)
c++·microsoft·visual studio
珊瑚怪人2 天前
Microsoft Visual Studio2022下载安装详细教程
ide·microsoft·c#·编辑器·visual studio·cpp