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
    def get(self):
        self.set_header("Content-Type", "application/json")
        available_card_numbers = pg.select("available_card_numbers")

        self.write(
            json.dumps({"error": "0", "available_card_numbers": available_card_numbers}, cls=public_bz.ExtEncoder)
        )
예제 #3
0
def getUser(user_name):
    '''
    modify by bigzhu at 15/07/31 16:41:16 api找用户时是按专注度来排序的,名字绝对匹配的未必是第一位, 从10个里面找
    '''
    users = list(pg.select('instagram_user', where="lower(username)=lower('%s')" % user_name))
    if users:
        return users[0]
    else:
        user = None
        for this_user in api.user_search(user_name, 10):
            if this_user.username.lower() == user_name.lower():
                user = this_user
                break
        #如果没有这个用户
        if user is None:
            public_db.delNoName('instagram', user_name)
        #user = api.user_search(user_name, 1)[0]
        user = api.user(user.id)

        db_user = storage()
        db_user.id = user.id
        db_user.username = user.username
        db_user.full_name = user.full_name
        db_user.profile_picture = user.profile_picture
        db_user.bio = user.bio
        db_user.website = user.website
        db_user.counts = json.dumps(user.counts)
        pg.insert('instagram_user', **db_user)
        #db_bz.insertIfNotExist(pg, 'instagram_user', db_user, "id=%s" % db_user.id)
        return getUser(user_name)
예제 #4
0
def check():
    '''
    create by bigzhu at 15/07/10 14:46:58
        从 user_info 取出 twitter url 来检查
    '''
    users = pg.select('user_info', what='twitter', where='twitter is not null')
    for user in users:
        if user.twitter and user.twitter != '':
            print 'check twitter %s' % user.twitter
            checkUserMessage(user.twitter)
예제 #5
0
def getTwitterUser(name):
    '''
    create by bigzhu at 15/07/17 15:09:56 twitter用户
    '''
    result = list(pg.select('twitter_user', where="lower(screen_name)=lower('%s')" % name))
    count = len(result)
    if count > 1:
        raise Exception('twitter_user screen_name=%s count=%s' % (name, count))
    if count == 1:
        return result[0]
예제 #6
0
def getGithubUser(name):
    '''
    create by bigzhu at 15/07/17 15:10:23 github 用户
    '''
    result = list(pg.select('github_user', where="lower(login)=lower('%s')" % name))
    count = len(result)
    if count > 1:
        raise Exception('github_user screen_name=%s count=%s' % (name, count))
    if count == 1:
        return result[0]
예제 #7
0
def getInstagramUser(name):
    '''
    create by bigzhu at 15/07/31 15:00:19 Instagram
    '''
    result = list(pg.select('instagram_user', where="lower(username)=lower('%s')" % name))
    count = len(result)
    if count > 1:
        raise Exception('instagram_user username=%s count=%s' % (name, count))
    if count == 1:
        return result[0]
예제 #8
0
def getGithubUser(name):
    '''
    create by bigzhu at 15/07/17 15:10:23 github 用户
    '''
    result = list(
        pg.select('github_user', where="lower(login)=lower('%s')" % name))
    count = len(result)
    if count > 1:
        raise Exception('github_user screen_name=%s count=%s' % (name, count))
    if count == 1:
        return result[0]
예제 #9
0
def check(user_name=None):
    '''
    '''
    where = '''
        tumblr is not null and tumblr!=''
    '''
    if user_name:
        where += " and tumblr='%s'" % user_name
    users = pg.select('user_info', what='tumblr', where=where)
    for user in users:
        print 'check tumblr %s' % user.tumblr
        main(user.tumblr)
예제 #10
0
def getInstagramUser(name):
    '''
    create by bigzhu at 15/07/31 15:00:19 Instagram
    '''
    result = list(
        pg.select('instagram_user',
                  where="lower(username)=lower('%s')" % name))
    count = len(result)
    if count > 1:
        raise Exception('instagram_user username=%s count=%s' % (name, count))
    if count == 1:
        return result[0]
예제 #11
0
def getTwitterUser(name):
    '''
    create by bigzhu at 15/07/17 15:09:56 twitter用户
    '''
    result = list(
        pg.select('twitter_user',
                  where="lower(screen_name)=lower('%s')" % name))
    count = len(result)
    if count > 1:
        raise Exception('twitter_user screen_name=%s count=%s' % (name, count))
    if count == 1:
        return result[0]
 def post(self):
     self.set_header("Content-Type", "application/json")
     parm = json.loads(self.request.body)
     openid = self.get_secure_cookie("openid")
     openid = checkOpenid(openid)
     print openid
     card_number = parm["card_number"]
     is_in = pg.select("available_card_numbers", where=" card_number='%s'" % card_number)
     if not is_in:
         raise Exception("卡号:%s 不是可以冲值的油卡,请联系英茂客服核实!" % card_number)
     parm["openid"] = openid
     pg.insert("bind_card_info", **parm)
     self.write(json.dumps({"error": "0"}, cls=public_bz.ExtEncoder))
