Example #1
0
 def killemall(self):
     for process in self.processes.values():
         try:
             process.tabPage.close()
         except Exception as e:
             logger.warning("Exception when trying to kill process..\n%s" %
                            e)
Example #2
0
 def delete(self, process):
     try:
         processName = process.name
         self.processes.pop(processName)
         logger.debug(u"Removed process %s" % processName)
     except KeyError:
         logger.warning(u"Trying to remove not existing process..")
Example #3
0
 def delete(self, process):
     try:
         processName = process.name
         self.processes.pop(processName)
         logger.debug("Removed process %s" % processName)
     except KeyError:
         logger.warning("Trying to remove not existing process..")
Example #4
0
def unit_shortcut_filter(value):
    """
    An utility for getting shortcut for measurement units
    """
    result = units.get(value, {}).get('symbol', '') or units.get(value, {}).get('name', '')
    if not result:
        logger.warning(f"Received unknown unit code: {value}",
        extra={'MESSAGE_ID': 'unknown_unit_code', 'unit_code': value})
    return result
Example #5
0
def checkPhone():
    phone = request.args.get('phone')
    exist = phone_exist(phone)
    if exist[0]:
        logger.warning(f'register failed, phone:{phone} has existed')
        return jsonify(status=False, message="phone has existed", data='')
    else:
        logger.info('phone available')
        return jsonify(status=True, message="phone available", data='')
Example #6
0
def updateUserImg():
    if 'username' not in session:
        logger.warning('user not login')
        return jsonify(status=False, message='user not login', data='')
    username = session.get('username')
    img = request.files['file']
    if img is None:
        return jsonify(status=False, message="img not existed", data='')
    imgPrefix = username
    imgName = imgSave(img, imgPrefix)
    originImg = get_uImg_by_username(username)
    if originImg is not None and originImg != 'default-user.jpg':
        originImgPath = os.path.join(app.instance_path, r'app\static\images',
                                     originImg)
        os.remove(originImgPath)
    update_user_img(username, imgName)
    return jsonify(status=True, message="img upload succeed", data=imgName)
Example #7
0
def create_user(userInfo):
    # 检测账号是否已存在
    logger.info(f'create user: {userInfo}')
    exist = username_exist(userInfo['username'])
    if exist[0]:
        logger.warning('create failed, username exist')
        return False, -1
    # 加密密码
    logger.info(f'{exist}')
    hash_pd = hashlib.sha256(userInfo['password'].encode("utf-8")).hexdigest() 
    logger.info(f"origin: {userInfo['password']}, hashl:{hash_pd}")
    new_user = User(username=userInfo['username'], password=hash_pd, phone=userInfo['phone'], img='default-user.jpg')
    db.session.add(new_user)
    db.session.flush()
    uid = new_user.id
    logger.info(f'user create succeed, uid: {uid}')
    db.session.commit()
    return True, uid
Example #8
0
def updateUserPassword():
    if 'username' not in session:
        logger.warning('user not login')
        return jsonify(status=False, message='user not login', data='')
    username = session.get('username')
    logger.info(f'{username} update password')
    oPassword = request.json.get('o_password', '')
    pdConfirm = user_verification({
        'username': username,
        'password': oPassword
    })
    if not pdConfirm[0]:
        logger.warning('update failed, origin password wrong')
        return jsonify(status=False, message="origin password wrong", data='')
    else:
        nPassword = request.json.get('n_password', '')
        update_user_password(username, nPassword)
        logger.info('update succeed')
        return jsonify(status=True, message="password update succeed", data='')
Example #9
0
 def add_forwarder(self, email, domain, target):
     payload = {
         "action": "create",
         "domain": domain,
         "user": email,
         "email": target
     }
     r = self.make_call('CMD_API_EMAIL_FORWARDERS', payload=payload)
     print(r)
     if r['error'] == ['0']:
         logger.info(f"forwarder created: {email}@{domain} -> {target}")
         return {
             "result": "Success",
             "detail": f"forwarder created: {email}@{domain} -> {target}"
         }
     else:
         logger.warning(f"Forwarder creation failed: {r['details']}")
         return {"result": "Fail", "detail": r['details'][0]}
     return r
