Beispiel #1
0
    def register(self, user):
        detail = dbconn.get_user(self.conn, user)
        if detail:
            self.sock.send(b"403 User Name Already Registered")
            return "403"

        self.sock.send(b"202 Proceed Password Register")
        data = self.sock.recv(1024)
        data_splitted = data.decode().split()
        command, argument = data_splitted[0], " ".join(data_splitted[1:])
        if command == "RPAS":
            detail = dbconn.register(self.conn, user, argument)

            self.sock.send(b"291 Register OK")
            return "410"
        else:
            self.sock.send(b"499 Unknown Command")
            return "499"
Beispiel #2
0
    def login(self, user):
        detail = dbconn.get_user(self.conn, user)
        if not detail:
            self.sock.send(b"401 User Name Null")
            return "401"

        user, password = detail

        # check for double login
        if user in self.player_list:
            self.sock.send(b"404 User Already Logged In")
            return "402"
        self.sock.send(b"201 Proceed Password Login")
        data = self.sock.recv(1024)
        data_splitted = data.decode().split()
        command, argument = data_splitted[0], " ".join(data_splitted[1:])
        if command == "LPAS":
            if argument != password:
                self.sock.send(b"402 Password Not Recognized")
                return "402"

            # successful login
            self.player.name = user
            self.player.loggedin = True
            # self.player.sock = self.sock
            self.socket_list[user] = {}
            self.socket_list[user]["main"] = self.sock

            # add current player to player_list
            self.player_list[user] = self.player

            self.sock.send(b"290 Login OK")
            return "290"
        else:
            self.sock.send(b"499 Unknown Command")
            return "499"
Beispiel #3
0
def readMsg(user_id, message):
    #处理消息核心
    user_id = str(user_id)
    #管理员列表
    admin_list = show_admin()

    if ('image' in message):
        if (dbconn.check_register(user_id)):
            #用户已注册
            get_img(user_id, message)
        else:
            #用户未注册
            goapi.sendMsg(
                user_id,
                '您还没注册呢,请输入例如"注册@小明@智科20-2"\n 班级请严格按格式输入,否则可能统计不上哦,另外特别注意' -
                '是减号不是破折号,也不要加空格')
        return
    if ('注册' in message):
        try:
            user_name = message.split('@')[1]
            user_class = message.split('@')[2]
            #简单过滤用户输入
            if not (inputFilter.is_Chinese(user_name)
                    and inputFilter.check_length(user_name)):
                goapi.sendMsg(user_id, '输入好像有点问题呢')
                return
            if not (inputFilter.is_valid(user_class)
                    and inputFilter.check_length(user_class)):
                goapi.sendMsg(user_id, '输入好像有点问题呢')
                return

        except:
            goapi.sendMsg(user_id, '输入好像有点问题呢')
        else:
            if (dbconn.check_register(user_id)):
                goapi.sendMsg(user_id, '您已注册过啦~')
                re_register_user(user_id, user_name, user_class)
            else:
                register_user(user_id, user_name, user_class)
        return
    if ('/admin' in message):
        user_class = dbconn.get_user(user_id)['user_class']
        upload_date = time.strftime("%Y-%m-%d", time.localtime())
        print(user_id)
        if (user_id in admin_list.keys()):
            group_id = admin_list[user_id]
            if ('群提醒' in message):
                send_alert(group_id,
                           dbconn.get_user(user_id)['user_class'], 'group')
            elif ('提醒' in message):
                send_alert(user_id,
                           dbconn.get_user(user_id)['user_class'], 'private')
                upload_date = time.strftime("%Y-%m-%d", time.localtime())
                time.sleep(1)
                #ocr_err_upload(user_id,user_class,upload_date)
                ocr_err_upload(user_id, user_class, upload_date)
                time.sleep(2)
                send_images_info(user_id, user_class)
            elif ('打包' in message):
                cmp_ret = compress.zip_file(
                    upload_date,
                    dbconn.get_user(user_id)['user_class'])
                goapi.sendMsg(user_id,
                              f"---打包完毕---\n共处理:{cmp_ret['file_num']}张照片")
                goapi.sendMsg(
                    user_id,
                    '下载地址:' + urllib.parse.quote(cmp_ret['file_name']))
            elif ('成员' in message):
                list_class_menbers(user_id, user_class)
            elif ('核对' in message):
                goapi.sendMsg(user_id, 'get')
                err_imgid = message.split('@')[1]
                ocr_times = message.split('@')[2]
                ocr_scores = message.split('@')[3]
                if (dbconn.err_check):
                    err_code = dbconn.err_check(err_imgid)
                    if (err_code):
                        dbconn.manual_update(ocr_times, ocr_scores, err_imgid)
                        goapi.sendMsg(
                            user_id,
                            f"人工校对完成:{dbconn.get_user_by_migid(err_imgid)}\n参赛次数:{ocr_times}\n积分:{ocr_scores}"
                        )
                elif (err_code == 0):
                    goapi.sendMsg(user_id, '该图片无需校对,请重新检查输入的id')
                elif (err_code == -1):
                    goapi.sendMsg(
                        user_id,
                        f"已经人工校对过了,覆盖校对:\n{dbconn.get_user_by_migid(imgid)}\n参赛次数:{ocr_times}\n积分:{ocr_scores}"
                    )

            else:
                goapi.sendMsg(user_id, "目前支持以下管理指令呢:\n群提醒\n提醒\n打包\n成员\n")
        else:

            goapi.sendMsg(user_id, "无管理权限")

    if ('/sudo' in message
            and (user_id == '601179193' or user_id == "29242764"
                 or user_id == "1476821890" or user_id == "3439911708")):
        #try:

        if ('增加管理员' in message):
            admin_id = message.split('@')[1]
            group_id = message.split('@')[2]
            goapi.sendMsg(user_id, str(add_admin(admin_id, group_id)))
        elif ('删除管理员' in message):
            admin_id = message.split('@')[1]
            goapi.sendMsg(user_id, str(del_admin(admin_id)))
        elif ('展示管理员' in message):
            goapi.sendMsg(user_id, str(show_admin()))
        else:
            goapi.sendMsg(user_id, '增加管理员\n删除管理员\n展示管理员')
        #except:
        #goapi.sendMsg(user_id,'增加管理员\n删除管理员\n展示管理员')
        #else:
        #pass

    return