예제 #13
0
def check():
    '''
    create by bigzhu at 15/07/31 14:28:30
    '''
    users = pg.select('user_info', what='instagram', where="instagram is not null and instagram!=''")
    print len(users)
    for user in users:
        if user.instagram and user.instagram != '':
            print 'check instagram %s' % user.instagram
            try:
                getMedia(user.instagram)
            except Exception:
                print public_bz.getExpInfoAll()
예제 #14
0
def check(user_name=None):
    '''
    create by bigzhu at 15/07/10 14:46:58
        从 user_info 取出 twitter url 来检查
    create by bigzhu at 15/08/23 23:07:22 加入user_name
    '''
    where = "twitter is not null"
    if user_name:
        where += " and twitter='%s'" % user_name
    users = pg.select('user_info', what='twitter', where=where)
    for user in users:
        if user.twitter and user.twitter != '':
            print 'check twitter %s' % user.twitter
            checkUserMessage(user.twitter)
예제 #15
0
def check(user_name=None):
    '''
    create by bigzhu at 15/07/10 14:46:58
        从 user_info 取出 twitter url 来检查
    create by bigzhu at 15/08/23 23:07:22 加入user_name
    '''
    where = "twitter is not null"
    if user_name:
        where += " and twitter='%s'" % user_name
    users = pg.select('user_info', what='twitter', where=where)
    for user in users:
        if user.twitter and user.twitter != '':
            print 'check twitter %s' % user.twitter
            checkUserMessage(user.twitter)
예제 #16
0
def check(user_name=None):
    '''
    create by bigzhu at 15/07/31 14:28:30
    modify by bigzhu at 15/08/23 22:30:25 可以指定查某个user_name
    '''
    where = '''
        instagram is not null and instagram!=''
    '''
    if user_name:
        where += " and instagram='%s'" % user_name
    users = pg.select('user_info', what='instagram', where=where)
    for user in users:
        if user.instagram and user.instagram != '':
            print 'check instagram %s' % user.instagram
            main(user.instagram)
예제 #17
0
def getWechatExt():
    '''
    判断wechat ext是否过期
    '''
    result = list(pg.select('wechat_dead_line'))
    if result:
        wechat_dead_line = result[0]
        wechat_ext = WechatExt(user_name, password,
                               appid=appid,
                               token=wechat_dead_line.token,
                               cookies=wechat_dead_line.cookies
                           )
    else:
        wechat_ext = getNewWechatExtInfo()
    return wechat_ext
예제 #18
0
def check(user_name=None):
    '''
    create by bigzhu at 15/07/31 14:28:30
    modify by bigzhu at 15/08/23 22:30:25 可以指定查某个user_name
    '''
    where = '''
        instagram is not null and instagram!=''
    '''
    if user_name:
        where += " and instagram='%s'" % user_name
    users = pg.select('user_info', what='instagram', where=where)
    for user in users:
        if user.instagram and user.instagram != '':
            print 'check instagram %s' % user.instagram
            main(user.instagram)
예제 #19
0
def getWechatExt():
    '''
    判断wechat ext是否过期
    '''
    result = list(pg.select('wechat_dead_line'))
    if result:
        wechat_dead_line = result[0]
        wechat_ext = WechatExt(user_name, password,
                               appid=appid,
                               token=wechat_dead_line.token,
                               cookies=wechat_dead_line.cookies
                               )
    else:
        wechat_ext = getNewWechatExtInfo()
    return wechat_ext
예제 #20
0
def saveUserCheckNew(blogs):
    '''
    create by bigzhu at 15/09/05 11:57:11
    '''
    user = blogs['blog']
    user_name = user['name']
    where = "name='%s'" % user_name
    result = list(pg.select('tumblr_user', where=where))
    if result:
        if result[0].updated == user['updated']:  # 如果没有更新过,就不用继续了
            print user_name, ' no update'
            # return
            pass
    pg.insertOrUpdate(pg, 'tumblr_user', user, where)
    blogs = blogs['posts']
    saveBlogs(user_name, blogs, offset=20)
예제 #21
0
def getUser(user_name, always_check=False):
    '''
    modify by bigzhu at 15/07/31 16:41:16 api找用户时是按专注度来排序的,名字绝对匹配的未必是第一位, 从10个里面找
    '''
    users = list(
        pg.select('instagram_user',
                  where="lower(username)=lower('%s')" % user_name))
    if users and not always_check:
        return users[0]
    else:
        user = None
        try:
            for this_user in api.user_search(user_name, 10):
                if this_user.username.lower() == user_name.lower():
                    user = this_user
                    break
        except instagram.bind.InstagramClientError:
            print public_bz.getExpInfoAll()
            return
        # 如果没有这个用户
        if user is None:
            public_db.delNoName('instagram', user_name)
            return
        try:
            user = api.user(user.id)
        except (instagram.bind.InstagramAPIError,
                instagram.bind.InstagramClientError):
            # 通常是没有访问权限
            print public_bz.getExpInfoAll()
            public_db.delNoName('instagram', user_name)
            return

        db_user = storage()
        db_user.id_str = user.id
        db_user.username = user.username
        db_user.full_name = user.full_name
        db_user.profile_picture = user.profile_picture
        db_user.bio = user.bio
        db_user.website = user.website
        db_user.counts = json.dumps(user.counts)
        #pg.insert('instagram_user', **db_user)
        pg.insertOrUpdate(pg, 'instagram_user', db_user,
                          "id_str='%s'" % db_user.id_str)
        #db_bz.insertIfNotExist(pg, 'instagram_user', db_user, "id=%s" % db_user.id)
        return getUser(user_name)
