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 _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 get_search_results(term1):
- urlstart = "http://www.faroo.com/api?q="
- urlpage = "&start="
- page = 1
- urlend = "&length=10&l=en&src=web&i=false&f=json"
- url = urlstart + term1 + urlpage
- 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 download_it(url):
- red = _wrap_with('31')
- blue = _wrap_with('34')
- white = _wrap_with('37')
- cyan = _wrap_with('36')
- yellow = _wrap_with('33')
- 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
- print "----------------------------------------------------------------------------\n"
- try:
- for a in range(len(dic['results'])):
- print cyan('LINK ')+white(str(dic['results'][a]['url']))+"\n"+cyan('LINK NAME ')+white(str(dic['results'][a]['title'])),"\n"
- if 'kwic' in dic['results'][a]: print yellow(str(dic['results'][a]['kwic']))
- else: pass
- print "----------------------------------------------------------------------------\n"
- sleep(0.5)
- except: pass
- sleep(1.3)
- os.system('clear')
- choosea = ''
- while choosea == '':
- url1 = url
- url1 += str(page)
- url1 += urlend
- download_it(url1)
- choosea = raw_input('press <enter> to fetch another or enter "q" to quit \n')
- page += 1
- hello()
- def hello():
- ch0 = """#######################################\n#"""
- ch1 = """ _ _ __ ___"""
- ch2 = """ #\n# """
- ch3 = """| | ___ | | __ _ / /_ / _ \ """
- ch4 = """ #\n# """
- ch5 = """| | / _ \| |/ _ | _ \ (_) | """
- ch6 = """ #\n# """
- ch7 = """| |__| (_) | | (_| | (_) \__, | """
- ch8 = """#\n# """
- ch9 = """|_____\___/|_|\__,_|\___/ /_/ """
- ch10= """ #\n# """
- ch11 = """____ _ """
- ch12 = """ #\n# """
- ch13 = """/ ___| ___ __ _ _ __ ___| |__ """
- ch14 = """ #\n# """
- ch15 = """\___ \ / _ \/ _ | '__/ __| _ \ """
- ch16 = """#\n# """
- ch17 = """___) | __/ (_| | | | (__| | | | """
- ch18 = """ #\n# """
- ch19 = """|____/ \___|\__,_|_| \___|_| |_| """
- ch20 = """ #\n# Powered by FAROO #\n#######################################\n"""
- ch21 = """Enter search term or q to quit: """
- 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(ch6)+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)
- os.system('clear')
- term = str(raw_input(ch))
- term1 = term.replace(" ","%20")
- if term1 == 'q':
- pass
- else: get_search_results(term1)
- hello()
Advertisement
Add Comment
Please, Sign In to add comment