Created
August 13, 2010 13:12
-
-
Save bussiere/522850 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
#save img by gmail | |
import smtplib | |
from email.MIMEMultipart import MIMEMultipart | |
from email.MIMEBase import MIMEBase | |
from email.MIMEText import MIMEText | |
from email import Encoders | |
import os | |
import time | |
import sys | |
import re | |
import random | |
gmail_user = "toto@gmail.com" | |
gmail_pwd = "titi" | |
def mail(to, subject, text, attach): | |
msg = MIMEMultipart() | |
msg['From'] = gmail_user | |
msg['To'] = to | |
msg['Subject'] = subject | |
msg.attach(MIMEText(text)) | |
part = MIMEBase('application', 'octet-stream') | |
part.set_payload(open(attach, 'rb').read()) | |
Encoders.encode_base64(part) | |
part.add_header('Content-Disposition', | |
'attachment; filename="%s"' % os.path.basename(attach)) | |
msg.attach(part) | |
mailServer = smtplib.SMTP("smtp.gmail.com", 587) | |
mailServer.ehlo() | |
mailServer.starttls() | |
mailServer.ehlo() | |
mailServer.login(gmail_user, gmail_pwd) | |
mailServer.sendmail(gmail_user, to, msg.as_string()) | |
# Should be mailServer.quit(), but that crashes... | |
mailServer.close() | |
def send(location=""): | |
if location != "" : | |
location = location.replace("\\","/") | |
fichpython = re.compile(r"\.py") | |
fichjpg = re.compile(r"\.jpg|\.jpeg|\.JPG") | |
fichpng = re.compile(r"\.png|\.PNG|\.Png") | |
fichavi = re.compile(r"\.avi|\.mpg|\.AVI") | |
i = 0 | |
for file in os.listdir(""): | |
time.sleep(random.uniform(1,3)) | |
if not fichpython.search(file): | |
i= i +1 | |
if i > 0 : | |
print file | |
if fichjpg.search(file): | |
mail("toto@gmail.com",file,file,file) | |
else : | |
if fichpng.search(file): | |
mail("toto@gmail.com",file,file,file) | |
else : | |
if fichavi.search(file): | |
mail("toto@gmail.com",file,file,file) | |
if __name__ == "__main__": | |
try : | |
nfile = sys.argv[1] | |
except : | |
nfile = "" | |
send(location=nfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment