Skip to content

Instantly share code, notes, and snippets.

@bharadwaj-raju
Last active March 21, 2016 11:24
Show Gist options
  • Save bharadwaj-raju/fda25725661d9c4b2d52 to your computer and use it in GitHub Desktop.
Save bharadwaj-raju/fda25725661d9c4b2d52 to your computer and use it in GitHub Desktop.
Get quotes from the bash.org QDB
import urllib2
from bs4 import BeautifulSoup
import re
from random import randint
# Get quotes from bash.org
# Constants
TOP_100_URL = 'http://bash.org/?top'
TOP_200_URL = 'http://bash.org/?top2'
def hunter2():
# The best dialogue ever
return '''
<Cthon98> hey, if you type in your pw, it will show as stars
<Cthon98> ********* see!
<AzureDiamond> hunter2
<AzureDiamond> doesnt look like stars to me
<Cthon98> <AzureDiamond> *******
<Cthon98> thats what I see
<AzureDiamond> oh, really?
<Cthon98> Absolutely
<AzureDiamond> you can go hunter2 my hunter2-ing hunter2
<AzureDiamond> haha, does that look funny to you?
<Cthon98> lol, yes. See, when YOU type hunter2, it shows to us as *******
<AzureDiamond> thats neat, I didnt know IRC did that
<Cthon98> yep, no matter how many times you type hunter2, it will show to us as *******
<AzureDiamond> awesome!
<AzureDiamond> wait, how do you know my pw?
<Cthon98> er, I just copy pasted YOUR ******'s and it appears to YOU as hunter2 cause its your pw
<AzureDiamond> oh, ok.'''
def from_top_100(index=0):
if index >= 100:
raise ValueError('There are only 100 quotes.')
# Gets quote number index (default is 0 (hunter2)) from top 100 quotes
top_100_page = urllib2.urlopen(TOP_100_URL).read()
soup = BeautifulSoup(top_100_page, 'html.parser')
# qt is bash.org <p> class for quote text
return soup.findAll(attrs={'class': re.compile(r".*\bqt\b.*")})[index].get_text()
def from_top_200(index=0):
if index >= 100:
raise ValueError('There are only 100 quotes.')
# Gets quote number index (default is 0) from top 200 quotes
top_200_page = urllib2.urlopen(TOP_200_URL).read()
soup = BeautifulSoup(top_200_page, 'html.parser')
# qt is bash.org <p> class for quote text
return soup.findAll(attrs={'class': re.compile(r".*\bqt\b.*")})[index].get_text()
def random_top_100():
# Gets random quote from top 100 quotes
index = randint(0, 99)
top_100_page = urllib2.urlopen(TOP_100_URL).read()
soup = BeautifulSoup(top_100_page, 'html.parser')
# qt is bash.org <p> class for quote text
return soup.findAll(attrs={'class': re.compile(r".*\bqt\b.*")})[index].get_text()
def random_top_200():
# Gets random quote from top 100 quotes
index = randint(0, 99)
top_200_page = urllib2.urlopen(TOP_200_URL).read()
soup = BeautifulSoup(top_200_page, 'html.parser')
# qt is bash.org <p> class for quote text
return soup.findAll(attrs={'class': re.compile(r".*\bqt\b.*")})[index].get_text()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment