Last active
December 20, 2015 01:19
-
-
Save zopieux/6048112 to your computer and use it in GitHub Desktop.
This file contains 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
# -*- coding: utf-8 -*- | |
import smtplib | |
from email.mime.text import MIMEText | |
from email.header import Header | |
import urllib.request as urllib | |
from bs4 import BeautifulSoup | |
from random import choice | |
def randomWikipediaPage(): | |
opener = urllib.build_opener() | |
opener.addheaders = [('User-agent', 'Mozilla/5.0')] | |
infile = opener.open('http://fr.wikipedia.org/wiki/Special:Random') | |
return infile.read().decode('utf8') | |
def randomWikipediaSentence(): | |
soup = BeautifulSoup(randomWikipediaPage()).find(id="mw-content-text").find_all("p") | |
return choice([t.get_text() for t in soup if len(t.get_text()) > 30]) | |
def mailAll(subject, message, email, password): | |
smtpserver = smtplib.SMTP("smtp.enseirb-matmeca.fr",587) | |
smtpserver.ehlo() | |
smtpserver.starttls() | |
smtpserver.login(email, password) | |
msg = MIMEText(message, _charset="UTF-8") | |
msg['Subject'] = Header(subject, "utf-8") | |
msg['To'] = 'eleves' | |
smtpserver.sendmail(email, '[email protected]', msg.as_string()) | |
smtpserver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment