Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions process_report/invoices/invoice.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
import pandas
import os

import process_report.util as util

Expand Down Expand Up @@ -122,3 +123,20 @@ def export(self):
def export_s3(self, s3_bucket):
s3_bucket.upload_file(self.output_path, self.output_s3_key)
s3_bucket.upload_file(self.output_path, self.output_s3_archive_key)

def fetch(self, s3_bucket=None):
"""Fetches the exported invoice CSV from S3 and loads it into self.data.

If s3_bucket is not provided, uses the default invoice bucket.
The CSV is downloaded to the current working directory using its base filename.
"""
s3_key = self.output_s3_key
local_filename = os.path.basename(s3_key)

if s3_bucket is None:
# Fallback to default bucket utility which also downloads
util.fetch_s3(s3_key)
else:
s3_bucket.download_file(s3_key, local_filename)

self.data = pandas.read_csv(local_filename)
Loading