Example #1
0
def main(*args, **kwargs):
	rhythm_obj=bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Player")
	rhythmshell_obj=bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell")
	rhythm=dbus.Interface(rhythm_obj, "org.gnome.Rhythmbox.Player")
	rhythmshell=dbus.Interface(rhythmshell_obj, "org.gnome.Rhythmbox.Shell")	
	artist=str(rhythmshell.getSongProperties(rhythm.getPlayingUri())['artist'])
	title=str(rhythmshell.getSongProperties(rhythm.getPlayingUri())['title'])

	searchstr='''"'''+title+'''"'''+' '+artist+' lyrics -search'
	
	gs=GoogleSearch(searchstr)
	print 'Googling for ',searchstr
	gs.results_per_page=10
	
	try:
		results=gs.get_results()
	except:
		# os.popen("dcop amarok contextbrowser showLyrics '<lyric>Google.com is not accessible. Check your internet connection and retry</lyric>'")
		print 'google.com is not accessible'
		return ''

	for res in results:
		lyric=getlyric(res.url.encode('utf8'),title)
		if lyric=='':
			pass
		else :
			print 'the lyric is:\n%s'%lyric
			break
Example #2
0
def main(*args, **kwargs):
	rhythm_obj=bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Player")
	rhythmshell_obj=bus.get_object("org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell")
	rhythm=dbus.Interface(rhythm_obj, "org.gnome.Rhythmbox.Player")
	rhythmshell=dbus.Interface(rhythmshell_obj, "org.gnome.Rhythmbox.Shell")	
	artist=str(rhythmshell.getSongProperties(rhythm.getPlayingUri())['artist'])
	title=str(rhythmshell.getSongProperties(rhythm.getPlayingUri())['title'])

	searchstr='''"'''+title+'''"'''+' '+artist+' lyrics -search'
	
	gs=GoogleSearch(searchstr)
	print 'Googling for ',searchstr
	gs.results_per_page=10

	results=gs.get_results()
	print "got results", results

#	try:
#		results=gs.get_results()
#	except:
#		print 'google.com is not accessible'
#		return ''

	for res in results:
		lyric=getlyric(res.encode('utf8'))
		if lyric=='':
			pass
		else :
			print 'the lyric is:\n%s'%lyric
			break
Example #3
0
 def __init__(self):
     self.__crawler = Crawler()
     self.__cleaner = Cleaner()
     self.__file_manager = FileManager()
     self.__search_engine = GoogleSearch(config.SEARCH_TOPIC,
                                         config.MAX_ITEM,
                                         config.NUMBER_OF_RESULTS_PER_PAGE,
                                         config.PAUSE_BTW_REQUEST)
     self.__csf_manager = CSFManager()
def search(a):
  try:
    gs = GoogleSearch(a)
    gs.results_per_page = 100
    results = gs.get_results()
    for res in results:
      print res.title.encode("utf8")
      print res.desc.encode("utf8")
      print res.url.encode("utf8")
      print
  except SearchError, e:
    print "Search failed:"
Example #5
0
def find(food_name):
	try:
	  print "Got" + str(food_name)
	  gs = GoogleSearch(food_name)
	  gs.results_per_page = 10
	  results = gs.get_results()
	  #print results
	  lines = []
	  for res in results:
	    lines.append(res.encode("utf8"))
	  
	  return lines
	except SearchError, e:
	  print "Search failed: %s" % e
Example #6
0
    def search(self, keyword, domain, numberOfResults=50, maxRequest=-1):
        """
        Google for a specific keyword
        :param keyword: The keyword
        :param domain: Constants defined by Googler (DOMAIN_ENGLISH, DOMAIN_VIETNAMESE ...)
        :param numberOfResults: Number of results to return
        :param maxRequest: Maximum search requests to make. If it's set to -1,
                        we'll take infinite requests to search
        :return: List of GoogleResult instances
        """
        # a trick to make Google not ban us for requesting so often
        keyword = keyword.replace(u' ', u'+')
        keyword = u'"%s"' % keyword  # quote it

        gs = GoogleSearch(query=keyword, tld=domain)
        gs.results_per_page = Googler.__RESULT_PER_PAGE

        ret = []
        requestCount = 0
        try:
            while True:
                results = gs.get_results()
                if not results or len(results) == 0:
                    return ret

                for result in results:
                    g = GoogleResult()
                    g.description = result.desc
                    g.url = result.url
                    g.title = result.title
                    if self.parse(g):
                        ret.append(g)
                        if len(ret) == numberOfResults:
                            return ret

                # sleep before conducting another search
                time.sleep(5)

                if maxRequest != -1:
                    requestCount += 1
                    if requestCount > maxRequest:
                        return ret

        except SearchError as e:
            print "Search failed: %s" % e

        return ret
