示例#1
0
def get_sms_verify_code(key):
    query = {
        'mobile': g_patient_info['phone'],
        'smsKey': 'ORDER_CODE',
        'uniqProductKey': key,
    }
    return api.api_call(api_config.API_114_VERIFY_CODE, query)
示例#2
0
def order_check():
    post_content_map = {
        'idCardNo': g_patient_info['idCardNo'],
        'idCardType': g_patient_info['idCardType'],
    }
    post_content = bytes(json.dumps(post_content_map), encoding='utf-8')
    return api.api_call(api_config.API_114_ORDER, post_data=post_content)
示例#3
0
def save_order(code, department, date, key, sms_code='', duty_time='0'):
    card = g_patient_info['cardList'][0]
    post_content_map = {
        'hosCode': code,
        'firstDeptCode': department['firstDeptCode'],
        'secondDeptCode': department['secondDeptCode'],
        'treatmentDay': date,
        'uniqProductKey': key,
        'cardType': card['cardType'],
        'cardNo': card['cardNo'],
        'smsCode': sms_code,
        'jytCardId': '',
        'hospitalCardId': '',
        'phone': g_patient_info['phone'],
        'dutyTime': duty_time,
    }
    if g_topic_key is not None and len(str(g_topic_key).split('-')) > 1:
        post_content_map['orderFrom'] = str(g_topic_key).split('-')[1]

    post_content = bytes(json.dumps(post_content_map), encoding='utf-8')
    resp = api.api_call(api_config.API_114_ORDER_SAVE, post_data=post_content)
    if api.is_success_response(resp):
        data = resp['data']
        if isinstance(data, dict) and 'orderNo' in data:
            order_no = data['orderNo']
            print(f'预约成功,订单号 {order_no}')
            order_detail(code, order_no)
    else:
        msg = resp['msg']
        notification_util.show_notification('预约失败', msg)
        print(f'提交预约单失败 : {msg}')
示例#4
0
文件: vps.py 项目: BCable/panenthe
	def remove_all_ips(self):
		if not self.require("real_id"):
			return errors.throw(errors.BACKEND_INVALID_INPUT)

		# vps IP addresses
		ac = api.api_call("vm_ips", {
			'vps_id': self.vps_id
		})
		ret = ac.execute()
		if ret != errors.ERR_SUCCESS: return ret

		# remove IPs from iptables
		try:
			ips = ac.output()[0]['ip']

			# loop through IPs and remove
			for ip in ips:
				iptables.delete_rule(
					"PANENTHE_BW", "-d %s" % ip, self.do_execute
				)
				iptables.delete_rule(
					"PANENTHE_BW", "-s %s" % ip, self.do_execute
				)

		except (IndexError, KeyError): pass

		# save rules
		srv = self.get_server()
		error = iptables.save(srv.do_execute, srv.get_remote_distro())

		if error != errors.ERR_SUCCESS:
			return error
示例#5
0
def order_detail(code, order_no):
    query = {
        'orderNo': order_no,
        'hosCode': code,
    }
    resp = api.api_call(api_config.API_114_ORDER_DETAIL, query)
    if api.is_success_response(resp):
        print(resp)
示例#6
0
def get_hospital_list(keywords):
    query = {
        'keywords': keywords,
        'sortType': 'COMPREHENSIVE',
        'areaId': 0,
        'pageNo': 1,
        'pageSize': 15,
    }
    return api.api_call(api_config.API_114_HOSPITAL_LIST, query)
示例#7
0
def get_department_duty_list(topic_key, hospital_code, department):
    post_content_map = {
        'hosCode': hospital_code,
        'firstDeptCode': department['firstDeptCode'],
        'secondDeptCode': department['secondDeptCode'],
    }
    if topic_key is not None:
        post_content_map['topic_key'] = topic_key
    post_content = bytes(json.dumps(post_content_map), encoding='utf-8')
    return api.api_call(api_config.API_114_DEP_LIST, post_data=post_content)
