Exemplo n.º 1
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.º 2
0
def get_wechat_access_token():
    """获取 access_token"""
    access_token = redis.get("wechat:access_token")
    if access_token:
        return access_token
    else:
        app.logger.warning(u"获取 access_token 缓存失败")
        return None
Exemplo n.º 3
0
def get_next_passes(lat, lng, elevation=30, n=15, visible_only=False):

    tle = redis.get('iss:tle').decode()

    if not tle:
        return []

    tle0, tle1, tle2 = json.loads(tle)

    sat = ephem.readtle(str(tle0), str(tle1), str(tle2))

    observer = ephem.Observer()
    observer.lat = lat
    observer.lon = lng
    observer.elevation = elevation

    observer.pressure = 0
    observer.horizon = '10'

    sun = ephem.Sun()

    passes = []

    for i in range(n):
        next_pass = observer.next_pass(sat)
        p = EphemPass(*next_pass)

        t = p.rise_time
        visible = False

        while t < p.set_time:
            t += ephem.second
            observer.date = t

            sat.compute(observer)
            sun.compute(observer)

            if not sat.eclipsed and -18 < degrees(sun.alt) < -6:
                visible = True
                break

        passes.append({
            'risetime':
            p.rise_time,
            'duration':
            datetime.timedelta(p.set_time - p.rise_time).seconds,
            'visible':
            visible
        })

        observer.date = p.set_time + (5 * ephem.minute)

    if visible_only:
        return filter(lambda p: p['visible'], passes)

    return passes
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 get_msg():
    msg = redis.get('follow:msg').replace('\n', '</br>')
    return msg
Exemplo n.º 6
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)
Exemplo n.º 7
0
    def is_over_limit(self):
        current_value = redis.get(self.key)
        if current_value is None:
            return False

        return int(current_value) > self.rate
Exemplo n.º 8
0
def event_resp():
    """关注/取消关注事件回复"""
    app.logger.info('--------用户关注------')
    response = wechat.response_text(redis.get('follow:msg'))
    app.logger.info(response)
    return response