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
- ques1 = """
- ######################################################
- # Question one: #
- # #
- # Name your favourite band. #
- # #
- ######################################################
- Enter bandname: """
- ques2 = """
- ######################################################
- # Question two: #
- # #
- # Name another band. #
- # #
- ######################################################
- Enter bandname: """
- ques3 = """
- ######################################################
- # Question three: #
- # #
- # Name your current location. #
- # #
- ######################################################
- Enter location: """
- ques4 = """
- ######################################################
- # Question four: #
- # #
- # How far are you willing to travel? #
- # #
- ######################################################
- Enter distance in km: """
- ques5 = """
- ######################################################
- # Question five: #
- # #
- # How many days from today should I search within? #
- # #
- ######################################################
- Enter number of days: """
- def _wrap_with(code):
- def inner(text, bold=False):
- c = code
- if bold:
- c = "1;%s" % c
- return "\033[%sm%s\033[0m" % (c, text)
- return inner
- def artist_gettoptags(api_key, artist):
- urlstart = "http://ws.audioscrobbler.com/2.0/?method=artist.gettoptags&artist="
- urlend = "&autocorrect=1&api_key="+api_key+"&format=json"
- url = urlstart
- def download_it(url):
- blue = _wrap_with('34')
- print blue("loading...")
- list1 = []
- 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')
- count = 0
- for f in range(len(dic['toptags']['tag'])):
- list1.append(dic['toptags']['tag'][f]['name'])
- count += 1
- if count == 10: break
- except: pass
- return list1
- os.system('clear')
- url += artist
- url += urlend
- list1 = download_it(url)
- return list1
- def geo_getEvents(api_key, location, distance, page1, arttags):
- urlstart = "http://ws.audioscrobbler.com/2.0/?method=geo.getEvents&location="+location+"&distance="+distance+"&page="
- urlend = "&api_key="+api_key+"&format=json"
- url = urlstart
- if page1 == 0: page1 = 1
- pages = int(page1)
- def wrap(text, width):
- 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 print_results(dic):
- white = _wrap_with('37')
- cyan = _wrap_with('36')
- blue = _wrap_with('34')
- print cyan("Startdate :"),white(dic['startDate'])
- print ""
- print cyan("Event name:"),white(dic['title'])
- print cyan("Headliner :"),white(dic['artists']['headliner'])
- print cyan("with "),white(wrap((str(dic['artists']['artist'])), 80))
- print ""
- print cyan("At :"),white(dic['venue']['name'])
- print cyan("Tel No :"),white(dic['venue']['phonenumber'])
- print cyan("Address :"),white(dic['venue']['location']['street'])
- print " ",white(dic['venue']['location']['city'])
- print " ",white(dic['venue']['location']['postalcode'])
- print "\n------------------------------------------------\n"
- d = raw_input(blue('<enter> to continue'))
- print "\n------------------------------------------------\n"
- def download_it(url):
- blue = _wrap_with('34')
- print blue("loading...")
- dic = {}
- conn = urllib.urlopen(url)
- for line in conn: # comes as a unicode string
- dic = json.loads(line) # load json into dic
- try:
- count = 0
- for f in range(len(dic['events']['event'])):
- listA = []
- try:
- listA = dic['events']['event'][f]['tags']['tag']
- for a in listA:
- if a in arttags:
- print_results(dic['events']['event'][f])
- break
- except: pass
- except: print "No more gigs found"
- os.system('clear')
- for a in range(pages):
- url1 = url
- url1 += str(a+1)
- url1 += urlend
- download_it(url1)
- sleep(1)
- def func1():
- os.system('clear')
- one = str(raw_input(ques1))
- os.system('clear')
- two = str(raw_input(ques2))
- os.system('clear')
- three = str(raw_input(ques3))
- os.system('clear')
- four = str(raw_input(ques4))
- os.system('clear')
- five = str(raw_input(ques5))
- os.system('clear')
- return one, two, three, four, five
- def intro(api_key):
- os.system('clear')
- one, two, three, four, five = func1()
- one = artist_gettoptags(api_key, one)
- sleep(1)
- two = artist_gettoptags(api_key, two)
- arttags = one + two
- sleep(1)
- geo_getEvents(api_key, three, four, five, arttags)
- ch0 = """\n#################################################\n# """
- ch1 = """_ _ __ ___ _"""
- ch2 = """ #\n# """
- ch3 = """| | ___ | | __ _ / /_ / _ \( )___ """
- ch4 = """ # \n# """
- ch5 = """| | / _ \| |/ _ | _ \ (_) |/ __| """
- ch5a = """ # \n# """
- ch6 = """| |__| (_) | | (_| | (_) \__, |\___ \ """
- ch6a = """ # \n# """
- ch7 = """ |_____\___/|_|\__,_|\___/ /_/ |__ _/ """
- ch8 = """ # \n# """
- ch9 = """ ____ _ _ _ """
- ch10 = """ # \n# """
- ch11 = """ / ___(_) __ _ __ _ _ _(_) __| | ___ """
- ch12 = """ # \n# """
- ch13 = """| | _| |/ _' | / _' | | | | |/ _ |/ _ \ """
- ch14 = """ # \n# """
- ch15 = """| |_| | | (_| | | (_| | |_| | | (_| | __/ """
- ch16 = """ # \n# """
- ch17 = """ \____|_|\__, | \__, |\__,_|_|\__,_|\___| """
- ch18 = """ # \n# """
- ch19 = """ |___/ |___/ LAST-FM """
- ch20 = """ # \n# # \n#################################################\n"""
- ch21 = """Please enter your last-fm api_key: """
- red = _wrap_with('31')
- magenta = _wrap_with('35')
- cyan = _wrap_with('36')
- ch = red(ch0)+magenta(ch1)+red(ch2)+magenta(ch3)+red(ch4)+magenta(ch5)+red(ch5a)+magenta(ch6)+red(ch6a)+magenta(ch7)+red(ch8)+magenta(ch9)+red(ch10)+magenta(ch11)+red(ch12)+magenta(ch13)+red(ch14)+magenta(ch15)+red(ch16)+magenta(ch17)+red(ch18)+magenta(ch19)+red(ch20)+cyan(ch21)
- dh1 = """
- #################################################
- # #
- # Answer the five following questions #
- # and I will recommend you some gigs #
- # using the Last-fm database... #
- # #
- #################################################
- Press <enter> to continue: """
- os.system('clear')
- api_key = str(raw_input(ch))
- os.system('clear')
- d = str(raw_input(dh1))
- intro(api_key)
Advertisement
Add Comment
Please, Sign In to add comment