This commit is contained in:
Ben Harris committed 2018-10-09 02:50:10 -04:00
1 parent a8a5de36f2
commit 58753c7234
38 files changed
+4549 -2523

No files matched your search

+9 -7
View File
@@ -2,17 +2,19 @@ import duckduckgo
import urllib
from bs4 import BeautifulSoup
def xkcd(query):
res = duckduckgo.get_zci('site:xkcd.com ' + query);
title = "";
try: #ddg returns a url for these searches. i want a title as well
title = BeautifulSoup(urllib.urlopen(res).read(), 'html.parser').title.text
res = duckduckgo.get_zci("site:xkcd.com " + query)
title = ""
try: # ddg returns a url for these searches. i want a title as well
title = BeautifulSoup(urllib.urlopen(res).read(), "html.parser").title.text
except:
pass #just swallow the error. maybe the result wasn't a url or something else bad happened
return [(((title + ' - ') if title else '') + res).encode('ascii', 'ignore')]
pass # just swallow the error. maybe the result wasn't a url or something else bad happened
return [(((title + " - ") if title else "") + res).encode("ascii", "ignore")]
# never mind, blocked by ddg
#def xkcd_links(query):
# def xkcd_links(query):
# url = "https://duckduckgo.com/html/?q=site%3Axkcd.com+" + query.replace(' ', '+')
# soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
# items = soup.find_all("a", class_="result__a")