Ejemplo n.º 1
0
def applyQual():
    if request.method == 'GET':
        # 显示所有未获得操作资格的仪器
        stuID = glo.get_value('glo_userID')
        db_insts = db.get_insts(opt='unqual', stuID=stuID)

        return render_template('applyqual.html', instruments=db_insts)
    else:
        # 选中某个仪器,显示可以审批的老师
        instID = request.form.get('form-instID', default='10001')  # 选中的仪器编号
        logger.info("<前端获取> 仪器编号:" + instID)
        db_teachers = db.get_qual(opt='faculty', instID=instID)
        logger.info("<数据库传回>teachers " + str(db_teachers))
        # TODO 将老师数据返回前端

        # TODO 发送申请
        # 要插入的新仪器申请记录的参数
        recordNum = glo.get_value('glo_record_num')
        glo.set_value('glo_record_num', recordNum + 1)
        recordID = recordNum + 1  # 编号
        state = 's1'  # 状态
        stuID = glo.get_value('glo_userID')  # 申请人学号
        groupName = None
        timeID = None
        instName = request.form.get('form-instname',
                                    default='default name')  # 仪器名称
        approvalID = request.form.get('form-approvalID',
                                      default='0000')  # 审批人编号

        db.add_inst_record(recordID, state, stuID, groupName, timeID, instName,
                           approvalID)
        return 'applied'
Ejemplo n.º 2
0
async def private_command(bot, event, command):
    print("--- private_command ---  " + str(command) + "  ---")

    message = ""
    # 普通命令
    if command == "发送笑话":
        message = get_joke()
    elif command == "图片":
        message = "图片生产中...."
    elif command == "":
        message = ""

    # 超级用户命令
    elif event.user_id in SUPERUSERS:
        if command == "开启优惠卷发送":
            message = "优惠卷发送已开启"
            glo.set_value("LOOP_COUPONS", True)
        elif command == "关闭优惠卷发送":
            message = "优惠卷发送已关闭"
            glo.set_value("LOOP_COUPONS", False)
        elif command == "查询当前状态":
            message = "当前状态为 \n\n"
            message += current_state()
    else:
        message = "你说的是人话么?"

    await bot.send(event, message)
Ejemplo n.º 3
0
 def run(self):
     cv2.namedWindow('capture position window')
     cap = cv2.VideoCapture(self.camera_idx)
     classifier_face = cv2.CascadeClassifier(
         "/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt2.xml"
     )
     while cap.isOpened():
         ok, frame = cap.read()
         if not ok:
             break
         grey = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
         face_rects = classifier_face.detectMultiScale(grey,
                                                       scaleFactor=1.2,
                                                       minNeighbors=3,
                                                       minSize=(32, 32))
         if len(face_rects) > 0:
             print(round_position(face_rects[0]))
             # self.position = round_position((face_rects[0]))
             glo.set_value('position', round_position(face_rects[0]))
             if self.unit_test:
                 x, y, w, h = face_rects[0]
                 # 识别出人脸后要画的边框的颜色,RGB格式
                 color = (0, 0, 255)
                 cv2.rectangle(frame, (x - 10, y - 10),
                               (x + w + 10, y + h + 10), color, 2)
         if self.unit_test:
             # 显示图像
             cv2.imshow(self.window_name, frame)
             c = cv2.waitKey(10)
             if c & 0xFF == ord('q'):
                 break
     # 释放摄像头并销毁所有窗口
     cap.release()
     cv2.destroyAllWindows()
     pass
Ejemplo n.º 4
0
def reserve():
    if request.method == 'GET':
        # 显示所有已获得操作资格的仪器
        stuID = glo.get_value('glo_userID')
        db_insts = db.get_insts(opt='qual', stuID=stuID)

        return render_template('applyqual.html', instruments=db_insts)
    else:
        # 选中某个仪器,显示可以审批的仪器管理员、可用时间段和可选课题组
        instID = request.form.get('form-instID', default='10001')  # 选中的仪器编号
        logger.info("<前端获取> 仪器编号:" + instID)

        db_admins = db.get_qual(opt='admin', instID=instID)
        logger.info("<数据库传回>db_admins " + str(db_admins))
        db_times = db.get_spare_time(instID)
        logger.info("<数据库传回>db_admins " + str(db_times))
        stuID = glo.get_value('glo_userID')
        db_groups = db.get_groups(opt='in', stuID=stuID)
        logger.info("<数据库传回>db_groups " + str(db_groups))

        # TODO 将所有数据返回前端

        # TODO 发送申请
        # 要插入的新仪器申请记录的参数
        recordNum = glo.get_value('glo_record_num')
        glo.set_value('glo_record_num', recordNum + 1)
        recordID = recordNum + 1  # 编号
        state = 's1'  # 状态
        stuID = glo.get_value('glo_userID')  # 申请人学号
        groupName = request.form.get('form-groupname',
                                     default='default g name')  # 课题组名称
        timeID = request.form.get('form-timeID',
                                  default='default timeID')  # 时间段编号
        instName = request.form.get('form-instname',
                                    default='default i name')  # 仪器名称
        approvalID = request.form.get('form-approvalID',
                                      default='0000')  # 审批人编号

        db.add_inst_record(recordID, state, stuID, groupName, timeID, instName,
                           approvalID)
        return 'applied'
Ejemplo n.º 5
0
def login():
    if request.method == 'GET':
        return render_template('login.html'), 200

    else:
        username = request.form.get('form-username', default='user')
        password = request.form.get('form-password', default='pass')
        logger.info("<前端获取> 账号:" + str((username)) + " 密码:" + str(password))

        db_user = db.get_user(username)
        logger.info("<数据库传回> " + str(db_user))
        if not db_user:  # 用户账号不存在
            # logger.info("<返回前端> none")
            return 'none'
        elif db_user[1] != password:  # 密码错误
            # logger.info("<返回前端> wrong")
            return 'wrong'
        else:  # 密码正确
            # 设置全局变量
            glo.set_value('glo_userID', username)
            glo.set_value('glo_identity', db_user[2])
            # logger.info("<返回前端> right")
            return 'right'
