コード例 #1
0
ファイル: google.py プロジェクト: RoyalBoy69/SlowMo
async def gsearch(message: Message):
    await message.edit("Processing ...")
    query = message.filtered_input_str
    flags = message.flags
    page = int(flags.get('-p', 1))
    limit = int(flags.get('-l', 5))
    if message.reply_to_message:
        query = message.reply_to_message.text
    if not query:
        await message.err(text="Give a query or reply to a message to google!")
        return
    try:
        g_search = GoogleSearch()
        gresults = await g_search.async_search(query, page)
    except Exception as e:
        await message.err(text=e)
        return
    output = ""
    for i in range(limit):
        try:
            title = gresults["titles"][i]
            link = gresults["links"][i]
            desc = gresults["descriptions"][i]
            output += f"[{title}]({link})\n"
            output += f"`{desc}`\n\n"
        except IndexError:
            break
    output = f"**Google Search:**\n`{query}`\n\n**Results:**\n{output}"
    await message.edit_or_send_as_file(text=output,
                                       caption=query,
                                       disable_web_page_preview=True)
コード例 #2
0
ファイル: google v2.py プロジェクト: prono69/PepeBot
async def gsearch(q_event):
    """For .google command, do a Google search."""
    await q_event.edit("""`Ruk Bsdk tera IP Ban karwata Hoon`""")
    reply = await q_event.get_reply_message()
    if q_event.pattern_match.group(1):
        url = q_event.pattern_match.group(1)
    elif reply is not None:
        url = reply.message
    else:
        return
    page = findall(r"page=\d+", url)
    try:
        page = page[0]
        page = page.replace("page=", "")
        url = url.replace("page=" + page[0], "")
    except IndexError:
        page = 1
    search_args = (str(url), int(page))
    gsearch = GoogleSearch()
    gresults = await gsearch.async_search(*search_args)
    msg = ""
    i = 1

    for i in range(11):
        try:
            title = gresults["titles"][i]
            link = gresults["links"][i]
            desc = gresults["descriptions"][i]
            msg += f"{i}. [{title}]({link})\n`{desc}`\n\n"
        except IndexError:
            break

    await q_event.edit("**Search Query:**\n`" + url + "`\n\n**Results:**\n" +
                       msg,
                       link_preview=False)
コード例 #3
0
async def gsearch(message: Message):
    await message.edit("Arıyorum ...")
    query = message.filtered_input_str
    flags = message.flags
    page = int(flags.get('-p', 1))
    limit = int(flags.get('-l', 5))
    if message.reply_to_message:
        query = message.reply_to_message.text
    if not query:
        await message.err(
            text="Google'a bir sorgu gönderin veya bir mesajı yanıtlayın!")
        return
    try:
        g_search = GoogleSearch()
        gresults = await g_search.async_search(query, page)
    except Exception as e:
        await message.err(text=e)
        return
    output = ""
    for i in range(limit):
        try:
            title = gresults["titles"][i]
            link = gresults["links"][i]
            desc = gresults["descriptions"][i]
            output += f"[{title}]({link})\n"
            output += f"`{desc}`\n\n"
        except IndexError:
            break
    output = f"**Google'da aradım:**\n`{query}`\n\n**Bulduklarım:**\n{output}"
    await message.edit_or_send_as_file(text=output,
                                       caption=query,
                                       disable_web_page_preview=True)
コード例 #4
0
async def gsearch(q_event):
    match = q_event.pattern_match.group(1)
    page = findall(r"page=\d+", match)
    try:
        page = page[0]
        page = page.replace("page=", "")
        match = match.replace("page=" + page[0], "")
    except IndexError:
        page = 1
    search_args = (str(match), int(page))
    gsearch = GoogleSearch()
    gresults = await gsearch.async_search(*search_args)
    msg = ""
    for i in range(5):
        try:
            title = gresults["titles"][i]
            link = gresults["links"][i]
            desc = gresults["descriptions"][i]
            msg += f"[{title}]({link})\n`{desc}`\n\n"
        except IndexError:
            break
    await q_event.edit(
        "**Search Query:**\n`" + match + "`\n\n**Results:**\n" + msg, link_preview=False
    )

    if BOTLOG:
        await q_event.client.send_message(
            BOTLOG_CHATID,
            "Google Search query `" + match + "` was executed successfully",
        )
