Python Final Project: Einstein Tweet Bot


Hey guys. After a long time hitting my head against the wall trying to figure out how to do simple things I just didn't yet know how to do, I finally broke through to the other side and have some semblance of a completely final project for the Python course.

I have written a simple tweet bot that scrapes 25 Einstein quotes from a goodreads website, then formats the code into text that the markhov chain generator can read, saves it to a text doc, and spits out a brand new quote from Einstein. I call it Einstein Remastered.

It definitely does not work perfectly. It sometimes takes large chunks of quotes directly (I think the sample size of 25 quotes did not provide enough variety). It also is still all lowercase, and has no punctuation.

Please let me know what you think of my code, or if you have any improvements you think I could make!

Here is my fetch_data file

import html2text
from re import sub
from urllib2 import urlopen
from bs4 import BeautifulSoup

bswebpage=BeautifulSoup(urlpage, 'lxml')

for result in results:
    equotes += sub("“|.”","","".join(result.contents[0:1]).strip())

with open("EinsteinQuotes.txt", "w") as f:

And here is my file:

from markov_python.cc_markov import MarkovChain
import string
from re import sub

mc = MarkovChain()

EinsteinRemastered = []

EinsteinRemastered += (mc.generate_text(18))

output = " ".join(EinsteinRemastered)
print sub('\xe2\x80\x9d|\xe2\x80\x9c|“|”', '', output)