Beispiel #1
0
def instagram_retrieve_photos(stream, since):
    now = datetime.utcnow()
    token = (stream.oauth_token, stream.oauth_token_secret)
    query = "users/{}/media/recent".format(stream.foreign_key)
    data = {
        "min_timestamp": int((since - datetime(1970, 1, 1)).total_seconds()),
        "access_token": token[0]
    }
    resp = instagram.get(query, data=data, token=token)
    more = True
    successful = False
    while resp.status == 200 and more:
        for photo in resp.data["data"]:
            create_instagram_photo(photo, stream)
        successful = True
        if resp.data["pagination"]:
            resp = instagram.get(resp.data["pagination"]["next_url"],
                                 token=token)
        else:
            more = False
        sleep(1)  # do not spam the api
    if resp.status != 200:
        successful = False
        app.logger.warning("Response code: {}; data: {}".format(
            resp.status, resp.data))
    if successful:
        stream.last_checked = now
        db.session.add(stream)
    db.session.commit()
    return resp.status
Beispiel #2
0
def instagram_retrieve_photos(stream, since):
    now = datetime.utcnow()
    token = (stream.oauth_token, stream.oauth_token_secret)
    query = "users/{}/media/recent".format(stream.foreign_key)
    data = {"min_timestamp" : int((since - datetime(1970, 1, 1)).total_seconds()),
            "access_token" : token[0]}
    resp = instagram.get(query, data=data, token=token)
    more = True
    successful = False
    while resp.status == 200 and more:
        for photo in resp.data["data"]:
            create_instagram_photo(photo, stream)
        successful = True
        if resp.data["pagination"]:
            resp = instagram.get(resp.data["pagination"]["next_url"], token=token)
        else:
            more = False
        sleep(1) # do not spam the api
    if resp.status != 200:
        successful = False
        app.logger.warning("Response code: {}; data: {}".format(resp.status, resp.data))
    if successful:
        stream.last_checked = now
        db.session.add(stream)
    db.session.commit()
    return resp.status
Beispiel #3
0
def instagram_metadata(stream, username=False):
    token = (stream.oauth_token, stream.oauth_token_secret)
    # build the query
    query = "users/{}".format(stream.foreign_key)
    # make the call and get the response
    resp = instagram.get(query, token=token, data={"access_token" : token[0]})

    if resp.status == 200:
        if username:
            return resp.data["data"]["username"]
        return resp.data["data"]["full_name"] or resp.data["data"]["username"]
    app.logger.error("Error in instagram_metadata, {}, {}".format(resp.status, resp.data))
    #abort(502)
    return "[instagram error]"
Beispiel #4
0
def instagram_metadata(stream, username=False):
    token = (stream.oauth_token, stream.oauth_token_secret)
    # build the query
    query = "users/{}".format(stream.foreign_key)
    # make the call and get the response
    resp = instagram.get(query, token=token, data={"access_token": token[0]})

    if resp.status == 200:
        if username:
            return resp.data["data"]["username"]
        return resp.data["data"]["full_name"] or resp.data["data"]["username"]
    app.logger.error("Error in instagram_metadata, {}, {}".format(
        resp.status, resp.data))
    #abort(502)
    return "[instagram error]"