Ejemplo n.º 6
0
def sync_handle_msg(event):
    # print(event)
    LOOP = glo.get_value("LOOP")
    if event.user_id == 303205844 and event.message_type == "private" and event.message == "开启循环" and not LOOP:
        bot.sync.send_private_msg(user_id=event.user_id, message='我已经开启了循环模式')
        # 设置开始循环
        glo.set_value("LOOP", True)

        i = 1
        while glo.get_value("LOOP", False):
            if glo.get_value("LOOP_COUPONS", False):
                coupons_send_one_goods(bot, i)

            # 如果没有循环任务,则关闭循环
            else:
                glo.set_value("LOOP", False)
                break
            i += 1 if i < 100 else 1
            print(glo.get_value("LOOP"), i)

    if event.user_id == 303205844 and event.message_type == "private" and event.message == "关闭循环" and LOOP:
        bot.sync.send_private_msg(user_id=event.user_id, message='我已经关闭了循环模式')
        # 设置关闭循环
        glo.set_value("LOOP", False)
Ejemplo n.º 7
0
CONFIG = {}
cfg = ConfigParser()
cfg.read('App/config/default.conf')

sections = cfg.sections()
for secKey in sections:
    CONFIG[secKey] = {}
    options = cfg.options(secKey)
    for optKey in options:
        CONFIG[secKey][optKey] = cfg.get(secKey, optKey)

if os.environ.get('PYTHON_ENV'):
    if os.environ['PYTHON_ENV'] == 'develop':
        cfg.read('App/config/develop.conf')
    elif os.environ['PYTHON_ENV'] == 'test-internet':
        cfg.read('App/config/test-internet.conf')
    elif os.environ['PYTHON_ENV'] == 'production':
        cfg.read('App/config/production.conf')

sections = cfg.sections()

for secKey in sections:
    if secKey not in CONFIG:
        CONFIG[secKey] = {}
    options = cfg.options(secKey)
    for optKey in options:
        CONFIG[secKey][optKey] = cfg.get(secKey, optKey)

glo.set_value('CONFIG', CONFIG)
Ejemplo n.º 8
0
import glo
from sqlalchemy import create_engine
from sqlalchemy.engine.url import URL
from sqlalchemy.orm import sessionmaker

CONFIG = glo.get_value('CONFIG', {})

s = URL(
    drivername=CONFIG['db']['drivername'],
    username=CONFIG['db']['username'],
    password=CONFIG['db']['password'],
    host=CONFIG['db']['host'],
    port=CONFIG['db']['port'],
    database=CONFIG['db']['database']
)

engine = create_engine(s, echo=int(CONFIG['db']['echo']))

DBSession = sessionmaker(bind=engine)

glo.set_value('ENGINE', engine)
glo.set_value('DB', DBSession())
Ejemplo n.º 9
0
        return "unfinished"


# 显示管理员的记录与反馈
@app.route('/record-admin', methods=['GET'])
def recordAdmin():
    adminID = glo.get_value('glo_userID')
    db_records = db.get_records(opt='approval', userID=adminID)
    logger.info("<数据库传回>db_records " + str(db_records))

    # TODO 这里所有类型和状态的记录都混在一起……交给前端分开吗?
    return "unfinished"


if __name__ == '__main__':
    host = util.get_config()["host"]  # 获取配置信息
    port = int(util.get_config()["port"])
    debug = util.get_config()["debug"]
    if debug == "True":
        debug = True
    else:
        debug = False
    print(debug)
    glo._init()
    glo.set_value('glo_userID', '151')  # 登录的账号
    glo.set_value('glo_identity', 'admin')  # 登录的身份
    record_num = db.get_records_num()
    glo.set_value('glo_record_num', record_num)  # 仪器申请记录表行数(用于新插入记录时,确定记录编号属性)
    app.run(host=host, port=port, threaded=True, debug=debug)
Ejemplo n.º 10
0
Archivo: sql.py Proyecto: dwj1979/anack
# -*- coding:utf-8 -*-
import pymysql
from sqlalchemy import create_engine
import glo

glo._init()

host = 'localhost'
user = '******'
passwd = 'yc5315558'
database = 'anack_sql'

glo.set_value('host', host)
glo.set_value('user', user)
glo.set_value('passwd', passwd)
glo.set_value('database', database)
glo.set_value('charset', 'utf8')


def df_to_mysql(table, df):
    connect = create_engine("mysql+pymysql://" + user + ":" + passwd + "@" +
                            host + ":3306/" + database + "?charset=utf8")
    df.to_sql(name=table,
              con=connect,
              if_exists='append',
              index=False,
              index_label=False)
Ejemplo n.º 11
0
from aiocqhttp import CQHttp, Event

from src.coupons import coupons, coupons_group, is_coupons, coupons_send_one_goods
from src.common import is_manual, is_command, private_manual, private_command
import glo

bot = CQHttp()
glo._init()

# 发送优惠卷
glo.set_value("LOOP_COUPONS", False)
# 开启循环
glo.set_value("LOOP", False)


# 私聊
@bot.on_message('private')
async def _(event: Event):
    global LOOP_COUPONS, LOOP

    if is_manual(event.message):
        await private_manual(bot, event)
    elif is_command(event.message):
        await private_command(bot, event, event.message)
    else:
        await bot.send(event, '你发了:')
        return {'reply': event.message}


# 群聊
@bot.on_message('group')