Commit 2ba88b2d authored by renzo's avatar renzo

mails agregados

parent 0d63f875
......@@ -2,27 +2,31 @@
import multiprocessing
import argparse
import os
from datetime import date
import datetime
import utils
def download_hycom(tmp_path, parallel_downloads=5):
# Genero la cola de descargas con tuplas de la forma (url, destination_path)
download_queue = []
today = date.today().strftime("%Y%m%d")
destination_folder = tmp_path + "/" + today
def download_hycom(tmp_path, parallel_downloads=5, day=""):
if day == "today" or not day:
day = datetime.date.today().strftime("%Y%m%d")
elif day == "yesterday":
day = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y%m%d")
destination_folder = tmp_path + "/" + day
if destination_folder and not os.path.exists(destination_folder):
os.makedirs(destination_folder)
# Genero la cola de descargas con tuplas de la forma (url, destination_path)
download_queue = []
for ending in ["prog", "diag"]:
for i in range(0, 49, 1):
url = "https://nomads.ncep.noaa.gov/pub/data/nccf/com/rtofs/prod/rtofs." \
+ today + "/rtofs_glo_2ds_n" + str(i).zfill(3) + "_1hrly_" + ending + ".nc"
+ day + "/rtofs_glo_2ds_n" + str(i).zfill(3) + "_1hrly_" + ending + ".nc"
destination_file = destination_folder + "/" + url.split("/")[-1]
download_queue.append((url, destination_file))
for i in range(0, 73, 1):
url = "https://nomads.ncep.noaa.gov/pub/data/nccf/com/rtofs/prod/rtofs." \
+ today + "/rtofs_glo_2ds_f" + str(i).zfill(3) + "_1hrly_" + ending + ".nc"
+ day + "/rtofs_glo_2ds_f" + str(i).zfill(3) + "_1hrly_" + ending + ".nc"
destination_file = destination_folder + "/" + url.split("/")[-1]
download_queue.append((url, destination_file))
......@@ -37,10 +41,14 @@ if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('tmp_path', type=str,
help='La carpeta base donde se realizan las descargas del proyecto')
parser.add_argument('--day', type=str, choices=["today", "yesterday"])
parser.add_argument('--parallel', type=int,
help='Ingrese la cantidad de descargas paralelas')
args = parser.parse_args()
if args.parallel is not None:
download_hycom(args.tmp_path, day=args.day)
elif args.day is None:
download_hycom(args.tmp_path, args.parallel)
else:
download_hycom(args.tmp_path)
download_hycom(args.tmp_path, args.parallel, args.day)
\ No newline at end of file
import os
import sys
import time
import requests
......@@ -14,15 +12,4 @@ def process_url(url_path_pair):
for chunk in r.iter_content(chunk_size=1024 * 1024):
if chunk:
f.write(chunk)
os.rename(tmp_destination, destination)
def enable_logs(path, filename):
global log_path
log_path = path + "/" + filename
if not os.path.exists(path):
os.makedirs(path)
log_file = open(log_path, "a")
sys.stdout = log_file
sys.stderr = log_file
return log_file
os.rename(tmp_destination, destination)
\ No newline at end of file
......@@ -15,7 +15,7 @@ PASSWORD = credentials.PASSWORD
def get_contacts(filename):
"""
Return two lists names, emails containing names and email addresses
read from a file specified by filename.
read from a name specified by filename.
"""
names = []
......@@ -30,7 +30,7 @@ def get_contacts(filename):
def read_template(filename):
"""
Returns a Template object comprising the contents of the
file specified by filename.
name specified by filename.
"""
with open(filename, 'r', encoding='utf-8') as template_file:
......@@ -38,7 +38,7 @@ def read_template(filename):
return Template(template_file_content)
def send(script, additional_msg=None, log_path=None):
def send(script, additional_msg="", log_path=None):
names, emails = get_contacts('contacts.conf') # read contacts
message_template = read_template('message.conf')
......@@ -72,7 +72,7 @@ def send(script, additional_msg=None, log_path=None):
f.read(),
Name="log.txt"
)
# After the file is closed
# After the name is closed
part['Content-Disposition'] = 'attachment; filename="%s"' % "log"
msg.attach(part)
......
......@@ -11,6 +11,7 @@ import time
import metadata
import process.process as exec
from mail import mail
log_handle = 0
......@@ -132,5 +133,6 @@ if __name__ == "__main__":
log_time(source)
logging.exception(str(datetime.datetime.now()) + "\n" + repr(e))
stop_logging(source)
mail.send(source)
finally:
enable_same_calls(lock_handle)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment