Download pool/shard004/Python/0035835_sendmail.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 2.02 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard004/Python/0035835_sendmail.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard004/Python/0035835_sendmail.py
-
curl -L -o 0035835_sendmail.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard004/Python/0035835_sendmail.py
2.02 kB
| #!/usr/bin/env python | |
| # coding=utf-8 | |
| import smtplib | |
| from email.mime.multipart import MIMEMultipart | |
| from email.mime.text import MIMEText | |
| # from email.MIMEText import MIMEText | |
| from email.mime.base import MIMEBase | |
| # from email.MIMEBase import MIMEBase | |
| from email import encoders | |
| import glob | |
| import click | |
| import os | |
| import json | |
| import datetime | |
| # filename = "output_Ctripplus_170614_1827_japan.xlsx" | |
| sendmail_secret = None | |
| with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'secrets.json')) as data_file: | |
| sendmail_secret = (json.load(data_file))['sendmail'] | |
| # @click.option('--duration', default=3, type=int) | |
| # @click.option('--days', default=1, type=int) | |
| def sendmail(filename, title): | |
| today_date = datetime.datetime.today().date() | |
| fromaddr = "tctctcly@gmail.com" | |
| # toaddr = "yu.leng@gta-travel.com, l" | |
| recipients = ['yu.leng@gta-travel.com', 'lily.yu@gta-travel.com', 'yun.liu@gta-travel.com'] | |
| msg = MIMEMultipart() | |
| msg['From'] = fromaddr | |
| # msg['To'] = toaddr | |
| msg['To'] = ", ".join(recipients) | |
| msg['Subject'] = title + '_' + today_date.strftime('%m%d') | |
| # body = "FYI\n\nThis email is auto generated by yu.leng@gta-travel.com." | |
| body = "This email is auto generated by yu.leng@gta-travel.com." | |
| msg.attach(MIMEText(body, 'plain')) | |
| newest = max(glob.iglob(filename), key=os.path.getctime) | |
| attachment = open(newest, "rb") | |
| part = MIMEBase('application', 'octet-stream') | |
| part.set_payload((attachment).read()) | |
| encoders.encode_base64(part) | |
| part.add_header('Content-Disposition', "attachment; filename= %s" % newest) | |
| msg.attach(part) | |
| server = smtplib.SMTP('smtp.gmail.com', 587) | |
| server.starttls() | |
| server.login(fromaddr, sendmail_secret['password']) | |
| text = msg.as_string() | |
| server.sendmail(fromaddr, recipients, text) | |
| server.quit() | |
| if __name__ == '__main__': | |
| sendmail() |