Exemplo n.º 1
0
def authorized():
    """get openid"""
    code = request.args.get("code")
    if not code:
        return "ERR_INVALID_CODE", 400
    wl = wechat_login(app.config['APP_ID'], app.config['APP_SECRET'])
    data = wl.access_token(code)
    app.logger.info(data)
    openid = data['openid']
    access_token = data['access_token']
    wechat_user = wl.user_info(access_token, openid)
    app.logger.info(wechat_user)
    account = User.query.filter_by(openid=wechat_user['openid']).first()
    if account:
        app.logger.info('----user is in our database---')
    else:
        unionid = ''
        if 'unionid' in wechat_user:
            unionid = wechat_user['unionid']
        account = User(unionid=unionid,
                       openid=wechat_user['openid'],
                       nick_name=str(wechat_user['nickname']),
                       head_img_url=wechat_user['headimgurl'],
                       sex=wechat_user['sex'],
                       is_del=0,
                       is_errands_man=0).save()
    token = str.replace(str(uuid.uuid1()), '-', '')
    redis.set("account:wechat_login:" + token, json.dumps(account.to_json()),
              72000)
    if account.phone:
        return jsonify({'token': token, 'type': 1})
    return jsonify({'token': token, 'type': 0})
Exemplo n.º 2
0
def update_tle():
    logger.info("Updating TLE")

    r = requests.get('http://www.celestrak.com/NORAD/elements/stations.txt')
    lines = [line for line in r.text.split('\n') if line]

    stations = []

    for i in range(0, len(lines), 3):
        stations.append(lines[i:i + 3])

    iss = stations[0]
    redis.set('iss:tle', json.dumps(iss))
Exemplo n.º 3
0
def init_wechat_sdk():
    """初始化微信 SDK"""
    access_token = redis.get("wechat:access_token")
    jsapi_ticket = redis.get("wechat:jsapi_ticket")
    token_expires_at = redis.get("wechat:access_token_expires_at")
    ticket_expires_at = redis.get("wechat:jsapi_ticket_expires_at")
    if access_token and jsapi_ticket and token_expires_at and ticket_expires_at:
        wechat = WechatBasic(appid=app.config['APP_ID'],
                             appsecret=app.config['APP_SECRET'],
                             token=app.config['TOKEN'],
                             access_token=access_token,
                             access_token_expires_at=int(token_expires_at),
                             jsapi_ticket=jsapi_ticket,
                             jsapi_ticket_expires_at=int(ticket_expires_at))
    else:
        wechat = WechatBasic(appid=app.config['APP_ID'],
                             appsecret=app.config['APP_SECRET'],
                             token=app.config['TOKEN'])
        access_token = wechat.get_access_token()
        redis.set("wechat:access_token", access_token['access_token'], 7000)
        redis.set("wechat:access_token_expires_at",
                  access_token['access_token_expires_at'], 7000)
        jsapi_ticket = wechat.get_jsapi_ticket()
        redis.set("wechat:jsapi_ticket", jsapi_ticket['jsapi_ticket'], 7000)
        redis.set("wechat:jsapi_ticket_expires_at",
                  jsapi_ticket['jsapi_ticket_expires_at'], 7000)

    return wechat
Exemplo n.º 4
0
def show_uese_info(openid):
    if redis.get('mark'):
        mark = int(redis.get('mark'))
        redis.set('mark', int(redis.get('mark')) + 1, 30)
    else:
        mark = 0
        redis.set('mark', 1, 30)
    user_info = get_user_info(openid, n=mark)
    if user_info:
        m = [
            '%s \n卧推->%03dkg 硬拉->%03dkg\n深蹲->%03dkg 引体->%03d个\n俯卧撑->%03d个 肩推->%03dkg\n高位下拉->%03dkg\n-------------------------------'
            % (u.regtime.strftime("%Y-%m-%d"), u.benchpress, u.deadlift,
               u.squat, u.ytxs, u.fwc, u.shoulderpress, u.gwxl)
            for u in user_info
        ]
        m.append('30秒继续回复xx 查看更早5条')
    else:
        m = ['没有发现数据', '请核实', '或者等待30S重试']
    return '\n'.join(m)
Exemplo n.º 5
0
def update_wechat_token():
    """刷新微信 token """
    wechat = init_wechat_sdk()
    wechat.grant_token()
    wechat.grant_jsapi_ticket()
    access_token = wechat.get_access_token()
    redis.set("wechat:access_token", access_token['access_token'], 7000)
    redis.set("wechat:access_token_expires_at",
              access_token['access_token_expires_at'], 7000)
    jsapi_ticket = wechat.get_jsapi_ticket()
    redis.set("wechat:jsapi_ticket", jsapi_ticket['jsapi_ticket'], 7000)
    redis.set("wechat:jsapi_ticket_expires_at",
              jsapi_ticket['jsapi_ticket_expires_at'], 7000)
Exemplo n.º 6
0
def kjs():
    '''空教室查询'''
    back = te()
    back = back
    redis.set('kong', json.dumps(back), ex=36000)
    return jsonify(back)
Exemplo n.º 7
0
def ex_follow_up():
    value = request.form.get('value')
    redis.set('follow:msg', value)
    msg = get_msg()
    return render_template('follow/follow.html', msg=msg)
Exemplo n.º 8
0
 def increase(self):
     current_value = redis.get(self.key)
     if current_value is None:
         redis.set(self.key, 1, self.duration)
     else:
         redis.incr(self.key)