Esempio n. 1
0
    def fetch_user(token, user_id):
        key = Vk_user.DB_KEY(user_id)
        if key in db.dict():
            user = Vk_user.from_json(db.get(key))
            if not user.outdated():
                return user

        params = {'user_ids': user_id, 'fields': 'photo_400_orig'}
        return Vk_user.from_api(token, params)
Esempio n. 2
0
    def fetch_user(token, user_id):
        key = Vk_user.DB_KEY(user_id)
        if key in db.dict():
            user = Vk_user.from_json(db.get(key))
            if not user.outdated():
                return user

        params = {'user_ids':user_id, 'fields':'photo_400_orig'}
        return Vk_user.from_api(token, params)
Esempio n. 3
0
    def fetch(token, chat_id):
        key = Vk_chat.DB_KEY(chat_id)
        if key in db.dict():
            chat = Vk_chat.from_json(db.get(key))
            if not chat.outdated():
                return chat

        params = {'chat_id':chat_id,
                'fields':'first_name, last_name, photo_400_orig'}
        return Vk_chat.from_api(token, params)
Esempio n. 4
0
    def all_from_db():
        clients = dict()
        for client_key in db.dict():
            if not re.match('Client-.+', client_key):
                continue

            client_json = db.get(client_key)
            client = Client.from_json(client_json)
            if client.vk_user.should_fetch():
                client.load_vk_user(client.vk_token)

            clients[client.chat_id] = client

        print('Restored clients from db: ' + str(clients))
        return clients
Esempio n. 5
0
    def all_from_db():
        clients = dict()
        for client_key in db.dict():
            if not re.match('Client-.+', client_key):
                continue

            client_json = db.get(client_key)
            client = Client.from_json(client_json)
            if client.vk_user.should_fetch():
                client.load_vk_user(client.vk_token)

            clients[client.chat_id] = client

        print('Restored clients from db: ' + str(clients))
        return clients