mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-05-07 20:07:01 -05:00
use gsearch for searches
This commit is contained in:
parent
9fe3ff13a0
commit
6b38d320b0
@ -15,6 +15,7 @@ import requests
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from fake_useragent import UserAgent
|
||||
from gsearch.googlesearch import search
|
||||
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
@ -30,16 +31,14 @@ class WikiLeaf(callbacks.Plugin):
|
||||
|
||||
def strain(self, irc, msg, args, strain):
|
||||
"""<strain>
|
||||
Returns strain information from WikiLeaf. Searches powered by DuckDuckGo.
|
||||
Returns strain information from WikiLeaf. Search powered by Google.
|
||||
"""
|
||||
searchurl = "https://duckduckgo.com/html/?q={0} site: wikileaf.com/strain".format(strain)
|
||||
ua = UserAgent()
|
||||
header = {'User-Agent':str(ua.random)}
|
||||
try:
|
||||
data = requests.get(searchurl, headers=header)
|
||||
soup = BeautifulSoup(data.text)
|
||||
url = re.sub('\s+', '', soup.find("a", class_="result__url").getText())
|
||||
data = requests.get("https://{0}".format(url), headers=header)
|
||||
ua = UserAgent()
|
||||
header = {'User-Agent':str(ua.random)}
|
||||
data = search("{0} site:wikileaf.com/strain/".format(strain), num_results=1)
|
||||
title, url = data[0]
|
||||
data = requests.get(url, headers=header)
|
||||
soup = BeautifulSoup(data.text)
|
||||
name = re.sub('\s+', ' ', soup.find("h1", itemprop="name").getText())
|
||||
straininfo = re.sub('\s+', ' ', soup.find("div", class_="product-info-line cannabis").getText())
|
||||
@ -53,3 +52,4 @@ class WikiLeaf(callbacks.Plugin):
|
||||
strain = wrap(strain, ['text'])
|
||||
|
||||
Class = WikiLeaf
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user