Add files via upload
This commit is contained in:
parent
813b4a9c17
commit
0d83ca18aa
|
|
@ -0,0 +1,45 @@
|
|||
###
|
||||
# Copyright (c) 2019 oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
"""
|
||||
WikiLeaf: Uses WikiLeaf API to retrieve information
|
||||
"""
|
||||
|
||||
import supybot
|
||||
import supybot.world as world
|
||||
|
||||
# Use this for the version of this plugin. You may wish to put a CVS keyword
|
||||
# in here if you're keeping the plugin in CVS or some similar system.
|
||||
__version__ = ""
|
||||
|
||||
# XXX Replace this with an appropriate author or supybot.Author instance.
|
||||
__author__ = supybot.authors.unknown
|
||||
|
||||
# This is a dictionary mapping supybot.Author instances to lists of
|
||||
# contributions.
|
||||
__contributors__ = {}
|
||||
|
||||
# This is a url where the most recent plugin package can be downloaded.
|
||||
__url__ = ''
|
||||
|
||||
from . import config
|
||||
from . import plugin
|
||||
from imp import reload
|
||||
# In case we're being reloaded.
|
||||
reload(config)
|
||||
reload(plugin)
|
||||
# Add more reloads here if you add third-party modules and want them to be
|
||||
# reloaded when this plugin is reloaded. Don't forget to import them as well!
|
||||
|
||||
if world.testing:
|
||||
from . import test
|
||||
|
||||
Class = plugin.Class
|
||||
configure = config.configure
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
###
|
||||
# Copyright (c) 2019, oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
import supybot.conf as conf
|
||||
import supybot.registry as registry
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization('WikiLeaf')
|
||||
except:
|
||||
# Placeholder that allows to run the plugin on a bot
|
||||
# without the i18n module
|
||||
_ = lambda x: x
|
||||
|
||||
|
||||
def configure(advanced):
|
||||
# This will be called by supybot to configure this module. advanced is
|
||||
# a bool that specifies whether the user identified themself as an advanced
|
||||
# user or not. You should effect your configuration by manipulating the
|
||||
# registry as appropriate.
|
||||
from supybot.questions import expect, anything, something, yn
|
||||
conf.registerPlugin('WikiLeaf', True)
|
||||
|
||||
|
||||
WikiLeaf = conf.registerPlugin('WikiLeaf')
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
###
|
||||
# Copyright (c) 2019 oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
import supybot.utils as utils
|
||||
from supybot.commands import *
|
||||
import supybot.plugins as plugins
|
||||
import supybot.ircutils as ircutils
|
||||
import supybot.callbacks as callbacks
|
||||
import supybot.ircmsgs as ircmsgs
|
||||
import requests
|
||||
import json
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
try:
|
||||
from supybot.i18n import PluginInternationalization
|
||||
_ = PluginInternationalization('WikiLeaf')
|
||||
except ImportError:
|
||||
# Placeholder that allows to run the plugin on a bot
|
||||
# without the i18n module
|
||||
_ = lambda x: x
|
||||
|
||||
class WikiLeaf(callbacks.Plugin):
|
||||
"""Uses API to retrieve information"""
|
||||
threaded = True
|
||||
|
||||
def strain(self, irc, msg, args, strain):
|
||||
"""<strain>
|
||||
Searches API based on user input
|
||||
"""
|
||||
strain = strain.replace(" ", "-").replace("#", "-").lower()
|
||||
url = "https://www.wikileaf.com/strain/{0}".format(strain)
|
||||
data = requests.get(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())
|
||||
description = re.sub('\s+', ' ', soup.find("div", itemprop='description').getText())
|
||||
thc = re.sub('\s+', ' ', soup.find_all("div", class_="product-container-header cf")[1].getText())
|
||||
reply = "\x02{0}\x0F | {1} | {2}".format(name.strip(), thc.strip(), description.strip())
|
||||
if reply:
|
||||
irc.reply(reply)
|
||||
else:
|
||||
irc.reply('No results found, what have you been smoking?')
|
||||
|
||||
strain = wrap(strain, ['text'])
|
||||
|
||||
Class = WikiLeaf
|
||||
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
###
|
||||
# Copyright (c) 2019, oddluck
|
||||
# All rights reserved.
|
||||
#
|
||||
#
|
||||
###
|
||||
|
||||
from supybot.test import *
|
||||
|
||||
|
||||
class WikiLeafTestCase(PluginTestCase):
|
||||
plugins = ('WikiLeaf',)
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
||||
Loading…
Reference in New Issue