医院预约挂号

医院预约挂号脚本

功能介绍

本脚本是一个用 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分钟

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

相关推荐
合作小小程序员小小店1 小时前
桌面开发,超市管理系统开发,基于C#,winform,sql server数据库
开发语言·数据库·sql·microsoft·sqlserver·c#
合作小小程序员小小店3 小时前
桌面开发,在线%超市销售管理%系统,基于vs2022,c#,winform,sql server数据
开发语言·数据库·microsoft·c#
天庭鸡腿哥4 小时前
吾爱3年前的作品,依旧流批!
科技·microsoft·visual studio·everything
q***d1734 小时前
C在物联网中的Azure IoT Solution Accelerators
物联网·microsoft·azure
1***s6324 小时前
C在物联网中的Azure IoT Hub
物联网·microsoft·azure
std78798 小时前
微软宣布Windows Server 2025是支持WINS名称解析服务的最终版本 后续将弃用
microsoft
std8602110 小时前
微软封锁Win11/Office KMS38破解!无法再激活到2038年
microsoft
许泽宇的技术分享1 天前
当AI Agent遇上.NET:微软Agent Framework的架构奥秘与实战启示
人工智能·microsoft·.net
lingggggaaaa1 天前
免杀对抗——C2远控篇&PowerShell&有无文件落地&C#参数调用&绕AMSI&ETW&去混淆特征
c语言·开发语言·笔记·学习·安全·microsoft·c#
s***4531 天前
MSSQL2022的一个错误:未在本地计算机上注册“Microsoft.ACE.OLEDB.16.0”提供程序
数据库·microsoft