mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
test
This commit is contained in:
parent
171b0f9a52
commit
3af17d26d3
@ -5,7 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
|||||||
import requests
|
import requests
|
||||||
import urllib
|
import urllib
|
||||||
from fake_useragent import UserAgent
|
from fake_useragent import UserAgent
|
||||||
import json
|
import re
|
||||||
|
|
||||||
from sopel.config.types import StaticSection, ValidatedAttribute
|
from sopel.config.types import StaticSection, ValidatedAttribute
|
||||||
|
|
||||||
@ -13,8 +13,6 @@ from .Config import config as botconfig
|
|||||||
from .Read import read as botread
|
from .Read import read as botread
|
||||||
from .Commands import commands as botcommands
|
from .Commands import commands as botcommands
|
||||||
|
|
||||||
from .Logs import logs
|
|
||||||
|
|
||||||
# TODO add a cache flush
|
# TODO add a cache flush
|
||||||
|
|
||||||
|
|
||||||
@ -46,7 +44,6 @@ class Search():
|
|||||||
# check cache
|
# check cache
|
||||||
if search_api not in list(self.cache.keys()):
|
if search_api not in list(self.cache.keys()):
|
||||||
self.cache[search_api] = dict()
|
self.cache[search_api] = dict()
|
||||||
logs.log("SpiceBot_Search", "Found " + str(len(list(self.valid_api.keys()))) + " search APIs", True)
|
|
||||||
|
|
||||||
def setup_search(self):
|
def setup_search(self):
|
||||||
botconfig.define_section("SpiceBot_Search", SpiceBot_Search_MainSection, validate=False)
|
botconfig.define_section("SpiceBot_Search", SpiceBot_Search_MainSection, validate=False)
|
||||||
@ -118,19 +115,15 @@ class Search():
|
|||||||
return var.url
|
return var.url
|
||||||
|
|
||||||
def search_urban(self, searchdict):
|
def search_urban(self, searchdict):
|
||||||
"""Search Urban Dictionary."""
|
query = requests.get(searchdict["searchurl"]).json()
|
||||||
|
if query:
|
||||||
try:
|
try:
|
||||||
data = requests.get(searchdict["searchurl"])
|
_definition = query['list'][0]['definition'].strip().replace(' ', ' ')
|
||||||
data = json.loads(data.decode('utf-8'))
|
definition = re.sub(r"\[*\]*", "", _definition)
|
||||||
|
return str(searchdict["query"]) + " " + str(definition)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logs.log("SpiceBot_Search", str(e), True)
|
definition = e
|
||||||
data = e
|
|
||||||
return None
|
return None
|
||||||
if data['result_type'] == 'no_results':
|
|
||||||
return None
|
|
||||||
result = data['list'][0]
|
|
||||||
response = "{0} - {1}".format(result['definition'].strip()[:256], searchdict["searchurl"])
|
|
||||||
return response
|
|
||||||
|
|
||||||
|
|
||||||
search = Search()
|
search = Search()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user