Skip to content

Commit 8636696

Browse files
committed
Closes #92
Added fetch function as an out-of-band utility to easily fetch invoices
1 parent 147b929 commit 8636696

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

process_report/invoices/invoice.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from dataclasses import dataclass
22
import pandas
3+
import os
34

45
import process_report.util as util
56

@@ -122,3 +123,20 @@ def export(self):
122123
def export_s3(self, s3_bucket):
123124
s3_bucket.upload_file(self.output_path, self.output_s3_key)
124125
s3_bucket.upload_file(self.output_path, self.output_s3_archive_key)
126+
127+
def fetch(self, s3_bucket=None):
128+
"""Fetches the exported invoice CSV from S3 and loads it into self.data.
129+
130+
If s3_bucket is not provided, uses the default invoice bucket.
131+
The CSV is downloaded to the current working directory using its base filename.
132+
"""
133+
s3_key = self.output_s3_key
134+
local_filename = os.path.basename(s3_key)
135+
136+
if s3_bucket is None:
137+
# Fallback to default bucket utility which also downloads
138+
util.fetch_s3(s3_key)
139+
else:
140+
s3_bucket.download_file(s3_key, local_filename)
141+
142+
self.data = pandas.read_csv(local_filename)

0 commit comments

Comments
 (0)