except ValueError: return None if (n < 0) or (n >= len(lst)): return None return lst[n] API_KEY = '3166d15f23de42305e82a2c2c3e8df99' if len(sys.argv) < 3: print('USAGE:') print('{} username dir1 [dir2 [dir3 …]]'.format(sys.argv[0])) sys.exit() lfm = LastFM(API_KEY) username = sys.argv[1] dirs = sys.argv[2:] picklename = 'local-lib.pickle' if dirs[0].endswith('pickle'): picklename = dirs.pop(0) local = pickle.load(open(picklename, 'rb')) else: local = {} # first, collect data from the local collection for d in dirs: for dirpath, dirnames, filenames in os.walk(d): print('Scanning {}'.format(dirpath), file=sys.stderr)
#!/usr/bin/env python3 import sys import json import pickle from lfm import LastFM from lfm import try_really_hard as trh API_KEY = '3166d15f23de42305e82a2c2c3e8df99' if len(sys.argv) != 3: print('USAGE:') print('{} username levels'.format(sys.argv[0])) sys.exit() lfm = LastFM(API_KEY) username = sys.argv[1] levels = int(sys.argv[2]) print('Fetching {u}\'s friends {l} levels deep.'.format(u=username, l=levels)) friends = [[username]] seen = set([username]) for i in range(1, levels + 1): this_level = [] for prev in friends[-1]: for friend in lfm.get_user_friends(prev): if friend not in seen: seen.add(friend) this_level.append(friend) friends.append(this_level)
#!/usr/bin/env python3 import sys import json import pickle from lfm import LastFM from lfm import try_really_hard as trh API_KEY = '3166d15f23de42305e82a2c2c3e8df99' if len(sys.argv) != 2: print('USAGE:') print('{} groupname'.format(sys.argv[0])) sys.exit() lfm = LastFM(API_KEY) groupname = sys.argv[1] members = lfm.get_group_members(groupname) print('Found {cnt} members of group "{grp}".'.format(grp=groupname, cnt=len(members))) artists = {} for i, user in enumerate(members): here = trh(lambda: lfm.get_user_artists(user)) for a in here: if a[0] in artists: artists[a[0]].append((user, a[1])) else: artists[a[0]] = [(user, a[1])] print('[{i}/{total}] User {user} processed, {n} artists found.'.format( i=i + 1,
#!/usr/bin/env python3 import sys import json import pickle from lfm import LastFM from lfm import try_really_hard as trh API_KEY = '3166d15f23de42305e82a2c2c3e8df99' if len(sys.argv) != 3: print('USAGE:') print('{} user1 user2'.format(sys.argv[0])) sys.exit() lfm = LastFM(API_KEY) user1, user2 = sys.argv[1:] shouts = [x for x in lfm.get_user_shouts(user1) if x[1] == user2] if user1 != user2: shouts += [x for x in lfm.get_user_shouts(user2) if x[1] == user1] shouts.sort() for shout in shouts: print(shout[0].isoformat(), shout[1]) print(shout[2]) print()
#!/usr/bin/env python3 import sys import json import pickle from lfm import LastFM from lfm import try_really_hard as trh API_KEY = '3166d15f23de42305e82a2c2c3e8df99' if len(sys.argv) != 2: print('USAGE:') print('{} groupname'.format(sys.argv[0])) sys.exit() lfm = LastFM(API_KEY) groupname = sys.argv[1] members = lfm.get_group_members(groupname) print('Found {cnt} members of group "{grp}".'.format(grp=groupname, cnt=len(members))) artists = {} for i, user in enumerate(members): here = trh(lambda: lfm.get_user_artists(user)) for a in here: if a[0] in artists: artists[a[0]].append((user, a[1])) else: artists[a[0]] = [(user, a[1])] print('[{i}/{total}] User {user} processed, {n} artists found.'.format(
return None if (n < 0) or (n >= len(lst)): return None return lst[n] API_KEY = '3166d15f23de42305e82a2c2c3e8df99' if len(sys.argv) < 3: print('USAGE:') print('{} username dir1 [dir2 [dir3 …]]'.format(sys.argv[0])) sys.exit() lfm = LastFM(API_KEY) username = sys.argv[1] dirs = sys.argv[2:] picklename = 'local-lib.pickle' if dirs[0].endswith('pickle'): picklename = dirs.pop(0) local = pickle.load(open(picklename, 'rb')) else: local = {} # first, collect data from the local collection for d in dirs: for dirpath, dirnames, filenames in os.walk(d): print('Scanning {}'.format(dirpath), file=sys.stderr)