Ejemplo n.º 1
0
def add_or_remove_favorite(user_id, username):
    """Page to display basic user information and ask to add as a favorite"""
    # Display user
    user = Grammie(wf(), user_id, username, age_info=1)
    user.display_info()
    
    # Ask to add or remove as a favorite
    make_add_or_remove_favorite_item(user_id, username)
Ejemplo n.º 2
0
def load_favorites():
    """Display favorite users"""   
    max_age_fav = HOUR
    favs = Favorites(wf())
    fav_users = favs.get_favorites()
    if fav_users is not None:
        fav_ids = sorted(fav_users, key=fav_users.get)
        for fav_id in fav_ids:
            fav_username = fav_users[fav_id]
            fav = Grammie(wf(), fav_id, fav_username, command=LOAD_USER, age_info=max_age_fav)
            # Update the cached value of a favorite in case the username changes
            favs.update_info(fav_id, fav.username)          
            fav.display_info()
        # Save favorites to cache
        favs.cache_favs()
    else:
        # No stored favorites, prompt user to add some
        wf().add_item('Add users as favorites to see them here')
Ejemplo n.º 3
0
def search_users(query):
    """Search for a user by username"""
    users = scratch._api.user_search(query, count=16)
    for user in users:
        guser = Grammie(wf(), user.id, user.username, command=MAKE_FAVORITE, update=False)
        guser.type = 'private'
        guser.profile_picture = user.profile_picture
        guser.full_name = user.full_name
        guser.display_info()
Ejemplo n.º 4
0
def check_user_followed_by(user_id, username):
    """Compare current followers of user to stored version"""
    max_items = 15  # Alfred is limited to the number of items it can display
    # Make a go back item
    special_unicode_value = prepare_item_with_command(LOAD_USER, user_id, username)
    wf().add_item( title='Go back',
                   valid=False,
                   autocomplete=unichr(special_unicode_value),
                   icon=ICON_BACK)
                   
    follow_data_dir = os.path.join(wf().datadir, 'follow_data')
    result = scratch.compare_new_followed_by(user_id, data_dir=follow_data_dir)
    if result:  # if result is None there wasnt any stored data
        new_followers, removed_followers = result
        if len(new_followers)==0:
            wf().add_item(title=u'No new users following {user}'.format(user=username),
                          icon=ICON_INFO)
        else:
            wf().add_item(title=u'{user} has {followers} new followers:'.\
                            format(user=username, followers=len(new_followers)),
                          icon=ICON_GROUP)            
            for follow in new_followers[:max_items]:
                user = Grammie(wf(), follow.id, follow.username, age_info=HOUR)
                user.display_info()
        if len(removed_followers)==0:
            wf().add_item(title=u'No users unfollowed {user}'.format(user=username),
                          icon=ICON_INFO)
        else:
            wf().add_item(title=u'{user} was unfollowed by {unfollows} users:'.\
                            format(user=username, unfollows=len(removed_followers)),
                          icon=ICON_GROUP)
            for follow in removed_followers[:max_items]:
                user = Grammie(wf(), follow.id, follow.username, age_info=HOUR)
                user.display_info()
    else:
        # No stored data
        wf().add_item(u'No information previsously stored for {}'.format(username))
Ejemplo n.º 5
0
def load_user(user_id, username):
    """Display details for a particular user"""
    # Get informaiton about user from instagram api
    user_info = get_user_info(user_id)
     
    # Display user
    user = Grammie(wf(), user_id, username, age_info=5*MINUTE)
    user.display_info()
    
    # Items to display only if there is user information
    if user_info:
        # Display item to show recent media
        special_unicode_value = prepare_item_with_command(RECENT_MEDIA, user_id, username)
        wf().add_item( title='Recent media ({media} total media)'.format(media=user_info['media_count']),
                       autocomplete=unichr(special_unicode_value),
                       icon=ICON_PICTURE )
        
        # Display item to search for recent likes
        special_unicode_value = prepare_item_with_command(GET_LIKES, user_id, username)
        if background.is_running(user_id + '.get_likes'):
            subtitle = '...Now searching for media liked by {user}'.format(user=username)
        else:
            # Check if previous data is availiable
            likes_path = os.path.join(wf().likesdir, user_id + '.json')
            if os.path.exists(likes_path):
                age_of_like_data = get_age_cached_data(likes_path)
                subtitle = "Age of data: " + age_of_like_data
            else: subtitle = ''
        wf().add_item( title='Search for media liked by {user}'.format(user=username),
                       subtitle=subtitle,
                       autocomplete=unichr(special_unicode_value),
                       icon=ICON_FAVORITE,
                       valid=True,
                       arg=unichr(special_unicode_value),
                       modifier_subtitles={
                        u'alt':'Retrieve previously found likes'
                        } )
        
        # Display item to check new and removed follows
        special_unicode_value = prepare_item_with_command(CHECK_FOLLOWS, user_id, username)
        # Find age of data
        follow_data_path = os.path.join(wf().followdir, user_id + '_follows.json')
        follow_data_age = get_age_cached_data(follow_data_path)
        if follow_data_age != '':
            subtitle = 'Age of data: {age}'.format(age=follow_data_age)
        else:
            subtitle = ''
        wf().add_item( title='New and removed follows ({follows} current follows)'.format(follows=user_info['follows']),
                       subtitle=subtitle,
                       autocomplete=unichr(special_unicode_value),
                       icon=ICON_GROUP )
                       
        # Display item to check for new and removed users following our user
        special_unicode_value = prepare_item_with_command(CHECK_FOLLOWED_BY, user_id, username)
        # Find age of data
        followers_data_path = os.path.join(wf().followdir, user_id + '_followed_by.json')
        followers_data_age = get_age_cached_data(followers_data_path)
        if followers_data_age != '':
            subtitle = 'Age of data: {age}'.format(age=followers_data_age)
        else:
            subtitle = ''
        wf().add_item( title='New and removed followers ({followers} current followers)'.format(followers=user_info['followers']),
                       subtitle=subtitle,
                       autocomplete=unichr(special_unicode_value),
                       icon=ICON_GROUP )
    
    # Ask to add or remove as a favorite
    make_add_or_remove_favorite_item(user_id, username)