コード例 #5
0
    def test_two_queries_different_results(self):
        """ Test that url updates work fine """
        from search_engine_parser.core.engines.google import Search as GoogleSearch  # pylint: disable=import-outside-toplevel
        from search_engine_parser.core.engines.yahoo import Search as YahooSearch  # pylint: disable=import-outside-toplevel
        gengine = GoogleSearch()
        yahoo_engine = YahooSearch()
        gresults = gengine.search(query="Hello From the Other Side")
        yresults = yahoo_engine.search(query="this is example Bob")
        for key in gresults[0]:
            self.assertNotEqual(gresults[0].get(key, "GSearch"),
                                yresults[0].get(key, "Ysearch"))

        self.assertNotEqual(gresults, yresults)
コード例 #6
0
    def test_two_queries_different_results(self):
        """ Test that url updates work fine """
        from search_engine_parser.core.engines.google import Search as GoogleSearch # pylint: disable=import-outside-toplevel
        from search_engine_parser.core.engines.yahoo import Search as YahooSearch # pylint: disable=import-outside-toplevel
        gengine = GoogleSearch()
        yahoo_engine = YahooSearch()
        gresults = None
        gresults = None
        with vcr.use_cassette('fixtures/google-test-diff-synopsis.yaml', record_mode='once'):
            gresults = gengine.search(query="What's up from this side")
        with vcr.use_cassette('fixtures/yahoo-test-diff-synopsis.yaml', record_mode='once'):
            yresults = yahoo_engine.search(query="this is example Bob")
        for key in gresults[0]:
            self.assertNotEqual(gresults[0].get(key, "GSearch"), yresults[0].get(key, "Ysearch"))

        self.assertNotEqual(gresults, yresults)
コード例 #7
0
async def gsearch(q_event):
    """For .google command, do a Google search."""
    textx = await q_event.get_reply_message()
    query = q_event.pattern_match.group(1)

    if query:
        pass
    elif textx:
        query = textx.text
    else:
        await q_event.edit(
            "`Pass a query as an argument or reply " "to a message for Google search!`"
        )
        return

    await q_event.edit("`Searching...`")

    search_args = (str(query), 1)
    googsearch = GoogleSearch()
    try:
        gresults = await googsearch.async_search(*search_args)
        msg = ""
        for i in range(0, 5):
            try:
                title = gresults["titles"][i]
                link = gresults["links"][i]
                desc = gresults["descriptions"][i]
                msg += f"{i+1}. [{title}]({link})\n`{desc}`\n\n"
            except IndexError:
                break
        await q_event.edit(
            "**Search Query:**\n`" + query + "`\n\n**Results:**\n" + msg,
            link_preview=False,
        )
    except NoResultsOrTrafficError as error:
        if BOTLOG:
            await q_event.client.send_message(
                BOTLOG_CHATID, f"`GoogleSearch error: {error}`"
            )
        return
    if BOTLOG:
        await q_event.client.send_message(
            BOTLOG_CHATID,
            "Google Search query `" + query + "` was executed successfully",
        )
コード例 #8
0
 async def cmd_google(self, ctx: command.Context):
     query = ctx.input
     await ctx.respond("Searching...")
     # await asyncio.sleep(1)
     search_args = (query,0)
     gsearch = GoogleSearch()
     gresults = await gsearch.async_search(*search_args)
     # a = {"Google": gresults}
     # msgId = ctx.msg.chat_id
     msg = ""
     for i in range(5):
         try:
             title = gresults["titles"][i]
             link = gresults["links"][i]
             desc = gresults["descriptions"][i]
             msg += f"[{title}]({link})\n`{desc}`\n\n"
         except IndexError:
             break
     # result = ()
     await ctx.respond("**Query :**\n" + query + "\n\n**Result :**\n" + msg, link_preview=False)
コード例 #9
0
from search_engine_parser.core.engines.yahoo import Search as YahooSearch
from search_engine_parser.core.engines.google import Search as GoogleSearch
from search_engine_parser.core.engines.bing import Search as BingSearch
from search_engine_parser.core.engines.duckduckgo import Search as DuckSearch
import csv

#Intializing Search Engines
g_search = GoogleSearch()
y_search = YahooSearch()
b_search = BingSearch()
d_search = DuckSearch()

#Search prompt
search_query = input("Enter your search query here: ") 
search_set = (search_query, 1)
search_set2 = (search_query, 2)

