mirror of
https://github.com/RussellChamp/tilde-projects.git
synced 2026-10-28 00:22:34 +00:00
black
This commit is contained in:
38 files changed
+4549
-2523
No files matched your search
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user