コード例 #1
0
def getWechat():
    '''
    控制最新的wechat
    '''
    result = list(pg.select('wechat_dead_line'))
    if result:
        wechat_dead_line = result[0]
        now = datetime.datetime.now()
        if wechat_dead_line.access_token_expires_at is not None and now < wechat_dead_line.access_token_expires_at and now < wechat_dead_line.jsapi_ticket_expires_at:
            conf = WechatConf(
                token=token,
                appid=appid,
                appsecret=appsecret,
                encrypt_mode='compatible',
                encoding_aes_key=encoding_aes_key,
                jsapi_ticket=wechat_dead_line.jsapi_ticket,
                jsapi_ticket_expires_at=time_bz.datetimeToTimestamp(wechat_dead_line.jsapi_ticket_expires_at),
                access_token=wechat_dead_line.access_token,
                access_token_expires_at=time_bz.datetimeToTimestamp(wechat_dead_line.access_token_expires_at),
            )
            wechat = WechatBasic(conf=conf)
        else:
            wechat, access_token, access_token_expires_at, jsapi_ticket, jsapi_ticket_expires_at = getNewWechatInfo()
            pg.update('wechat_dead_line', where='1=1', access_token=access_token, access_token_expires_at=access_token_expires_at, jsapi_ticket=jsapi_ticket, jsapi_ticket_expires_at=jsapi_ticket_expires_at)
    else:
        wechat, access_token, access_token_expires_at, jsapi_ticket, jsapi_ticket_expires_at = getNewWechatInfo()
        pg.insert('wechat_dead_line', access_token=access_token, access_token_expires_at=access_token_expires_at, jsapi_ticket=jsapi_ticket, jsapi_ticket_expires_at=jsapi_ticket_expires_at)
    return wechat
コード例 #2
0
ファイル: wechat_oper.py プロジェクト: bigzhu/follow_center_p
def getWechat():
    '''
    控制最新的wechat
    '''
    result = list(pg.select('wechat_dead_line'))
    if result:
        wechat_dead_line = result[0]
        now = datetime.datetime.now()
        if wechat_dead_line.access_token_expires_at is not None and now < wechat_dead_line.access_token_expires_at and now < wechat_dead_line.jsapi_ticket_expires_at:
            wechat = WechatBasic(
                jsapi_ticket=wechat_dead_line.jsapi_ticket,
                jsapi_ticket_expires_at=time_bz.datetimeToTimestamp(
                    wechat_dead_line.jsapi_ticket_expires_at),
                access_token=wechat_dead_line.access_token,
                access_token_expires_at=time_bz.datetimeToTimestamp(
                    wechat_dead_line.access_token_expires_at),
                token=token,
                appid=appid,
                appsecret=appsecret)
        else:
            wechat, access_token, access_token_expires_at, jsapi_ticket, jsapi_ticket_expires_at = getNewWechatInfo(
            )
            pg.update('wechat_dead_line',
                      where='1=1',
                      access_token=access_token,
                      access_token_expires_at=access_token_expires_at,
                      jsapi_ticket=jsapi_ticket,
                      jsapi_ticket_expires_at=jsapi_ticket_expires_at)
    else:
        wechat, access_token, access_token_expires_at, jsapi_ticket, jsapi_ticket_expires_at = getNewWechatInfo(
        )

        pg.insert('wechat_dead_line',
                  access_token=access_token,
                  access_token_expires_at=access_token_expires_at,
                  jsapi_ticket=jsapi_ticket,
                  jsapi_ticket_expires_at=jsapi_ticket_expires_at)
    return wechat
コード例 #3
0
def getWechat():
    '''
    控制最新的wechat
    '''
    result = list(pg.select('wechat_dead_line'))
    if result:
        wechat_dead_line = result[0]
        now = datetime.datetime.now()
        if now < wechat_dead_line.access_token_expires_at and now < wechat_dead_line.jsapi_ticket_expires_at:
            wechat = WechatBasic(jsapi_ticket=wechat_dead_line.jsapi_ticket,
                                 jsapi_ticket_expires_at=time_bz.datetimeToTimestamp(wechat_dead_line.jsapi_ticket_expires_at),
                                 access_token=wechat_dead_line.access_token,
                                 access_token_expires_at=time_bz.datetimeToTimestamp(wechat_dead_line.access_token_expires_at),
                                 token=token,
                                 appid=appid,
                                 appsecret=appsecret)
        else:
            wechat, access_token, access_token_expires_at, jsapi_ticket, jsapi_ticket_expires_at = getNewWechatInfo()
            pg.update('wechat_dead_line', where='1=1', access_token=access_token, access_token_expires_at=access_token_expires_at, jsapi_ticket=jsapi_ticket, jsapi_ticket_expires_at=jsapi_ticket_expires_at)
    else:
        wechat, access_token, access_token_expires_at, jsapi_ticket, jsapi_ticket_expires_at = getNewWechatInfo()

        pg.insert('wechat_dead_line', access_token=access_token, access_token_expires_at=access_token_expires_at, jsapi_ticket=jsapi_ticket, jsapi_ticket_expires_at=jsapi_ticket_expires_at)
    return wechat
コード例 #4
0
ファイル: public_db.py プロジェクト: xdliuyong/follow_center
def getMessages(user_id=None, god_name=None, type=None, id=None, limit=50, offset=None, last_time=None):
    '''
    create by bigzhu at 15/07/14 15:11:44 查出我 Follow 的用户的twitter message
    modify by bigzhu at 15/07/17 01:39:21 过于复杂,合并sql,根据god_name也可以查
    modify by bigzhu at 15/07/19 15:30:55 可以根据type和id查出某一条记录
    modify by bigzhu at 15/07/22 12:49:35 limit 设定取多少条
    modify by bigzhu at 15/08/13 17:20:15 建立view,查询简化得不行
    modify by bigzhu at 15/08/16 18:09:53 支持对last_time的查询
    '''
    sql = "select * from messages"
    if last_time is not None:
        last_time = time_bz.datetimeToTimestamp(last_time)  # 转为timestamp
        last_time = last_time - 30*10*10  # 后30分钟的也取出来
        where = ' where created_at>to_timestamp(%s)' % last_time
        sql += where

    if type and id:
        sql = '''
        select * from (%s) s
        where s.m_type='%s'
        and s.id = %s
        ''' % (sql, type, id)
    if god_name:
        sql = '''
        select * from (%s) s
        where lower(s.user_name)=lower('%s')
        ''' % (sql, god_name)
    if user_id:
        sql = '''
        select * from (%s) s
        where lower(s.user_name) in (
            select lower(user_name) from user_info where id in(
                    select god_id from follow_who where user_id=%s
                )
        )
        ''' % (sql, user_id)
    if limit:
        sql = '''
        select * from (%s) s
        limit %s
        ''' % (sql, limit)
    if offset:
        sql = sql + ' offset %s' % offset
    return pg.query(sql)