From 932daf0d1e403a679a112f455a012068e28ea694 Mon Sep 17 00:00:00 2001 From: Gordon Shumway <39967334+oddluck@users.noreply.github.com> Date: Thu, 7 Feb 2019 08:16:05 -0500 Subject: [PATCH 1/4] Add files via upload --- __init__.py | 45 +++++++++++++++++++++++++++++++++ config.py | 35 ++++++++++++++++++++++++++ plugin.py | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test.py | 16 ++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 __init__.py create mode 100644 config.py create mode 100644 plugin.py create mode 100644 test.py diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..fc853c9 --- /dev/null +++ b/__init__.py @@ -0,0 +1,45 @@ +### +# Copyright (c) 2019 oddluck +# All rights reserved. +# +# +### + +""" +Weed: Uses Weed 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: diff --git a/config.py b/config.py new file mode 100644 index 0000000..3017fbb --- /dev/null +++ b/config.py @@ -0,0 +1,35 @@ +### +# Copyright (c) 2019, oddluck +# All rights reserved. +# +# +### + +import supybot.conf as conf +import supybot.registry as registry +try: + from supybot.i18n import PluginInternationalization + _ = PluginInternationalization('Weed') +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('Weed', True) + + +Weed = conf.registerPlugin('Weed') + +conf.registerGlobalValue(Weed, 'strain_api', +registry.String('', _("""Strain API Key"""))) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: + diff --git a/plugin.py b/plugin.py new file mode 100644 index 0000000..5a49b4f --- /dev/null +++ b/plugin.py @@ -0,0 +1,71 @@ +### +# 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 + +try: + from supybot.i18n import PluginInternationalization + _ = PluginInternationalization('Weed') +except ImportError: + # Placeholder that allows to run the plugin on a bot + # without the i18n module + _ = lambda x: x + +class Weed(callbacks.Plugin): + """Uses API to retrieve information""" + threaded = True + + def strain(self, irc, msg, args, strain): + """ + Searches API based on user input + """ + + response1 = None + response2 = None + channel = msg.args[0] + strain = re.sub('[^\w\:\"\#\-\.\' ]', '', strain).casefold() + strain_api = self.registryValue('strain_api') + + url = "http://strainapi.evanbusse.com/{0}/strains/search/name/{1}".format(strain_api, strain) + + data = requests.get(url).json() + + for item in data: + if item['desc'] is not None and item['name'].casefold() == strain: + name = ircutils.bold(item['name']) + type = ircutils.bold(item['race']) + desc = item['desc'] + response1 = "{0} :: {1} :: {2}".format(name, type, desc) + break + for item in data: + if item['desc'] is not None and item['name'].casefold() != strain: + name = ircutils.bold(item['name']) + type = ircutils.bold(item['race']) + desc = item['desc'] + response2 = "{0} :: {1} :: {2}".format(name, type, desc) + break + if response1 != None: + irc.reply(response1) + elif response1 == None and response2 != None: + irc.reply(response2) + else: + irc.reply('No results found, what have you been smoking?') + + strain = wrap(strain, ['text']) + +Class = Weed + + +# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/test.py b/test.py new file mode 100644 index 0000000..7581c07 --- /dev/null +++ b/test.py @@ -0,0 +1,16 @@ +### +# Copyright (c) 2019, oddluck +# All rights reserved. +# +# +### + +from supybot.test import * + + +class WeedTestCase(PluginTestCase): + plugins = ('Weed',) + + +# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: + From aaa55003b973aef2b438370a9cf13318e5d0b70f Mon Sep 17 00:00:00 2001 From: Gordon Shumway <39967334+oddluck@users.noreply.github.com> Date: Thu, 7 Feb 2019 08:18:28 -0500 Subject: [PATCH 2/4] Create README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..c389410 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Weed +Limnoria plugin to fetch cannabis (marijuana) strain information from the strain api (strains.evanbusse.com) + +obtain an api key from http://strains.evanbusse.com/ + +config plugins.weed.strain_api your_key_here From ab4b52450a0f37144998a78ca80952c9383fe951 Mon Sep 17 00:00:00 2001 From: Gordon Shumway <39967334+oddluck@users.noreply.github.com> Date: Thu, 7 Feb 2019 09:28:37 -0500 Subject: [PATCH 3/4] added flavors to output --- plugin.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/plugin.py b/plugin.py index 5a49b4f..45a4014 100644 --- a/plugin.py +++ b/plugin.py @@ -44,17 +44,34 @@ class Weed(callbacks.Plugin): for item in data: if item['desc'] is not None and item['name'].casefold() == strain: + id = item['id'] name = ircutils.bold(item['name']) type = ircutils.bold(item['race']) desc = item['desc'] - response1 = "{0} :: {1} :: {2}".format(name, type, desc) + url2 = "http://strainapi.evanbusse.com/{0}/strains/data/flavors/{1}".format(strain_api, id) + data2 = requests.get(url2).json() + flavor1 = data2[0] + flavor2 = data2[1] + flavor3 = data2[2] + response1 = "{0} | {1} | Flavors: {2}, {3}, {4} | {5}".format(name, type, flavor1, flavor2, flavor3, desc) break for item in data: if item['desc'] is not None and item['name'].casefold() != strain: + id = item['id'] name = ircutils.bold(item['name']) type = ircutils.bold(item['race']) desc = item['desc'] - response2 = "{0} :: {1} :: {2}".format(name, type, desc) + url2 = "http://strainapi.evanbusse.com/{0}/strains/data/flavors/{1}".format(strain_api, id) + data2 = requests.get(url2).json() + flavor1 = data2[0] + flavor2 = data2[1] + flavor3 = data2[2] + url3 = "http://strainapi.evanbusse.com/{0}/strains/data/flavors/{1}".format(strain_api, id) + data3 = requests.get(url2).json() + effect1 = data2[0] + effect2 = data2[1] + effect3 = data2[2] + response2 = "{0} | {1} | Flavors: {2}, {3}, {4} | {5}".format(name, type, flavor1, flavor2, flavor3, desc) break if response1 != None: irc.reply(response1) @@ -66,6 +83,3 @@ class Weed(callbacks.Plugin): strain = wrap(strain, ['text']) Class = Weed - - -# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: From 511b6d24d2f6c2a0e816772e991f96b5574d8307 Mon Sep 17 00:00:00 2001 From: Gordon Shumway <39967334+oddluck@users.noreply.github.com> Date: Thu, 7 Feb 2019 09:31:12 -0500 Subject: [PATCH 4/4] Add files via upload --- plugin.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugin.py b/plugin.py index 45a4014..da9e998 100644 --- a/plugin.py +++ b/plugin.py @@ -66,11 +66,6 @@ class Weed(callbacks.Plugin): flavor1 = data2[0] flavor2 = data2[1] flavor3 = data2[2] - url3 = "http://strainapi.evanbusse.com/{0}/strains/data/flavors/{1}".format(strain_api, id) - data3 = requests.get(url2).json() - effect1 = data2[0] - effect2 = data2[1] - effect3 = data2[2] response2 = "{0} | {1} | Flavors: {2}, {3}, {4} | {5}".format(name, type, flavor1, flavor2, flavor3, desc) break if response1 != None: