mirror of
https://github.com/RussellChamp/tilde-projects.git
synced 2026-10-28 08:32:32 +00:00
Random update of various things
This commit is contained in:
1 parent
d76dd9c674
commit
57485f6ffd
22 files changed
+269
-73
No files matched your search
+16
-12
@@ -9,16 +9,20 @@ def xkcd(query):
|
||||
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')
|
||||
return [(((title + ' - ') if title else '') + res).encode('ascii', 'ignore')]
|
||||
|
||||
def xkcd_links(query):
|
||||
url = "https://duckduckgo.com/html/?q=site%3Axkcd.com+" + query.replace(' ', '+')
|
||||
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
|
||||
links = filter(lambda a: a[0:8] == 'xkcd.com', [a.text.strip() for a in soup.find_all("div", class_="url")])
|
||||
def pretty_link(url):
|
||||
data = BeautifulSoup(urllib.urlopen('http://'+url).read(), 'html.parser')
|
||||
title = data.title.text if data.title else ''
|
||||
return (title + ' - ' + url) if title else url
|
||||
|
||||
links = map(lambda url: pretty_link(url), links)
|
||||
return links
|
||||
# never mind, blocked by ddg
|
||||
#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")
|
||||
# print items
|
||||
# items = filter(lambda i: i[0:8] == 'xkcd.com', [i.find(class_="result__title").text.strip() for i in items])
|
||||
# print items
|
||||
# def pretty_link(item):
|
||||
# url = item.find(class_="result__url").text.strip()
|
||||
# title = item.find(class_="result__title").text.strip()
|
||||
# return (title + ' - ' + url) if title else url
|
||||
#
|
||||
# links = map(lambda url: pretty_link(url), items)
|
||||
# return links
|
||||
Reference in new issue
Block a user