Beispiel #4
0
def get_img(user_id, message):
    #从message中解析到图片下载地址,并保存数据库,下载文件
    try:
        img_url = message.split('url=')[1][0:-1]
        user_name = dbconn.get_user(user_id)['user_name']
        user_class = dbconn.get_user(user_id)['user_class']
        upload_date = time.strftime("%Y-%m-%d", time.localtime())
        upload_time = time.strftime("%H:%M:%S", time.localtime())

        #修改文件名格式(注意只保存文件名和数据库中显示的file_name改变,目录等名称不变)
        file_date = time.strftime("%Y%m%d", time.localtime())

        #安全过滤
        if not (img_url[0:24] == 'http://c2cpicdw.qpic.cn/'):
            goapi.sendMsg(user_id, '图片url解析错误')
            return

        #判断文件目录是否存在
        if not (os.path.exists(f"images/{upload_date}")):
            os.mkdir(f"images/{upload_date}")
        if not (os.path.exists(f"images/{upload_date}/{user_class}")):
            os.mkdir(f"images/{upload_date}/{user_class}")

        file_name = f"/{upload_date}/{user_class}/{user_class}班-{user_name}-{file_date}.jpg"
        if (dbconn.check_today_upload(user_id, upload_date)):
            goapi.sendMsg(user_id, '您今天已经上传过照片啦,已覆盖之前的图片~')

        download_img(img_url, file_name)
        #print(img_url)
    except Exception as err:
        goapi.sendMsg(user_id, '图片下载出错了!')
        print(err)
    else:
        print("成功处理图片:" + file_name)
        goapi.sendMsg(
            user_id,
            "成功处理图片,正在识别...\n" + f"{user_class}班-{user_name}-{file_date}.jpg")
        """图片识别部分"""
        try:
            print(file_name)
            ocr_ret = ocrplus.ocr_img("images" + file_name)
            ocr_err_code = ocr_ret['err_code']
            if (ocr_err_code == 0):
                goapi.sendMsg(
                    user_id,
                    f"参赛次数:{ocr_ret['个人参赛次数']}\n个人积分:{ocr_ret['个人积分']}")
                ocr_times = ocr_ret['个人参赛次数']
                ocr_scores = ocr_ret['个人积分']
            else:
                print("图片无法识别:" + ocr_ret)
                #图片识别接口返回无法识别
                goapi.sendMsg(user_id, f"OCR无法识别,团支书将人工复核~")
                dbconn.insert_img(user_id, file_name, upload_date, upload_time,
                                  '1', '0', '0')
                return
        except:
            #图片识别接口出错
            print("OCR接口出错:")
            goapi.sendMsg(user_id, f"qwq图片识别出错了!可能是字体原因,请尝试更换字体后重试")
            dbconn.insert_img(user_id, file_name, upload_date, upload_time,
                              '1', '0', '0')
        else:
            dbconn.insert_img(user_id, file_name, upload_date, upload_time,
                              ocr_err_code, ocr_times, ocr_scores)

    return
