mirror of
https://github.com/RussellChamp/tilde-projects.git
synced 2026-10-28 00:22:34 +00:00
Just some new banterbot trick and changes and things
This commit is contained in:
1 parent
10d2aef8d0
commit
5bd1f60a0b
24 files changed
+784
-40
No files matched your search
@@ -0,0 +1,24 @@
|
||||
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
|
||||
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')
|
||||
|
||||
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
|
||||
Reference in new issue
Block a user