From c82f9f52195ba7717f04695cb1eb359e5402a6d6 Mon Sep 17 00:00:00 2001 From: Brian Wilson Date: Mon, 29 Jul 2019 16:57:03 -0400 Subject: [PATCH] Get cybersource and PayPal tasks running in py3. --- .../tasks/warehouse/financial/cybersource.py | 14 ++++++++------ edx/analytics/tasks/warehouse/financial/paypal.py | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/edx/analytics/tasks/warehouse/financial/cybersource.py b/edx/analytics/tasks/warehouse/financial/cybersource.py index ae625a2acd..3a9b3f5a35 100644 --- a/edx/analytics/tasks/warehouse/financial/cybersource.py +++ b/edx/analytics/tasks/warehouse/financial/cybersource.py @@ -86,11 +86,11 @@ def run(self): raise Exception(msg) # if there are no transactions in response, there will be no merchant id. - if self.merchant_id not in response.content and not self.is_empty_transaction_allowed: + if self.merchant_id.encode('utf8') not in response.content and not self.is_empty_transaction_allowed: raise Exception('No transactions to process.') with self.output().open('w') as output_file: - output_file.write(response.content) + output_file.write(response.content.decode('utf8')) def output(self): """Output is in the form {output_root}/cybersource/{CCYY-mm}/cybersource_{merchant}_{CCYYmmdd}.csv""" @@ -230,10 +230,12 @@ def __init__(self, *args, **kwargs): path_targets = PathSetTask([path], include=[file_pattern], include_zero_length=True).output() paths = list(set([os.path.dirname(target.path) for target in path_targets])) dates = [path.rsplit('/', 2)[-1] for path in paths] - latest_date = sorted(dates)[-1] - - latest_completion_date = datetime.datetime.strptime(latest_date, "dt=%Y-%m-%d").date() - run_date = latest_completion_date + datetime.timedelta(days=1) + if dates: + latest_date = sorted(dates)[-1] + latest_completion_date = datetime.datetime.strptime(latest_date, "dt=%Y-%m-%d").date() + run_date = latest_completion_date + datetime.timedelta(days=1) + else: + run_date = self.interval_start # Limit intervals to merchant account close date(if any). if self.merchant_close_date: diff --git a/edx/analytics/tasks/warehouse/financial/paypal.py b/edx/analytics/tasks/warehouse/financial/paypal.py index 5531f39373..bf3a425c2c 100644 --- a/edx/analytics/tasks/warehouse/financial/paypal.py +++ b/edx/analytics/tasks/warehouse/financial/paypal.py @@ -661,7 +661,9 @@ def write_transaction_record(self, row, output_tsv_file): # identifier for the transaction payment_record.paypal_transaction_id, ] - output_tsv_file.write(b'\t'.join(field.encode('utf-8') for field in record) + b'\n') + # output_tsv_file.write(b'\t'.join(field.encode('utf-8') for field in record) + b'\n') + # Apparently the write wants str, not bytes. + output_tsv_file.write('\t'.join(field for field in record) + '\n') def output(self): # NOTE: both the cybersource and paypal tasks write to the payments folder