示例#8
0
def check_save_order(code, department, date, key, sms_code='', duty_time='0'):
    if len(g_patient_info) == 0 or g_patient_info['cardList'] is None or len(
            g_patient_info['cardList']) == 0:
        print('无就诊卡相关信息')
        return False
    card = g_patient_info['cardList'][0]
    post_content_map = {
        'hosCode': code,
        'firstDeptCode': department['firstDeptCode'],
        'secondDeptCode': department['secondDeptCode'],
        'treatmentDay': date,
        'uniqProductKey': key,
        'cardType': card['cardType'],
        'cardNo': card['cardNo'],
        'smsCode': sms_code,
        'jytCardId': '',
        'hospitalCardId': '',
        'phone': g_patient_info['phone'],
        'dutyTime': duty_time
    }
    post_content = bytes(json.dumps(post_content_map), encoding='utf-8')
    resp = api.api_call(api_config.API_114_ORDER_SAVE_CHECK,
                        post_data=post_content)
    if api.is_success_response(resp):
        data = resp['data']
        if isinstance(data, dict):
            if 'state' in data:
                state = data['state']
                if state == 'OK' or state == 'NEED_CONFIRM':
                    save_order(code, department, date, key, sms_code,
                               duty_time)
                    return True
                elif state == 'TOAST':
                    msg = data['msg']
                    if '请重新选择就诊时段' == msg:
                        print('需要重新选择就诊时段')
                        resp = get_department_day_duty_detail(
                            date, g_topic_key, code, department)
                        duty_detail = parse_department_day_duty_info(
                            code_name_map[code], resp)
                        if 'period' in duty_detail:
                            period = duty_detail['period']
                            if isinstance(period, dict):
                                period_duty_time = period['dutyTime']
                                print(f'新的就诊时段 {period_duty_time}')
                                check_save_order(code, department, date, key,
                                                 period_duty_time)
                            elif isinstance(period, list):
                                for period_item in period:
                                    period_duty_time = period_item['dutyTime']
                                    print(f'新的就诊时段 {period_duty_time}')
                                    check_save_order(code, department, date,
                                                     key, period_duty_time)
                                    break
示例#9
0
def get_department_day_duty_detail(date, topic_key, hospital_code, department):
    post_content_map = {
        'hosCode': hospital_code,
        'firstDeptCode': department['firstDeptCode'],
        'secondDeptCode': department['secondDeptCode'],
        'target': date,
        # 'topicKey': topic_key,
    }
    if topic_key is not None:
        post_content_map['topicKey'] = topic_key
    post_content = bytes(json.dumps(post_content_map), encoding='utf-8')
    return api.api_call(api_config.API_114_DETAIL, post_data=post_content)
示例#10
0
def get_hospital_department_list(hos_code):
    global department_name_code_map
    target_department = api.config_dict[DEPARTMENT]
    query = {
        'hosCode': hos_code,
    }
    rsp = api.api_call(api_config.API_114_HOSPITAL_DEPARTMENT_LIST, query)
    if api.is_success_response(rsp):
        rsp_data = rsp['data']
        if isinstance(rsp_data, dict) and 'list' in rsp_data:
            depart_list = rsp_data['list']
            if isinstance(depart_list, list):
                for department_info in depart_list:
                    if isinstance(department_info, dict):
                        department_code = department_info['code']
                        department_name_code_map[
                            department_code] = department_info
    if len(department_name_code_map) > 0:
        for key in department_name_code_map:
            info = department_name_code_map[key]
            dep_name = info['name']
            dep_1_code = info['code']
            dep_2_code = ''
            sub_list = info['subList']
            if isinstance(sub_list, list):
                if len(sub_list) == 1:
                    dep_2_code = sub_list[0]['code']
                for sub in sub_list:
                    sub_name = sub['name']
                    sub_dep_1_code = sub['dept1Code']
                    sub_dep_2_code = sub['code']
                    print(f'{sub_name} {sub_dep_1_code} {sub_dep_2_code}')
                    if len(str(target_department)) > 0 and str(
                            sub_name).__contains__(target_department):
                        if loop == 0:
                            found = check_duty_and_register(
                                hos_code, sub_dep_1_code, sub_dep_2_code)
                            if not found:
                                notification_util.show_notification(
                                    '是否可预约', '暂无可预约的号')
                        else:
                            repeat_timer = timer.RepeatingTimer(
                                loop_query_delay,
                                check_duty_and_register,
                                args=[
                                    hos_code, sub_dep_1_code, sub_dep_2_code
                                ])
                            repeat_timer.start()
                        return True
            print(f'{dep_name} {dep_1_code} {dep_2_code}')
    return False
