Beispiel #1
0
def get_recent_likes(user_id):
    """Find recently liked media"""
    # Find recent likes
    likes = scratch.stalk_likes_in_follows(user_id)
    likes = likes[0:NUM_UNICODE_CHARS]  # Only process up to first 30 items
    # Convert likes to a saveable format
    likes = [models.media.dictionary_from_object(u) for u in likes]
    # Save the liked media
    user_likes_dir = os.path.join(wf().likesdir, user_id + '.json')
    with open(user_likes_dir, 'wb') as likes_file:
        likes_file.write(json.dumps(likes))
    # Download the media
    scratch.download_images(likes, wf().mediadir, resolution='thumbnail')
# Retrive user information from insagram
user = scratch._api.user(user_id)
username = user.username
count_follows = user.counts["follows"]
count_followed_by = user.counts["followed_by"]

# Issue notification that a search is started
Notifier.notify(
    title="Instastalk",
    subtitle="User: {user}".format(user=username),
    message="Searching {follows} follows for likes".format(follows=count_follows),
)

# Find recent likes
likes = scratch.stalk_likes_in_follows(user_id)
likes_recent = likes[0:MAX_LIKED_MEDIA]  # Only process up to first 50 items
# Convert likes to a saveable format
likes_recent_dict = [models.Media.dictionary_from_object(u) for u in likes]
# Save the liked media
if not os.path.exists(likes_dir):
    os.makedirs(likes_dir)
user_likes_path = os.path.join(likes_dir, user_id + ".json")
with open(user_likes_path, "wb") as likes_file:
    likes_file.write(json.dumps(likes_recent_dict))
# Download the media
scratch.download_images(likes, media_dir, resolution="thumbnail")

# Issue notification that the search is complete
num_likes = len(likes_recent_dict)
Notifier.notify(