Beispiel #1
0
def flickr_import(app):
    """Import the latest photos to redis."""
    from flask import g
    from rdrei.utils import flickr

    with _prepared_context(app):
        for photo in flickr.get_recent_profile_photos():
            # Check if the entry exists.
            key = 'photo:' + photo['id']
            print("Current Key: ", key)
            if g.db.exists(key):
                print("Came across already known photo.")
                break

            for subkey in ('title', 'farm', 'server', 'secret', 'id',
                           'original_secret', 'height_o', 'width_o',
                           'height_m', 'width_m'):
                # We need to double-check, because flickr is very picky about
                # what and when to include attributes.
                if subkey in photo:
                    g.db.hset(key, subkey, photo[subkey])

            # Save the tags to subsets
            for tag in photo['tags'].split(' '):
                g.db.sadd('phototags:' + tag, photo['id'])
                # And don't forget to keep track of the tags itself.
                g.db.sadd('phototags', tag)

            g.db.sadd('photos', photo['id'])
Beispiel #2
0
def test_recent():
    """Test if we can get the most recent photos"""
    photo_counter = 0
    for photo in flickr.get_recent_profile_photos(TEST_USER_ID, per_page=10, max_photos=10):
        photo_counter += 1
        assert "title" in photo
        assert "tags" in photo

    eq_(photo_counter, 10)