mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
test urban
This commit is contained in:
parent
fdd06256bf
commit
9843fd55e3
@ -5,6 +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
|
||||||
|
|
||||||
from sopel.config.types import StaticSection, ValidatedAttribute
|
from sopel.config.types import StaticSection, ValidatedAttribute
|
||||||
|
|
||||||
@ -12,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
|
||||||
|
|
||||||
|
|
||||||
@ -89,24 +88,10 @@ class Search():
|
|||||||
return returnurl
|
return returnurl
|
||||||
|
|
||||||
def search_handler(self, searchdict):
|
def search_handler(self, searchdict):
|
||||||
try:
|
if searchdict["query_type"] in ["urban"]:
|
||||||
results = requests.get(searchdict["searchurl"], headers=self.header).text()
|
return self.search_urban(searchdict)
|
||||||
except Exception as e:
|
else:
|
||||||
results = e
|
return self.search_url(searchdict)
|
||||||
logs.log('SpiceBot_Search', str(e))
|
|
||||||
return None
|
|
||||||
logs.log('SpiceBot_Search', str(results))
|
|
||||||
return None
|
|
||||||
|
|
||||||
def search_handler_old(self, searchdict):
|
|
||||||
try:
|
|
||||||
var = requests.get(searchdict["searchurl"], headers=self.header)
|
|
||||||
except Exception as e:
|
|
||||||
var = e
|
|
||||||
var = None
|
|
||||||
if not var or not var.url:
|
|
||||||
return None
|
|
||||||
return var.url
|
|
||||||
|
|
||||||
def search_url_assemble(self, searchdict):
|
def search_url_assemble(self, searchdict):
|
||||||
# url base
|
# url base
|
||||||
@ -119,5 +104,29 @@ class Search():
|
|||||||
url += str(self.valid_api[searchdict["query_type"]]['additional_url'])
|
url += str(self.valid_api[searchdict["query_type"]]['additional_url'])
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
def search_url(self, searchdict):
|
||||||
|
try:
|
||||||
|
var = requests.get(searchdict["searchurl"], headers=self.header)
|
||||||
|
except Exception as e:
|
||||||
|
var = e
|
||||||
|
var = None
|
||||||
|
if not var or not var.url:
|
||||||
|
return None
|
||||||
|
return var.url
|
||||||
|
|
||||||
|
def search_urban(self, searchdict):
|
||||||
|
"""Search Urban Dictionary."""
|
||||||
|
try:
|
||||||
|
data = requests.get(searchdict["searchurl"])
|
||||||
|
data = json.loads(data.decode('utf-8'))
|
||||||
|
except Exception as e:
|
||||||
|
data = e
|
||||||
|
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()
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"url": "http://www.google.com/maps/place/",
|
"url": "http://www.google.com/maps/place/",
|
||||||
"query": '',
|
|
||||||
"query_param": '',
|
"query_param": '',
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"url": "http://api.urbandictionary.com/v0/define?",
|
||||||
|
"query_param": 'term=',
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user