示例#11
0
def get_hospitals_by_area_and_topic(topic_key, area_id, keyword=''):
    global g_topic_key
    g_topic_key = topic_key
    query = {
        'keywords': keyword,
        'sortType': 'COMPREHENSIVE',
        'areaId': area_id,
        'pageNo': 1,
        'pageSize': 15,
    }
    if topic_key is not None:
        query['topicKey'] = topic_key
    return api.api_call(api_config.API_114_HOSPITAL_TOPIC_LIST,
                        query,
                        post_data=None)
示例#12
0
def fanyiApi(text):
    for vender in ['google', 'tencent', 'youdao', 'baidu']:
        try:
            print(colorful.bold | '{}:'.format(vender))
            result = api_call('fanyi', {
                'vender': vender,
                'q': text,
                'from': 'ja',
                'to': 'zh'
            })
            for s in result:
                for s in filter(lambda x: x != '', s.split('。')):
                    print('    ' + s + '。')
            print()
        except Exception as e:
            printException(e)
示例#13
0
def register_confirm(key,
                     date,
                     topic_key,
                     hospital_code,
                     department,
                     duty_time='0'):
    post_content_map = {
        'hosCode': hospital_code,
        'firstDeptCode': department['firstDeptCode'],
        'secondDeptCode': department['secondDeptCode'],
        'target': date,
        # 'topicKey': topic_key,
        'uniqProductKey': key,
        'dutyTime': duty_time
    }
    if topic_key is not None:
        post_content_map['topicKey'] = topic_key
    post_content = bytes(json.dumps(post_content_map), encoding='utf-8')
    return api.api_call(api_config.API_114_CONFIRM, post_data=post_content)
示例#14
0
文件: server.py 项目: BCable/panenthe
	def cron_daily(self):
		self.require_remote()

		# get VMs
		ac = api.api_call("server_vms", {
			'server_id': self.get_server_id()
		})
		ret = ac.execute()
		if ret != errors.ERR_SUCCESS: return ret
		result = ac.output()

		# get backend
		from backend import backend

		# update stats on each VPS
		for vps in result:
			vps['server'] = self.remote_server
			backend.execute("vpsctl", "usage_bandwidth", str(vps))

		# we return here because this is never called by the cron directly...
		# the cron is actually called by cron_daily() of masterctl
		return errors.throw(errors.ERR_SUCCESS)
示例#15
0
def get_patient_list():
    global g_patient_info
    resp = api.api_call(api_config.API_114_PATIENT_LIST)
    if api.is_success_response(resp):
        data = resp['data']
        if isinstance(data, dict):
            count = data['count']
            if count == 0:
                print('需要添加就诊卡信息')
                return None
            patient_list = data['list']
            if isinstance(patient_list, list):
                for patient in patient_list:
                    if isinstance(patient, dict):
                        if patient['patientName'] == api.config_dict['name']:
                            card_list = patient['cardList']
                            if isinstance(card_list, list):
                                for card in card_list:
                                    card_type = card['cardTypeView']
                                    card_no = card['cardNo']
                                    print(f'{card_type} {card_no}')
                            g_patient_info = patient
                            return patient
示例#16
0
文件: master.py 项目: BCable/panenthe
    def cron_daily(self):
        # get servers
        ac = api.api_call("server_list", {})
        ret = ac.execute()
        if ret != errors.ERR_SUCCESS:
            return ret
        servers = ac.output()

        # loop servers
        for remote_server_dict in servers:
            # nothing update on master
            if remote_server_dict["parent_server_id"] == 0:
                continue

                # master
            server_dict = self.get_dict()
            # slave
            server_dict["remote_server"] = remote_server_dict

            # call its cron_daily command
            server_obj = server(server_dict)
            ret = server_obj.cron_daily()
            if ret != errors.ERR_SUCCESS:
                return ret