예제 #22
0
def getUser(user_name, always_check=False):
    '''
    modify by bigzhu at 15/07/31 16:41:16 api找用户时是按专注度来排序的,名字绝对匹配的未必是第一位, 从10个里面找
    '''
    users = list(pg.select('instagram_user', where="lower(username)=lower('%s')" % user_name))
    if users and not always_check:
        return users[0]
    else:
        user = None
        try:
            for this_user in api.user_search(user_name, 10):
                if this_user.username.lower() == user_name.lower():
                    user = this_user
                    break
        except instagram.bind.InstagramClientError:
            print public_bz.getExpInfoAll()
            return
        # 如果没有这个用户
        if user is None:
            public_db.delNoName('instagram', user_name)
            return
        try:
            user = api.user(user.id)
        except (instagram.bind.InstagramAPIError, instagram.bind.InstagramClientError):
            # 通常是没有访问权限
            print public_bz.getExpInfoAll()
            public_db.delNoName('instagram', user_name)
            return

        db_user = storage()
        db_user.id_str = user.id
        db_user.username = user.username
        db_user.full_name = user.full_name
        db_user.profile_picture = user.profile_picture
        db_user.bio = user.bio
        db_user.website = user.website
        db_user.counts = json.dumps(user.counts)
        #pg.insert('instagram_user', **db_user)
        pg.insertOrUpdate(pg, 'instagram_user', db_user, "id_str='%s'" % db_user.id_str)
        #db_bz.insertIfNotExist(pg, 'instagram_user', db_user, "id=%s" % db_user.id)
        return getUser(user_name)
예제 #23
0
def saveUser(id, url):
    '''
    create by bigzhu at 15/07/15 21:27:19 保存github信息
    create by bigzhu at 15/07/22 16:17:37 fix bug, not return id
    '''
    if list(pg.select('github_user', where='id=%s' % id)):
        return id
    else:
        r = requests.get(url)
        user = storage(r.json())
        del user.url
        del user.followers_url
        del user.following_url
        del user.gists_url
        del user.starred_url
        del user.subscriptions_url
        del user.organizations_url
        del user.repos_url
        del user.events_url
        del user.received_events_url
        del user.type
        return db_bz.insertIfNotExist(pg, 'github_user', user)
예제 #24
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
예제 #25
0
def saveUser(id, url):
    '''
    create by bigzhu at 15/07/15 21:27:19 保存github信息
    create by bigzhu at 15/07/22 16:17:37 fix bug, not return id
    '''
    if list(pg.select('github_user', where='id=%s' % id)):
        return id
    else:
        r = requests.get(url)
        user = storage(r.json())
        print user
        if hasattr(user, 'url'):
            del user.url
        del user.followers_url
        del user.following_url
        del user.gists_url
        del user.starred_url
        del user.subscriptions_url
        del user.organizations_url
        del user.repos_url
        del user.events_url
        del user.received_events_url
        del user.type
        return db_bz.insertIfNotExist(pg, 'github_user', user)
예제 #26
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:
            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
예제 #27
0
def getWechatUserByOpenid(openid):
    '''
    create by bigzhu at 15/04/04 12:48:58 根据 openid 来查询微信用户
    '''
    return list(pg.select('wechat_user', where="openid='%s'" % openid))
예제 #28
0
def getWechatUserByOpenid(openid):
    """
    create by bigzhu at 15/04/04 12:48:58 根据 openid 来查询微信用户
    """
    return list(pg.select("wechat_user", where="openid='%s'" % openid))
예제 #29
0
def getLast(user_id):
    if user_id is None:
        return
    result = list(pg.select("last", where="user_id=%s" % user_id))
    if result:
        return result[0]
예제 #30
0
def getWechatUserByOpenid(openid):
    '''
    create by bigzhu at 15/04/04 12:48:58 根据 openid 来查询微信用户
    '''
    return list(pg.select('wechat_user', where="openid='%s'" % openid))
예제 #31
0
def getLast(user_id):
    if user_id is None:
        return
    result = list(pg.select('last', where="user_id=%s" % user_id))
    if result:
        return result[0]
예제 #32
0
def getLast(user_id):
    result = list(pg.select('last', where="user_id=%s" % user_id))
    if result:
        return result[0]