Update plugin.py

This commit is contained in:
Gordon Shumway 2019-03-12 00:42:01 -04:00 committed by GitHub
parent e9ac0d6cb1
commit aff7c09943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -33,14 +33,14 @@ class WikiLeaf(callbacks.Plugin):
"""
strain = strain.replace(" ", "-").replace("#", "").lower()
searchurl = "https://duckduckgo.com/html/?q={0} site: wikileaf.com/strain".format(strain)
search = requests.get(searchurl)
soup = BeautifulSoup(search.text)
url = re.sub('\s+', '', soup.find("a", class_="result__url").getText())
data = requests.get("https://{0}".format(url))
if not data: # http fetch breaks.
irc.reply("ERROR")
return
try:
search = requests.get(searchurl)
soup = BeautifulSoup(search.text)
url = re.sub('\s+', '', soup.find("a", class_="result__url").getText())
data = requests.get("https://{0}".format(url))
if not data: # http fetch breaks.
irc.reply("ERROR")
return
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())