Last active
December 17, 2015 21:39
-
-
Save yasyf/5675822 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys, os, requests, json, random | |
from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL) | |
#from smtplib import SMTP | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
SMTPserver = '' | |
sender = '' | |
destination = '' | |
USERNAME = "" | |
PASSWORD = "" | |
TEXT_CONTENT="Mr. Warner,\n Below is suggestion %d of my classroom wall ideas.\n I hope you enjoy it! \n Link: %s\n Thanks,\n Yasyf \n\n\n %s" | |
HTML_CONTENT="Mr. Warner,<br /> Below is suggestion %d of my classroom wall ideas.<br /> I hope you enjoy it! <br /> Link: <a href='%s'>%s</a> <br />Thanks,<br /> Yasyf<br /><img src='%s' height='500' width='500' /><br /><br /><br /><small>%s</small>" | |
SUBJECT="Classroom Wall Idea %s" | |
QUERY = "math+pie" | |
BASE_URL = 'https://ajax.googleapis.com/ajax/services/search/images?'\ | |
'v=1.0&q=' + QUERY + '&start=%d' | |
JOKES = open("Quick Math Jokes.txt").readlines() | |
def scrape(n): | |
r = requests.get(BASE_URL % n) | |
url = json.loads(r.text)['responseData']['results'][0]['unescapedUrl'] | |
return url | |
def mail(n,link): | |
joke = JOKES[random.randint(0,len(JOKES)-1)] | |
text_content = TEXT_CONTENT % (n,link,joke) | |
html_content = HTML_CONTENT % (n,link,link,link,joke) | |
subject = SUBJECT % (n) | |
try: | |
msg = MIMEMultipart('alternative') | |
msg['Subject'] = subject | |
msg['From'] = sender | |
msg['To'] = destination | |
text = MIMEText(text_content, 'plain') | |
html = MIMEText(html_content, 'html') | |
msg.attach(text) | |
msg.attach(html) | |
conn = SMTP(SMTPserver) | |
conn.set_debuglevel(False) | |
conn.login(USERNAME, PASSWORD) | |
try: | |
conn.sendmail(sender, destination, msg.as_string()) | |
finally: | |
conn.close() | |
except Exception, exc: | |
sys.exit( "mail failed; %s" % str(exc) ) # give a error message | |
def main(): | |
for x in range(0,61): | |
try: | |
image = scrape(x) | |
print x,image | |
mail(x+1,image) | |
print "Mailed %s!" % x | |
except Exception: | |
pass | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mathematics is made of 50 percent formulas, 50 percent proofs, and 50 percent imagination. | |
An engineer thinks that his equations are an approximation to reality. A physicist thinks reality is an approximation to his equations. A mathematician doesn't care. | |
Old mathematicians never die; they just lose some of their functions. | |
Mathematicians are like Frenchmen: whatever you say to them, they translate it into their own language, and forthwith it means something entirely different. -- Goethe | |
Mathematics is the art of giving the same name to different things. -- J. H. Poincare | |
What is a rigorous definition of rigor? | |
There is no logical foundation of mathematics, and Gödel has proved it! | |
A topologist is a person who doesn't know the difference between a coffee cup and a doughnut. | |
A mathematician is a blind man in a dark room looking for a black cat which isn't there. (Charles R Darwin) | |
A statistician is someone who is good with numbers but lacks the personality to be an accountant. | |
Classification of mathematical problems as linear and nonlinear is like classification of the Universe as bananas and non-bananas. | |
A law of conservation of difficulties: there is no easy way to prove a deep result. | |
A tragedy of mathematics is a beautiful conjecture ruined by an ugly fact. | |
Algebraic symbols are used when you do not know what you are talking about. | |
Math is the language God used to write the universe. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment