diff --git a/process_report/invoices/billable_invoice.py b/process_report/invoices/billable_invoice.py index 1761cc8..2546573 100644 --- a/process_report/invoices/billable_invoice.py +++ b/process_report/invoices/billable_invoice.py @@ -1,15 +1,10 @@ from dataclasses import dataclass -import logging import pandas import pyarrow from process_report.invoices import invoice -logger = logging.getLogger(__name__) -logging.basicConfig(level=logging.INFO) - - @dataclass class BillableInvoice(invoice.Invoice): """ diff --git a/process_report/process_report.py b/process_report/process_report.py index 49b7644..faf7818 100644 --- a/process_report/process_report.py +++ b/process_report/process_report.py @@ -1,6 +1,7 @@ import argparse import sys import datetime +import logging import pandas import pyarrow @@ -58,6 +59,10 @@ ALIAS_S3_FILEPATH = "PIs/alias.csv" +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.INFO) + + def load_alias(alias_file): alias_dict = dict() @@ -67,7 +72,7 @@ def load_alias(alias_file): pi_alias_info = line.strip().split(",") alias_dict[pi_alias_info[0]] = pi_alias_info[1:] except FileNotFoundError: - print("Validating PI aliases failed. Alias file does not exist") + logging.error("Validating PI aliases failed. Alias file does not exist") sys.exit(1) return alias_dict @@ -199,11 +204,11 @@ def main(): with open(args.projects_file) as file: projects = [line.rstrip() for line in file] - print("Invoice date: " + str(invoice_month)) + logger.info("Invoice date: " + str(invoice_month)) timed_projects_list = timed_projects(args.timed_projects_file, invoice_month) - print("The following timed-projects will not be billed for this period: ") - print(timed_projects_list) + logger.info("The following timed-projects will not be billed for this period: ") + logger.info(timed_projects_list) projects = list(set(projects + timed_projects_list)) diff --git a/process_report/processors/add_institution_processor.py b/process_report/processors/add_institution_processor.py index ecd2530..1440c49 100644 --- a/process_report/processors/add_institution_processor.py +++ b/process_report/processors/add_institution_processor.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +import logging import pandas @@ -7,6 +8,10 @@ from process_report import util +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.INFO) + + @dataclass class AddInstitutionProcessor(processor.Processor): @staticmethod @@ -27,7 +32,7 @@ def _get_institution_from_pi(institute_map, pi_uname): institution_domain = institution_domain[institution_domain.find(".") + 1 :] if institution_name == "": - print(f"Warning: PI name {pi_uname} does not match any institution!") + logger.warning(f"PI name {pi_uname} does not match any institution!") return institution_name @@ -49,7 +54,7 @@ def _add_institution(self): for i, row in self.data.iterrows(): pi_name = row[invoice.PI_FIELD] if pandas.isna(pi_name): - print(f"Project {row[invoice.PROJECT_FIELD]} has no PI") + logger.info(f"Project {row[invoice.PROJECT_FIELD]} has no PI") else: self.data.at[ i, invoice.INSTITUTION_FIELD diff --git a/process_report/processors/new_pi_credit_processor.py b/process_report/processors/new_pi_credit_processor.py index 576c50b..90e93ce 100644 --- a/process_report/processors/new_pi_credit_processor.py +++ b/process_report/processors/new_pi_credit_processor.py @@ -1,4 +1,5 @@ import sys +import logging from dataclasses import dataclass import pandas @@ -9,6 +10,10 @@ from process_report.processors import discount_processor +logger = logging.getLogger(__name__) +logging.basicConfig(level=logging.INFO) + + @dataclass class NewPICreditProcessor(discount_processor.DiscountProcessor): """ @@ -114,7 +119,9 @@ def get_initial_credit_amount( new_pi_credit_amount = get_initial_credit_amount( old_pi_df, self.invoice_month, self.INITIAL_CREDIT_AMOUNT ) - print(f"New PI Credit set at {new_pi_credit_amount} for {self.invoice_month}") + logger.info( + f"New PI Credit set at {new_pi_credit_amount} for {self.invoice_month}" + ) credit_eligible_projects = self._get_credit_eligible_projects(data) current_pi_set = set(credit_eligible_projects[invoice.PI_FIELD]) @@ -168,8 +175,8 @@ def get_initial_credit_amount( if (pi_old_pi_entry[credit_used_field] != 0) and ( credits_used != pi_old_pi_entry[credit_used_field] ): - print( - f"Warning: PI file overwritten. PI {pi} previously used ${pi_old_pi_entry[credit_used_field]} of New PI credits, now uses ${credits_used}" + logger.warning( + f"PI file overwritten. PI {pi} previously used ${pi_old_pi_entry[credit_used_field]} of New PI credits, now uses ${credits_used}" ) old_pi_df.loc[ old_pi_df[invoice.PI_PI_FIELD] == pi, credit_used_field diff --git a/process_report/util.py b/process_report/util.py index 41c7419..b6f9058 100644 --- a/process_report/util.py +++ b/process_report/util.py @@ -23,7 +23,9 @@ def get_invoice_bucket(): aws_secret_access_key=os.environ["S3_APP_KEY"], ) except KeyError: - print("Error: Please set the environment variables S3_KEY_ID and S3_APP_KEY") + logger.error( + "Error: Please set the environment variables S3_KEY_ID and S3_APP_KEY" + ) return s3_resource.Bucket(os.environ.get("S3_BUCKET_NAME", "nerc-invoicing"))