Example #7
0
async def main():
    storage_manager = get_storage_manager('redis')
    async with GoogleSearch() as google_search:
        bot = Bot(command_prefix='!')
        initialize_bot(bot, storage_manager, google_search)
        try:
            await bot.start(settings.TOKEN)
        finally:
            await bot.close()
Example #8
0
def GetSearchResults(query=None,type=None, exact=False):
	
	if (type=="movies"):
		# This a google search. The -tv will ommit all TV shows.
		search = 'intitle:%s -"Episode List" -"Series Rating"' % (query)
	else:
		search = 'allintitle:%s "Episode List"' % (query)
	
	gs = GoogleSearch(search)
	gs.results_per_page = 25
	gs.page = 0
	results = gs.get_results() +  gs.get_results()
	items = []
	
	for res in results:
	
		name = re.sub(
			'(<em>|</em>|<a>|</a>|DivX|-|icefilms(\.info)?|<b>\.\.\.</b>|Episode List|links)',
			'',
			res.title.encode('utf8')
		).strip()

		url=res.url
		video_url = re.search("icefilms\.info(/.*)", url).group(1)
		
		res = {}
		
		res['type'] = type
		res['title'] = name

		match = re.search("(.*)\((\d*)\)", res['title'])
		
		if (match):
			res['title'] = match.group(1).strip()
			res['year'] = int(match.group(2).strip())
			
		res['id'] = video_url
		
		items.append(res)
	
	return items
Example #9
0
	def find_lyric(self,title,artist,is_first=False,is_next=False,is_prev=False):
		if is_first==True:
			self.result_no=-1
			self.all_lyrics=[]
			searchstr='''"'''+title+'''"'''+' '+artist+' lyrics -search'
			gs=GoogleSearch(searchstr)
			print 'Googling for ',searchstr
			self.results=gs.get_results()
			print "the search results are: "
			for i in self.results:
				print i

		if is_prev==True:
			if self.result_no>=1:
				self.result_no-=1
				print "returning the lyric no %d"%self.result_no
				return self.all_lyrics[self.result_no]
			else:
				return "This is the first one"
		
		if is_next==True:
			if len(self.all_lyrics)>self.result_no+1:
				self.result_no+=1
				return self.all_lyrics[self.result_no]

		while self.result_no+1<len(self.results):
			self.result_no+=1
			lyric=getlyric(self.results[self.result_no].encode('utf8'))
			self.all_lyrics.append(lyric)
		
			if lyric=='':
				pass
			else :
				print "result_no is %d"%self.result_no
				return lyric
		else:
			return "this is the last lyric I could find"
Example #10
0
def main():
	artist=get('dcop %s player artist'%amarokid).strip()
	title=get('dcop %s player title'%amarokid).strip()

	if title =='':
		searchstr=get('dcop %s player nowPlaying'%amarokid)+' lyrics'
	else :
		searchstr='''"'''+title+'''"'''+' '+artist+' lyrics'

	gs=GoogleSearch(searchstr)
	print 'Googling for ',searchstr
	gs.results_per_page=10
	try:
		results=gs.get_results()
	except:
		os.popen("dcop %s contextbrowser showLyrics '<lyric>Google.com is not accessible. Check your internet connection and retry</lyric>'"%amarokid)
		print 'google.com is not accessible'
		return ''

	xml=open('%s/tmp.xml'%user.home,'w')
	for res in results:
		lyric=getlyric(res.url.encode('utf8'),title)
		if lyric=='':
			pass
		else :
			print 'the lyric is:\n%s'%lyric
			xmldoc=xmlcorrect(lyric)
			xmldoc="""<lyric artist="%s" title="%s" page_url="%s" >"""%(artist,title,res.url.encode('utf8'))+xmldoc+'</lyric>'
			print >> xml, xmldoc
			xml.close()
			sh=open('%s/tmp.sh'%user.home,'w')
			print >> sh, "xml=$(cat ~/tmp.xml)"
			print >> sh, '''dcop %s contextbrowser showLyrics "${xml}"'''%amarokid
			sh.close()
			get("sh %s/tmp.sh"%user.home)
			break
