Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Get cybersource and PayPal tasks running in py3.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhw committed Jul 29, 2019
1 parent 98b69af commit c82f9f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 8 additions & 6 deletions edx/analytics/tasks/warehouse/financial/cybersource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion edx/analytics/tasks/warehouse/financial/paypal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c82f9f5

Please sign in to comment.