92 lines
4.5 KiB
Python
92 lines
4.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
from irc3.plugins.command import command
|
|
import irc3
|
|
import requests
|
|
###########################################################################################
|
|
###########################################################################################
|
|
@irc3.plugin
|
|
class Plugin:
|
|
#######################################################################################
|
|
#######################################################################################
|
|
def __init__(self, bot):
|
|
self.bot = bot
|
|
#######################################################################################
|
|
#######################################################################################
|
|
def _get_weed(self,t,s):
|
|
try:
|
|
url=""
|
|
if t == "search":
|
|
s = s.lower().replace(' ','-')
|
|
url = 'https://api.wikileaf.com/api/v7/search/all/?type=S&num=24&offset=0&sort=popular&query={}'.format(s)
|
|
if t == "review":
|
|
url = 'https://api.wikileaf.com/api/v6/reviews/?content_type__model=strain&object_id={}'.format(s)
|
|
r = requests.get(url)
|
|
try:
|
|
if r.json()['detail'] == 'Not found.':
|
|
return 'Not Found.'
|
|
except:
|
|
return r.json()
|
|
except:
|
|
return -1
|
|
#######################################################################################
|
|
#######################################################################################
|
|
@command(permission='view')
|
|
def strain(self, mask, target, args):
|
|
"""strain
|
|
%%strain <message>...
|
|
"""
|
|
try:
|
|
msg = ' '.join(args['<message>'])
|
|
r_strain_id = -1
|
|
r = self._get_weed('search',msg)
|
|
b = r['results'][0]
|
|
try:
|
|
r_name = b['name']
|
|
r_score = b['score']
|
|
r_review_avg = b['review_avg']
|
|
r_review_count = b['review_count']
|
|
r_type = b['type']
|
|
r_compound_thc_min = b['compound']['THC']['min']
|
|
r_compound_thc_max = b['compound']['THC']['max']
|
|
r_compound_cbd_min = b['compound']['CBD']['min']
|
|
r_compound_cbd_max = b['compound']['CBD']['max']
|
|
r_consumption_time = b['consumption_time']
|
|
r_uses = b['uses']
|
|
r_effects = b['effects']
|
|
r_logo_url = "https://assets.wikileaf.com/{}".format(b['logo_url'])
|
|
r_strain_id = b['strain_id']
|
|
msg = "▶ name: {}".format(r_name)
|
|
msg = msg + " ▶ " + "score: {}".format(r_score)
|
|
msg = msg + " ▶ " + "review avg: {}".format(r_review_avg)
|
|
msg = msg + " ▶ " + "review count: {}".format(r_review_count)
|
|
msg = msg + " ▶ " + "type: {}".format(r_type)
|
|
msg = msg + " ▶ " + "compound thc min: {} / max: {}".format(r_compound_thc_min,r_compound_thc_max)
|
|
msg = msg + " ▶ " + "compound cbd min: {} / max: {}".format(r_compound_cbd_min,r_compound_cbd_max)
|
|
msg = msg + " ▶ " + "consumption time: {}".format(r_consumption_time)
|
|
msg = msg + " ▶ " + "uses: {}".format(r_uses)
|
|
msg = msg + " ▶ " + "effects: {}".format(r_effects)
|
|
msg = msg + " ▶ " + "logo: {}".format(r_logo_url)
|
|
self.bot.privmsg(target, msg)
|
|
except:
|
|
msg = "strain: not found"
|
|
self.bot.privmsg(target, msg)
|
|
try:
|
|
r = self._get_weed('review',r_strain_id)
|
|
b = r['results']
|
|
for i,_ in enumerate(b):
|
|
msg = "▶▶ " + "review {} - rating: {} / comment: {}".format(i+1,_['rating'],_['comment'])
|
|
self.bot.privmsg(target, msg)
|
|
if i >= 2: break
|
|
url = b[0]['url']
|
|
msg = "▶▶▶ " + "url: {}".format(url)
|
|
self.bot.privmsg(target, msg)
|
|
except:
|
|
pass
|
|
except:
|
|
msg = "strain: not found"
|
|
self.bot.privmsg(target, msg)
|
|
#######################################################################################
|
|
#######################################################################################
|
|
###########################################################################################
|
|
###########################################################################################
|