Beispiel #1
0
def flickr_retrieve_photos(stream, since):
    now = datetime.utcnow()
    token = (stream.oauth_token, stream.oauth_token_secret)
    # build the query
    query = {
        "method": "flickr.people.getPhotos",
        "user_id": stream.foreign_key,
        "extras":
        "date_upload, date_taken, description, media, tags, url_h, url_k",
        "format": "json",
        "nojsoncallback": 1,
        "min_upload_date": (since - datetime(1970, 1, 1)).total_seconds()
    }
    # make the call and get the response
    resp = flickr.get("", data=query, token=token)
    successful = False
    page = None
    pages = None
    if isinstance(resp.data, str):
        resp.data = json.loads(resp.data)
    # on successful response get the paging data
    if resp.status == 200 and resp.data["stat"] == "ok":
        page = int(resp.data["photos"]["page"])
        pages = int(resp.data["photos"]["pages"])
    more = True
    # do the page dance!
    while resp.status == 200 and more and resp.data["stat"] == "ok":
        for photo in resp.data["photos"]["photo"]:
            photo_visible = str(photo["ispublic"]) == "1" or str(
                photo["isfriend"]) == "1" or str(photo["isfamily"]) == "1"
            if photo_visible and "digestif:ignore=true" not in photo["tags"]:
                flickrphoto = create_flickr_photo(photo, stream)
        query["page"] = page + 1
        if page >= pages:
            more = False
        else:
            # dance dance dance
            resp = flickr.get("", data=query, token=token)
            if isinstance(resp.data, str):
                resp.data = json.loads(resp.data)
            if resp.status == 200 and resp.data["stat"] == "ok":
                page = int(resp.data["photos"]["page"])
                pages = int(resp.data["photos"]["pages"])
        successful = True
        sleep(1)  # do not spam the api
    if resp.status != 200 or resp.data["stat"] != "ok":
        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 flickr_retrieve_photos(stream, since):
    now = datetime.utcnow()
    token = (stream.oauth_token, stream.oauth_token_secret)
    # build the query
    query = {"method" : "flickr.people.getPhotos",
             "user_id" : stream.foreign_key,
             "extras" : "date_upload, date_taken, description, media, tags, url_h, url_k",
             "format" : "json",
             "nojsoncallback" : 1,
             "min_upload_date" :  (since - datetime(1970, 1, 1)).total_seconds()}
    # make the call and get the response
    resp = flickr.get("", data=query, token=token)
    successful = False
    page = None
    pages = None
    if isinstance(resp.data, str):
        resp.data = json.loads(resp.data)
    # on successful response get the paging data
    if resp.status == 200 and resp.data["stat"] == "ok":
        page = int(resp.data["photos"]["page"])
        pages = int(resp.data["photos"]["pages"])
    more = True
    # do the page dance!
    while resp.status == 200 and more and resp.data["stat"] == "ok":
        for photo in resp.data["photos"]["photo"]:
            photo_visible = str(photo["ispublic"]) == "1" or str(photo["isfriend"]) == "1" or str(photo["isfamily"]) == "1"
            if photo_visible and "digestif:ignore=true" not in photo["tags"]:
                flickrphoto = create_flickr_photo(photo, stream)
        query["page"] = page + 1
        if page >= pages:
            more = False
        else:
            # dance dance dance
            resp = flickr.get("", data=query, token=token)
            if isinstance(resp.data, str):
                resp.data = json.loads(resp.data)
            if resp.status == 200 and resp.data["stat"] == "ok":
                page = int(resp.data["photos"]["page"])
                pages = int(resp.data["photos"]["pages"])
        successful = True
        sleep(1) # do not spam the api
    if resp.status != 200 or resp.data["stat"] != "ok":
        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 flickr_metadata(stream):
    token = (stream.oauth_token, stream.oauth_token_secret)
    # build the query
    query = {"method" : "flickr.people.getInfo",
             "user_id" : stream.foreign_key,
             "format" : "json",
             "nojsoncallback" : 1}
    # make the call and get the response
    resp = flickr.get("", data=query, token=token)
    if isinstance(resp.data, str):
        try:
            resp.data = json.loads(resp.data)
        except ValueError:
            app.logger.warn("Could not decode json: {}".format(resp.data))
            return "[flickr error]"
    if resp.status == 200 and resp.data["stat"] == "ok":
        return resp.data["person"]["realname"]["_content"] or resp.data["person"]["username"]
    app.logger.error("Error in flickr_metadata, {}, {}".format(resp.status, resp.data))
    #abort(502)
    return "[flickr error]"
Beispiel #4
0
def flickr_metadata(stream):
    token = (stream.oauth_token, stream.oauth_token_secret)
    # build the query
    query = {
        "method": "flickr.people.getInfo",
        "user_id": stream.foreign_key,
        "format": "json",
        "nojsoncallback": 1
    }
    # make the call and get the response
    resp = flickr.get("", data=query, token=token)
    if isinstance(resp.data, str):
        try:
            resp.data = json.loads(resp.data)
        except ValueError:
            app.logger.warn("Could not decode json: {}".format(resp.data))
            return "[flickr error]"
    if resp.status == 200 and resp.data["stat"] == "ok":
        return resp.data["person"]["realname"]["_content"] or resp.data[
            "person"]["username"]
    app.logger.error("Error in flickr_metadata, {}, {}".format(
        resp.status, resp.data))
    #abort(502)
    return "[flickr error]"