Example #10
0
def featurize(dicts, msg_type='person', is_training_data=False):
    """
    Takes in a list of dicts with type msg_type, and attempts to extract useful features
    :param obj_dicts: (list)
        contains one or more dictionaries, each of which is a person-dict payload
    :param msg_type: (str)
        specifies dict type
    :return (dict)
        keys are Person IDs(PIDs) mapped to a list containing every feature value for that person
    """
    pids_to_features = {}

    for msg_info in dicts:

        # Check to make sure each ID is valid, or else skip
        try:
            pid = msg_info.get(msg_type).get('id', {})
            pids_to_features[pid] = {}
        except AttributeError:
            logger.warning('general - missing pid for payload dict: {}'.format(msg_info))
            continue

        """
        Create features for this dict (from degrees, employments, tags, and achievements)
        Note: .update is almost 6x slower than [] = s, but I'm prioritizing legibility here.
        If there's a need for faster run-time, we can time these functions and check scale
        The syntax is so legible, that it's worth it.
        We should try to be efficient, but not go overboard.
        """
        feats_dict = pids_to_features.get(pid)

        feats_dict.update(tag_helpers.featurize_tags(msg_info, msg_type))
        feats_dict.update(education_helpers.featurize_degrees(msg_info))
        feats_dict.update(employment_helpers.featurize_employments(msg_info, is_training_data))
        feats_dict.update(achievement_helpers.featurize_achievements(msg_info))

        # This line is redundant, but including for clarity
        # feats_dict updates the same obj in pids_to_features[pid], but more explicit is safer here
        pids_to_features[pid] = feats_dict

    return pids_to_features
Example #11
0
def register():
    if request.method == 'GET':
        username = request.args.get('username')
        exist = username_exist(username)
        if exist[0]:
            logger.warning(f'register failed, username:{username} has existed')
            return jsonify(status=False,
                           message="username has existed",
                           data='')
        else:
            logger.info('username available')
            return jsonify(status=True, message="username available", data='')
    else:
        userInfo = form2Dict(request.json, {
            'username': '',
            'password': '',
            'phone': ''
        })
        status, uid = create_user(userInfo)
        if status:
            return jsonify(status=True, message="succeed", data={'uid': uid})
        else:
            return jsonify(status=False, message="failed", data='')
Example #12
0
def updateUserPhone():
    if 'username' not in session:
        logger.warning('user not login')
        return jsonify(status=False, message='user not login', data='')
    username = session.get('username')
    logger.info(f'{username} update phone')
    phone = request.json.get('phone', '')
    exist = phone_exist(phone)
    if exist[0]:
        logger.warning('update failed, phone has existed')
        return jsonify(status=False, message="phone has existed", data='')
    else:
        update_user_phone(username, phone)
        logger.warning('update succeed')
        return jsonify(status=True, message="phone update succeed", data='')
Example #13
0
 def killemall(self):
     for process in self.processes.values():
         try:
             process.tabPage.close()
         except Exception as e:
             logger.warning(u"Exception when trying to kill process..\n%s" % e)
Example #14
0
def user_session_check():
    if 'username' not in session:
        logger.warning('user not login')
        return jsonify(status=False, message='user not login', data='')
    else:
        return None
Example #15
0
    def ep(cls, ep_id: int, url: str):
        db_session = Session()
        try:
            with requests.Session() as http_client:
                r = http_client.get(url)
                initial_state_dict = get_initial_state_from_html(r.text)
                if initial_state_dict:
                    initial_state = PlayerPageInitialState.parse_obj(
                        initial_state_dict)
                else:
                    logger.error("can't get initial state from url {}", url)
                    return

                ep = db_session.query(
                    sa.Ep).filter(sa.Ep.ep_id == ep_id).first()
                if ep is None:
                    logger.warning("not fount episode {} with submit url {}",
                                   ep_id, url)
                    return
                upsert_bilibili_ep(
                    db_session,
                    {
                        "ep_id": ep_id,
                        "source_ep_id": initial_state.epInfo.ep_id,
                        "subject_id": ep.subject_id,
                        "title": initial_state.epInfo.title,
                    },
                )
                logger.info("upsert BilibiliEpisode with kwargs {{!r}}".format(
                    source_ep_id=ep_id,
                    ep_id=initial_state.epInfo.ep_id,
                    subject_id=ep.subject_id,
                ))

                season_id = initial_state.mediaInfo.season_id
                o = (db_session.query(sa.BangumiBilibili).filter(
                    sa.BangumiBilibili.season_id == season_id,
                    sa.BangumiBilibili.subject_id == ep.subject_id,
                    sa.BangumiBilibili.media_id ==
                    initial_state.mediaInfo.media_id,
                ).first())
                if o is None:
                    logger.info(
                        "upsert BilibiliBangumi<{!r}>",
                        {
                            "media_id": initial_state.mediaInfo.media_id,
                            "season_id": initial_state.mediaInfo.season_id,
                            "subject_id": ep.subject_id,
                        },
                    )
                    upsert_bilibili_bangumi(
                        db_session,
                        {
                            "media_id": initial_state.mediaInfo.media_id,
                            "season_id": initial_state.mediaInfo.season_id,
                            "subject_id": ep.subject_id,
                            "title": initial_state.mediaInfo.title,
                        },
                    )
        except Exception:
            db_session.rollback()
            logger.exception(
                f"can't get media info for subject_id {ep_id}, url <{url}>")
            raise
        else:
            db_session.commit()
        finally:
            db_session.close()