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

Commit c82f9f5

Browse files
committed
Get cybersource and PayPal tasks running in py3.
1 parent 98b69af commit c82f9f5

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

edx/analytics/tasks/warehouse/financial/cybersource.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ def run(self):
8686
raise Exception(msg)
8787

8888
# if there are no transactions in response, there will be no merchant id.
89-
if self.merchant_id not in response.content and not self.is_empty_transaction_allowed:
89+
if self.merchant_id.encode('utf8') not in response.content and not self.is_empty_transaction_allowed:
9090
raise Exception('No transactions to process.')
9191

9292
with self.output().open('w') as output_file:
93-
output_file.write(response.content)
93+
output_file.write(response.content.decode('utf8'))
9494

9595
def output(self):
9696
"""Output is in the form {output_root}/cybersource/{CCYY-mm}/cybersource_{merchant}_{CCYYmmdd}.csv"""
@@ -230,10 +230,12 @@ def __init__(self, *args, **kwargs):
230230
path_targets = PathSetTask([path], include=[file_pattern], include_zero_length=True).output()
231231
paths = list(set([os.path.dirname(target.path) for target in path_targets]))
232232
dates = [path.rsplit('/', 2)[-1] for path in paths]
233-
latest_date = sorted(dates)[-1]
234-
235-
latest_completion_date = datetime.datetime.strptime(latest_date, "dt=%Y-%m-%d").date()
236-
run_date = latest_completion_date + datetime.timedelta(days=1)
233+
if dates:
234+
latest_date = sorted(dates)[-1]
235+
latest_completion_date = datetime.datetime.strptime(latest_date, "dt=%Y-%m-%d").date()
236+
run_date = latest_completion_date + datetime.timedelta(days=1)
237+
else:
238+
run_date = self.interval_start
237239

238240
# Limit intervals to merchant account close date(if any).
239241
if self.merchant_close_date:

edx/analytics/tasks/warehouse/financial/paypal.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,9 @@ def write_transaction_record(self, row, output_tsv_file):
661661
# identifier for the transaction
662662
payment_record.paypal_transaction_id,
663663
]
664-
output_tsv_file.write(b'\t'.join(field.encode('utf-8') for field in record) + b'\n')
664+
# output_tsv_file.write(b'\t'.join(field.encode('utf-8') for field in record) + b'\n')
665+
# Apparently the write wants str, not bytes.
666+
output_tsv_file.write('\t'.join(field for field in record) + '\n')
665667

666668
def output(self):
667669
# NOTE: both the cybersource and paypal tasks write to the payments folder

0 commit comments

Comments
 (0)