Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os as os
- import urllib
- import json # we are after all importing json
- from time import sleep
- def artist_getinfo(api_key):
- urlstart = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist="
- urlend = "&autocorrect=1&api_key="+api_key+"&format=json"
- url = urlstart
- ch1 = """
- ###############################################################
- # method - artist.getInfo #
- # #
- ###############################################################
- Enter name of Artist : """
- def wrap(text, width):
- """
- A word-wrap function that preserves existing line breaks
- and most spaces in the text. Expects that existing line
- breaks are posix newlines (\n).
- usage: print(wrap(msg,40))
- """
- return reduce(lambda line, word, width=width: '%s%s%s' %
- (line,' \n'[(len(line)-line.rfind('\n')-1 + len(word.split('\n',1)[0]) >= width)],word),text.split(' '))
- def download_it(url, loca):
- print "loading..."
- dic = {}
- conn = urllib.urlopen(url)
- try:
- os.system('clear')
- for line in conn: # comes as a unicode string
- dic = json.loads(line) # load json into dic
- print "###############################################################"
- print "Artist info for",loca
- print "###############################################################"
- print "about..."
- content = dic['artist']['bio']['content']
- print wrap(content.strip(),80)
- print "###############################################################"
- print "tags...\n"
- for f in range(len(dic['artist']['tags']['tag'])):
- print dic['artist']['tags']['tag'][f]['name']
- print "###############################################################"
- print "similar artists...\n"
- for f1 in range(len(dic['artist']['similar']['artist'])):
- print dic['artist']['similar']['artist'][f1]['name']
- print "###############################################################"
- print "Listeners: ",dic['artist']['stats']['listeners']
- print "Playcount: ",dic['artist']['stats']['playcount']
- except: print "No artist info found"
- os.system('clear')
- loca = raw_input(ch1)
- url += loca
- url += urlend
- download_it(url, loca)
- ex = raw_input('\nPress <ENTER> to continue')
- def artist_getsimilar(api_key):
- urlstart = "http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist="
- urllimit = "&limit="
- urlend = "&autocorrect=1&api_key="+api_key+"&format=json"
- url = urlstart
- ch2 = """
- ###############################################################
- # method - artist.getSimilar #
- # #
- # 1 : Limit the number of similar artists returned #
- # 0 : Fetch the JSON #
- # #
- ###############################################################
- first Enter name of Artist : """
- def download_it(url, loca):
- print "loading..."
- dic = {}
- conn = urllib.urlopen(url)
- for line in conn: # comes as a unicode string
- dic = json.loads(line) # load json into dic
- try:
- os.system('clear')
- print "###############################################################"
- print "Similar Artists to",loca
- print "###############################################################"
- count = 0
- for f in range(len(dic['similarartists']['artist'])):
- print dic['similarartists']['artist'][f]['name']
- count += 1
- if count == 10: break
- except: print "No similar artists found"
- os.system('clear')
- loca = raw_input(ch2)
- url += loca
- loopy = 0
- while loopy == 0:
- print "\nChoose an option from the menu above"
- choosea = str(raw_input('> '))
- if choosea == '0':
- loopy = 1
- elif choosea == '1':
- limi = str(raw_input('Enter number of sim artists to get: '))
- url += urllimit + limi
- url += urlend
- pnumber = 1
- download_it(url, loca)
- ex = raw_input('\nPress <ENTER> to continue')
- def artist_gettoptags(api_key):
- urlstart = "http://ws.audioscrobbler.com/2.0/?method=artist.gettoptags&artist="
- urlend = "&autocorrect=1&api_key="+api_key+"&format=json"
- url = urlstart
- ch3 = """
- ###############################################################
- # method - artist.getTopTags #
- # #
- ###############################################################
- first Enter name of Artist : """
- def download_it(url, loca):
- print "loading..."
- dic = {}
- conn = urllib.urlopen(url)
- for line in conn: # comes as a unicode string
- dic = json.loads(line) # load json into dic
- try:
- os.system('clear')
- print "###############################################################"
- print "Top tags for",loca
- print "###############################################################"
- count = 0
- for f in range(len(dic['toptags']['tag'])):
- print dic['toptags']['tag'][f]['name'],dic['toptags']['tag'][f]['count']
- count += 1
- if count == 10: break
- except: print "No tags found"
- os.system('clear')
- loca = raw_input(ch3)
- url += loca
- url += urlend
- download_it(url, loca)
- ex = raw_input('\nPress <ENTER> to continue')
- def library_getartists(api_key):
- urlstart = "http://ws.audioscrobbler.com/2.0/?method=library.getartists"
- urllimit = "&limit="
- urlpage = "&page="
- urlend = "&api_key="+api_key+"&format=json&user="
- url = urlstart
- ch4 = """
- #################################################################
- # method - library.getArtists #
- # #
- # 1 : The number of results to fetch per page. Defaults to 50. #
- # 2 : Specify number of pages to fetch: Default = 1. #
- # 0 : Fetch the JSON #
- # #
- #################################################################
- first Enter the users name: """
- def download_it(url, username):
- print "loading..."
- dic = {}
- conn = urllib.urlopen(url)
- for line in conn: # comes as a unicode string
- dic = json.loads(line) # load json into dic
- try:
- os.system('clear')
- print "###############################################################"
- print "Artists from the library of",username
- print "###############################################################"
- count = 0
- for f in range(len(dic['artists']['artist'])):
- print dic['artists']['artist'][f]['name'],dic['artists']['artist'][f]['playcount']
- count += 1
- if count == 10: break
- except: print "No artists found"
- os.system('clear')
- username = raw_input(ch4)
- urlend += username
- pages = 0
- loopy = 0
- while loopy == 0:
- print "\nChoose an option from the menu above"
- choosea = str(raw_input('> '))
- if choosea == '0':
- loopy = 1
- elif choosea == '1':
- limi = str(raw_input('Enter results per page: '))
- url += urllimit + limi
- elif choosea == '2':
- pages = int(raw_input('Enter number of pages: '))
- if pages > 1:
- for a in range(pages):
- url1 = url
- url1 += urlpage + str(a+1)
- url1 += urlend
- download_it(url1, username)
- sleep(1)
- else:
- url += urlend
- download_it(url, username)
- ex = raw_input('\nPress <ENTER> to continue')
- def tag_getsimilar(api_key):
- urlstart = "http://ws.audioscrobbler.com/2.0/?method=tag.getsimilar&tag="
- urlend = "&api_key="+api_key+"&format=json"
- url = urlstart
- ch5 = """
- ###############################################################
- # method - tag.getSimilar #
- # #
- ###############################################################
- Enter tag : """
- def download_it(url, loca):
- print "loading..."
- dic = {}
- conn = urllib.urlopen(url)
- for line in conn: # comes as a unicode string
- dic = json.loads(line) # load json into dic
- try:
- os.system('clear')
- print "###############################################################"
- print "Tags similar to",loca
- print "###############################################################"
- count = 0
- for f in range(len(dic['similartags']['tag'])):
- print dic['similartags']['tag'][f]['name']
- count += 1
- if count == 10: break
- except: print "No tags found"
- os.system('clear')
- loca = raw_input(ch5)
- url += loca
- url += urlend
- download_it(url, loca)
- ex = raw_input('\nPress <ENTER> to continue')
- def user_getfriends(api_key):
- urlstart = "http://ws.audioscrobbler.com/2.0/?method=user.getfriends&user="
- urllimit = "&limit="
- urlpage = "&page="
- urlend = "&api_key="+api_key+"&format=json"
- url = urlstart
- ch6 = """
- #################################################################
- # method - user.getFriends #
- # #
- # 1 : The number of results to fetch per page. Defaults to 50. #
- # 2 : Specify number of pages to fetch: Default = 1. #
- # 0 : Fetch the JSON #
- # #
- #################################################################
- first Enter the users name: """
- def download_it(url, username):
- print "loading..."
- dic = {}
- conn = urllib.urlopen(url)
- for line in conn: # comes as a unicode string
- dic = json.loads(line) # load json into dic
- try:
- os.system('clear')
- print "###############################################################"
- print "Friends of",username
- print "###############################################################"
- count = 0
- for f in range(len(dic['friends']['user'])):
- print dic['friends']['user'][f]['name'],dic['friends']['user'][f]['realname'],dic['friends']['user'][f]['age'],dic['friends']['user'][f]['country']
- count += 1
- if count == 10: break
- except: print "No friends found"
- os.system('clear')
- username = raw_input(ch6)
- url += username
- pages = 0
- loopy = 0
- while loopy == 0:
- print "\nChoose an option from the menu above"
- choosea = str(raw_input('> '))
- if choosea == '0':
- loopy = 1
- elif choosea == '1':
- limi = str(raw_input('Enter results per page: '))
- url += urllimit + limi
- elif choosea == '2':
- pages = int(raw_input('Enter number of pages: '))
- if pages > 1:
- for a in range(pages):
- url1 = url
- url1 += urlpage + str(a+1)
- url1 += urlend
- download_it(url1, username)
- sleep(1)
- else:
- url += urlend
- download_it(url, username)
- ex = raw_input('\nPress <ENTER> to continue')
- def user_getlovedtracks(api_key):
- urlstart = "http://ws.audioscrobbler.com/2.0/?method=user.getlovedtracks&user="
- urllimit = "&limit="
- urlpage = "&page="
- urlend = "&api_key="+api_key+"&format=json"
- url = urlstart
- ch7 = """
- #################################################################
- # method - user.getLovedTracks #
- # #
- # 1 : The number of results to fetch per page. Defaults to 50. #
- # 2 : Specify number of pages to fetch: Default = 1. #
- # 0 : Fetch the JSON #
- # #
- #################################################################
- first Enter the users name: """
- def download_it(url, username):
- print "loading..."
- dic = {}
- conn = urllib.urlopen(url)
- for line in conn: # comes as a unicode string
- dic = json.loads(line) # load json into dic
- try:
- os.system('clear')
- print "###############################################################"
- print "Loved tracks of",username
- print "###############################################################"
- count = 0
- for f in range(len(dic['lovedtracks']['track'])):
- print dic['lovedtracks']['track'][f]['name'],dic['lovedtracks']['track'][f]['artist']['name']
- count += 1
- if count == 10: break
- except: print "No loved tracks found"
- os.system('clear')
- username = raw_input(ch7)
- url += username
- pages = 0
- loopy = 0
- while loopy == 0:
- print "\nChoose an option from the menu above"
- choosea = str(raw_input('> '))
- if choosea == '0':
- loopy = 1
- elif choosea == '1':
- limi = str(raw_input('Enter results per page: '))
- url += urllimit + limi
- elif choosea == '2':
- pages = int(raw_input('Enter number of pages: '))
- if pages > 1:
- for a in range(pages):
- url1 = url
- url1 += urlpage + str(a+1)
- url1 += urlend
- download_it(url1, username)
- sleep(1)
- else:
- url += urlend
- download_it(url, username)
- ex = raw_input('\nPress <ENTER> to continue')
- def gui(api_key):
- ch = """
- ###############################################################
- # options #
- # #
- # 1 - artist.getInfo #
- # 2 - artist.getSimilar #
- # 3 - artist.getTopTags #
- # 4 - library.getArtists #
- # 5 - tag.getSimilar #
- # 6 - user.getFriends #
- # 7 - user.getLovedTracks #
- # 0 - exit #
- ###############################################################
- Choose an option from the menu above: """
- loopy = 0
- while loopy == 0:
- os.system('clear')
- choosea = str(raw_input(ch))
- if choosea == '0':
- loopy = 1
- elif choosea == '1':
- artist_getinfo(api_key)
- elif choosea == '2':
- artist_getsimilar(api_key)
- elif choosea == '3':
- artist_gettoptags(api_key)
- elif choosea == '4':
- library_getartists(api_key)
- elif choosea == '5':
- tag_getsimilar(api_key)
- elif choosea == '6':
- user_getfriends(api_key)
- elif choosea == '7':
- user_getlovedtracks(api_key)
- else:
- print "#invalid option#"
- os.system('clear')
- def hello():
- os.system('clear')
- ch0 = """
- #####################################################
- # _ _ __ #
- # | | ___ ___| |_ / _|_ __ ___ -69 #
- # | |/ _ '/ __| __|____| |_| _ ' _ \ #
- # | | (_| \__ \ |_|____| _| | | | | | #
- # |_|\__,_|___/\__| |_| |_| |_| |_| #
- # #
- # An interface to the last-fm API: lolamontes69 #
- # #
- #####################################################
- Enter your api_key: """
- api_key = str(raw_input(ch0))
- gui(api_key)
- hello()
Advertisement
Add Comment
Please, Sign In to add comment