Exemplo n.º 1
0
def make_add_or_remove_favorite_item(user_id, username):
    """Create an alfred item to add or remove a user from favorites"""
    # Add item depending on if this user is a favorite
    favs = Favorites(wf())
    favUsers = favs.get_favorites()
    special_unicode_value = wf().alfred_items.special_unicode_value.next()
    command = None
    if favUsers is not None:
        if user_id in favUsers:
            wf().add_item( title=u'Remove from favorites',
                           autocomplete=unichr(special_unicode_value),
                           icon=ICON_TRASH)
            command = REMOVE_FAV
        else:
            wf().add_item(title=u'Add to favorites',
                        autocomplete=unichr(special_unicode_value))
            command = ADD_FAV
    # Else user is not a favorite because the 'favorites' file doesnt exist
    else:
        wf().add_item(title=u'Create a favorite',
                    autocomplete=unichr(special_unicode_value))
        command = ADD_FAV
    # Update special info
    data = {special_unicode_value: (command, {'user_id': user_id, 'username': username})}
    wf().alfred_items.special_info.send(data)
Exemplo 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')