#Searching for query
g_results = g_search.search(*search_set)
b_results = b_search.search(*search_set2)
d_results = d_search.search(*search_set2)
y_results = y_search.search(*search_set)

#Create csv file
with open('data.csv','w',newline='') as file:
    #Creating writer
    writer = csv.writer(file)
    #Writing each row's header
    writer.writerow(['Bing','DuckDuckGo','Google','Yahoo'])
    #Print first 20 links for each search engine (can comment)
    for i in range(0,21):
コード例 #10
0
ファイル: unconditional.py プロジェクト: thevickypedia/Jarvis
def google(query: str, suggestion_count: int = 0) -> None:
    """Uses Google's search engine parser and gets the first result that shows up on a Google search.

    Notes:
        - If it is unable to get the result, Jarvis sends a request to ``suggestqueries.google.com``
        - This is to rephrase the query and then looks up using the search engine parser once again.
        - ``suggestion_count`` is used to limit the number of times suggestions are used.
        - ``suggestion_count`` is also used to make sure the suggestions and parsing don't run on an infinite loop.
        - This happens when ``google`` gets the exact search as suggested ones which failed to fetch results earlier.

    Args:
        suggestion_count: Integer value that keeps incrementing when ``Jarvis`` looks up for suggestions.
        query: Takes the voice recognized statement as argument.
    """
    results = []
    try:
        google_results = GoogleSearch().search(query, cache=False)
        results = [result['titles'] for result in google_results]
    except NoResultsOrTrafficError:
        suggest_url = "https://suggestqueries.google.com/complete/search"
        params = {
            "client": "firefox",
            "q": query,
        }
        response = requests.get(suggest_url, params)
        if not response:
            return
        try:
            suggestion = response.json()[1][1]
            suggestion_count += 1
            if suggestion_count >= 3:  # avoids infinite suggestions over the same suggestion
                speaker.speak(text=response.json()[1][0].replace('=', ''),
                              run=True)  # picks the closest match and Google's it
                return
            else:
                google(suggestion, suggestion_count)
        except IndexError:
            return

    if not results:
        return

    for result in results:
        if len(result.split()) < 3:
            results.remove(result)

    if not results:
        return

    results = results[0:3]  # picks top 3 (first appeared on Google)
    results.sort(key=lambda x: len(x.split()), reverse=True)  # sorts in reverse by the word count of each sentence
    output = results[0]  # picks the top most result
    if '\n' in output:
        required = output.split('\n')
        modify = required[0].strip()
        split_val = ' '.join(wordninja.split(modify.replace('.', 'rEpLaCInG')))
        sentence = split_val.replace(' rEpLaCInG ', '.')
        repeats = []  # Captures repeated words by adding them to the empty list
        [repeats.append(word) for word in sentence.split() if word not in repeats]
        refined = ' '.join(repeats)
        output = refined + required[1] + '.' + required[2]
    output = output.replace('\\', ' or ')
    match_word = re.search(r'(\w{3},|\w{3}) (\d,|\d|\d{2},|\d{2}) \d{4}', output)
    if match_word:
        output = output.replace(match_word.group(), '')
    output = output.replace('\\', ' or ')
    speaker.speak(text=output, run=True)
コード例 #11
0
ファイル: .engine.py プロジェクト: saeedo201/Engine-Searches
                    type="string",
                    help="Engine: google, yahoo, yandex, bing, ask, all")
(option, args) = optparse.parse_args()
if option.domin == None and option.engine == None:
    print(optparse.usage)
    exit(0)
elif option.engine not in ("google", "yahoo", "bing", "ask", "yandex", "all"):
    os.system('printf "\e[1;31m"')
    print(
        "Invalid search engine, try with: google, yahoo, bing, ask, yandex, all"
    )
    exit(0)
else:
    if option.engine == "google":
        print("[-] Searching in Google:")
        gsearch = GoogleSearch()
        gresults = gsearch.search(option.domin, 1)
        a = {"Google": gresults}
        for k, v in a.items():
            os.system('printf "\e[1;35m"')
            print(f"-------------{k}------------")
            #pprint.pprint(a[k]['links'])
            data_list = (a[k]['links'])
            data = '\n'.join(data_list)
            with open("google.txt", "a") as f:
                f.write(f"-------------{k}------------\n")
                f.write(data)
    elif option.engine == "yahoo":
        print("[-] Searching in Yahoo:")
        yasearch = YahooSearch()
        yaresults = yasearch.search(option.domin, 1)