Beispiel #5
0
def readMsg(user_id, message):
    #处理消息核心
    user_id = str(user_id)
    #管理员列表
    admin_list = show_admin()

    if ('image' in message):
        if (dbconn.check_register(user_id)):
            #用户已注册
            get_img(user_id, message)
        else:
            #用户未注册
            goapi.sendMsg(user_id,
                          '您还没注册呢,请输入例如"注册@张三@计科20-2"\n 班级请严格按格式输入,否则可能统计不上哦')
        return
    if ('注册' in message):
        try:
            user_name = message.split('@')[1]
            user_class = message.split('@')[2]
            #简单过滤用户输入
            if not (inputFilter.is_Chinese(user_name)
                    and inputFilter.check_length(user_name)):
                goapi.sendMsg(user_id, '输入好像有点问题呢')
                return
            if not (inputFilter.is_valid(user_class)
                    and inputFilter.check_length(user_class)):
                goapi.sendMsg(user_id, '输入好像有点问题呢')
                return

        except:
            goapi.sendMsg(user_id, '输入好像有点问题呢')
        else:
            if (dbconn.check_register(user_id)):
                goapi.sendMsg(user_id, '您已注册过啦~')
                re_register_user(user_id, user_name, user_class)
            else:
                register_user(user_id, user_name, user_class)
        return
    if ('/admin' in message):
        user_class = dbconn.get_user(user_id)['user_class']
        upload_date = time.strftime("%Y-%m-%d", time.localtime())
        print(user_id)
        if (user_id in admin_list.keys()):
            group_id = admin_list[user_id]
            if ('群提醒' in message):
                send_alert(group_id,
                           dbconn.get_user(user_id)['user_class'], 'group')
            elif ('提醒' in message):
                send_alert(user_id,
                           dbconn.get_user(user_id)['user_class'], 'private')
                upload_date = time.strftime("%Y-%m-%d", time.localtime())
                time.sleep(1)
                #ocr_err_upload(user_id,user_class,upload_date)
                ocr_err_upload(user_id, user_class, upload_date)
                time.sleep(2)
                send_images_info(user_id, user_class)
            elif ('打包' in message):
                cmp_ret = compress.zip_file(
                    upload_date,
                    dbconn.get_user(user_id)['user_class'])
                goapi.sendMsg(user_id,
                              f"---打包完毕---\n共处理:{cmp_ret['file_num']}张照片")
                goapi.sendMsg(
                    user_id, '下载地址:http://static.catop.top:8001/' +
                    urllib.parse.quote(cmp_ret['file_name']))
            elif ('成员' in message):
                list_class_menbers(user_id, user_class)
            else:
                goapi.sendMsg(user_id, "目前支持以下管理指令呢:\n群提醒\n提醒\n打包\n成员\n")
        else:

            goapi.sendMsg(user_id, "无管理权限")

    if ('/sudo' in message
            and (user_id == '601179193' or user_id == "29242764")):
        #try:

        if ('增加管理员' in message):
            admin_id = message.split('@')[1]
            group_id = message.split('@')[2]
            goapi.sendMsg(user_id, str(add_admin(admin_id, group_id)))
        elif ('删除管理员' in message):
            admin_id = message.split('@')[1]
            goapi.sendMsg(user_id, str(del_admin(admin_id)))
        elif ('展示管理员' in message):
            goapi.sendMsg(user_id, str(show_admin()))
        else:
            goapi.sendMsg(user_id, '增加管理员\n删除管理员\n展示管理员')
        #except:
        #goapi.sendMsg(user_id,'增加管理员\n删除管理员\n展示管理员')
        #else:
        #pass

    return
Beispiel #6
0
import learner
import recognizer
import dbconn

print("Sign up enter 1")
print("Sign in enter 2\n")
print("Select action from above two.")
print("Press 'q' for exit from camera view.\n")
action = raw_input('Select action : ')
email = raw_input('Enter email : ')
try:
    if int(action) == 1:
        name = raw_input('Enter name : ')
        res = dbconn.create_user(email, name)
        if res == True:
            id, name = dbconn.get_user(email)
            res_train = learner.learn_user(id)

            if res_train == True:
                print("\nUser sign up successful.")
            else:
                # delete user if training unsuccessful
                dbconn.del_user(id)
                print("\nUser sign up unsuccessful.")
        else:
            print('\nEmail address already exist.')
    elif int(action) == 2:
        res = dbconn.get_user(email)
        if res != None:
            id, name = res
            recognizer.recognize_face(id, name)