Example #11
0
def GetSearchResults(query=None, type=None, exact=False):

    if (type == "movies"):
        # This a google search. The -tv will ommit all TV shows.
        search = 'intitle:%s -"Episode List" -"Series Rating"' % (query)
    else:
        search = 'allintitle:%s "Episode List"' % (query)

    gs = GoogleSearch(search)
    gs.results_per_page = 25
    gs.page = 0
    results = gs.get_results() + gs.get_results()
    items = []

    for res in results:

        name = re.sub(
            '(<em>|</em>|<a>|</a>|DivX|-|icefilms(\.info)?|<b>\.\.\.</b>|Episode List|links)',
            '', res.title.encode('utf8')).strip()

        url = res.url
        video_url = re.search("icefilms\.info(/.*)", url).group(1)

        res = {}

        res['type'] = type
        res['title'] = name

        match = re.search("(.*)\((\d*)\)", res['title'])

        if (match):
            res['title'] = match.group(1).strip()
            res['year'] = int(match.group(2).strip())

        res['id'] = video_url

        items.append(res)

    return items
Example #12
0
import argparse
import logging
import os
import sys

from search import GoogleSearch
import settings

logging.basicConfig(stream=sys.stdout, level=logging.INFO)

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('term', help='search term')

    if not os.path.exists(settings.STORAGE_ROOT):
        try:
            os.makedirs(settings.STORAGE_ROOT)
        except OSError:
            logging.error('Unable to create storage folder %s' %
                          settings.STORAGE_ROOT)
            sys.exit(1)

    GoogleSearch(parser.parse_args().term).search()
Example #13
0
class Application():
    def __init__(self):
        self.__crawler = Crawler()
        self.__cleaner = Cleaner()
        self.__file_manager = FileManager()
        self.__search_engine = GoogleSearch(config.SEARCH_TOPIC,
                                            config.MAX_ITEM,
                                            config.NUMBER_OF_RESULTS_PER_PAGE,
                                            config.PAUSE_BTW_REQUEST)
        self.__csf_manager = CSFManager()

    def setQuery(self, keyword):
        self.__search_engine.setKeyword(keyword)

    def run(self, query):
        log.info("Application started.")
        web_list = self.__search_engine.search(query)
        log.debug("Search is done." + str(len(web_list)) + " URL was found.")
        if web_list:
            web_list_content_clean = self.__crawler.get_text_from_list_of_urls(
                web_list, verbose=True)
            log.info("Search contents are downloaded.")

        if web_list_content_clean:
            web_list_content_clean = self.__cleaner.clean_content(
                web_list_content_clean)
            log.info("Content was cleaned.")

        return web_list, web_list_content_clean

    def save_as_csv(self, web_list, web_list_content_clean, topic=None):
        if not topic:
            topic = config.SEARCH_TOPIC

        return self.__file_manager.save_as_csv(web_list,
                                               web_list_content_clean, topic)

    def save_as_json(self, web_list, web_list_content_clean, topic=None):
        if not topic:
            topic = config.SEARCH_TOPIC
        return self.__file_manager.save_as_json(web_list,
                                                web_list_content_clean, topic)

    def verify_require_folders(self):
        try:
            Path(os.getcwd() + '/tmp/').mkdir(parents=True, exist_ok=True)
            Path(os.getcwd() + '/files/').mkdir(parents=True, exist_ok=True)
            Path(os.getcwd() + '/log/').mkdir(parents=True, exist_ok=True)
        except FileNotFoundError as e:
            log.error("Error:/log creation ", exc_info=True)
        except NotImplementedError as e:
            log.error("Error:/log creation ", exc_info=True)

    def remove_tmp_folders(self):
        try:
            #Path(os.getcwd() + '/tmp/').unlink(missing_ok=True)
            # Path(os.getcwd() + '/tmp/').rmdir()
            Path(os.getcwd() + '/tmp/').rmtree(ignore_errors=True)
            # self.rm_rf(Path(os.getcwd() + '/tmp/'))
        except FileNotFoundError as e:
            log.error("Error:/tmp creation ", exc_info=True)
        except NotImplementedError as e:
            log.error("Error:/tmp creation ", exc_info=True)

    def rm_rf(self, pth: Path):
        for child in pth.iterdir():
            if child.is_file():
                child.unlink()
            else:
                self.rm_rf(child)
        pth.rmdir()

    def get_csf_manager(self):
        if not self.__csf_manager:
            self.__csf_manager = CSFManager()
        return self.__csf_manager
Example #14
0
#!/usr/bin/python
#
# This program does a Google search for "quick and dirty" and returns
# 50 results.
#

from search import GoogleSearch, SearchError
try:
  gs = GoogleSearch("quick and dirty")
  gs.results_per_page = 50
  results = gs.get_results()
  for res in results:
    print res.title.encode('utf8')
    print res.desc.encode('utf8')
    print res.url.encode('utf8')
    print
except SearchError, e:
  print "Search failed: %s" % e