示例#17
0
文件: server.py 项目: BCable/panenthe
	def initialize_bw(self):
		self.require_remote()

		# sanity (of which I have none)
		self.cleanup_bw()

		# create chains
		(exit_code,_,_) = iptables.add_chain("PANENTHE_BW", self.do_execute)

		if exit_code != 0:
			return errors.throw(errors.SERVER_IPTABLES)

		# create rule for INPUT table
		(exit_code,_,_) = iptables.insert_rule(
			"INPUT", "-j PANENTHE_BW", self.do_execute
		)

		if exit_code != 0:
			return errors.throw(errors.SERVER_IPTABLES)

		# create rule for FORWARD table
		(exit_code,_,_) = iptables.insert_rule(
			"FORWARD", "-j PANENTHE_BW", self.do_execute
		)

		if exit_code != 0:
			return errors.throw(errors.SERVER_IPTABLES)

		# create rule for OUTPUT table
		(exit_code,_,_) = iptables.insert_rule(
			"OUTPUT", "-j PANENTHE_BW", self.do_execute
		)

		if exit_code != 0:
			return errors.throw(errors.SERVER_IPTABLES)

		# server IP addresses
		ac = api.api_call("server_ips", {
			'server_id': self.get_server_id()
		})
		ret = ac.execute()
		if ret != errors.ERR_SUCCESS: return ret
		result = ac.output()

		# use IPs
		try:
			result[0]
			result[0]['ip']
			ips = result[0]['ip']

			# loop through IPs
			for ip in ips:
				iptables.add_rule("PANENTHE_BW", "-d %s" % ip, self.do_execute)
				iptables.add_rule("PANENTHE_BW", "-s %s" % ip, self.do_execute)

		# there might not be any IPs yet
		except (IndexError, KeyError): pass

		# save iptables rules
		error = iptables.save(self.do_execute, self.get_remote_distro())

		return error
示例#18
0
def get_hospital_detail(hos_code):
    query = {
        'hosCode': hos_code,
    }
    return api.api_call(api_config.API_114_HOSPITAL_DETAIL, query)
示例#19
0
文件: update.py 项目: BCable/panenthe
import copy
import sys
import urllib

##

import glob
import errors

from backend import backend
from execute import *
import api
import vps

# get server list
ac = api.api_call("server_list", {})
ret = ac.execute()
if ret != errors.ERR_SUCCESS:
	sys.exit(1)
servers = ac.output()

# for each server, call bandwidth initialize
for server in servers:
	# get the dictionary
	server_text = urllib.unquote(str(server)).replace("+", " ")
	server_dict = eval(server_text)
	server_dict['remote_server'] = copy.copy(server_dict)
	server_text = str(server_dict)

	# create bandwidth cron on master, and that's all
	if server['parent_server_id'] == 0:
示例#20
0
文件: vps.py 项目: BCable/panenthe
	def usage_bandwidth(self):
		if not self.require("real_id"):
			return errors.throw(errors.BACKEND_INVALID_INPUT)

		# vps IP addresses
		ac = api.api_call("vm_get_info", {
			'vps_id': self.vps_id
		})
		ret = ac.execute()
		if ret != errors.ERR_SUCCESS: return ret
		result = ac.output()

		# check output
		try:
			self.ips = result[0]['ip']

		# error with output
		except IndexError:
			return errors.throw(errors.BACKEND_ERR_UNKNOWN)

		# no IPs associated with it, so nothing to update
		except KeyError:
			return errors.throw(errors.ERR_SUCCESS)

		# get IP stats
		total_destination = 0
		total_source = 0
		for ip in self.ips:
			(exit_code,stdout,_) = self.do_execute(
				"%s -nvxL PANENTHE_BW | /usr/bin/env grep \"%s\" | " % (
					glob.config.get("paths", "iptables"), ip
				) +
				"/usr/bin/env sed -r \"s/[ ]+/ /g\""
			)

			for line in stdout:
				data = line.split(" ")

				# 2 is bytes, 7 is source IP, 8 is destination IP
				if data[7] == "0.0.0.0/0" and data[8] != "0.0.0.0/0":
					total_destination += int(data[2])
				elif data[8] == "0.0.0.0/0" and data[7] != "0.0.0.0/0":
					total_source += int(data[2])

		# update PHP
		(php_exit_code,_,_) = php.db_update(
			"vps_stats", "update_bandwidth",
			str(self.server['server_id']), str(self.vps_id),
			str(total_destination), str(total_source)
		)

		# php exit code
		if php_exit_code != 0:
			return php_exit_codes.translate(php_exit_code)

		# set up iptables for the rules since PHP was updated successfully
		for ip in self.ips:
			# add #1
			(exit_code,_,_) = iptables.add_rule(
				"PANENTHE_BW", "-d %s" % ip, self.do_execute
			)

			if exit_code != 0:
				return errors.throw(errors.SERVER_IPTABLES)

			# add #2
			(exit_code,_,_) = iptables.add_rule(
				"PANENTHE_BW", "-s %s" % ip, self.do_execute
			)

			if exit_code != 0:
				return errors.throw(errors.SERVER_IPTABLES)

		return errors.throw(errors.ERR_SUCCESS)