Hey, here’s a Q&D script to get a random quote from the bash.org quotedb.
August 11th, 2003
Hey, here’s a Q&D script to get a random quote from the bash.org quotedb. Enjoy. (Note that some
quotes are just not safe for work. This is the nature of
bash.org.)
#!/usr/bin/python
# bash.org random quotefetcher, by dsandler.org
import sys, urllib, re
URL = "http://bash.org/?random1"
fetch = urllib.urlopen(URL)
quote = ""
line = 1
while line:
line = fetch.readline()
if re.match(r'<p class="quote">', line):
quote = line
line = ""
while line:
line = fetch.readline()
if re.match(r'<p class="quote">', line):
line = ""
else:
quote = quote + line
fetch.close()
if quote != "":
sys.stdout.write(quote)