Skip to content

Commit

Permalink
use iso dates in file names
Browse files Browse the repository at this point in the history
  • Loading branch information
svonworl committed Nov 25, 2024
1 parent 996583d commit 23f7d07
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions report.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ def generate_file_name(self, root: str, dateComponents: Iterable[str], base: str
return f'{root}/{slash_date}/{base}-{dash_date}.{extension}'

def generate_billing_csv_file_name(self, date: datetime.date) -> str:
return self.generate_file_name(self.platform, (str(date.year), str(date.month)), self.platform, 'csv')
return self.generate_file_name(self.platform, (str(date.year).zfill(4), str(date.month).zfill(2)), self.platform, 'csv')

def generate_terra_json_file_name(self, date: datetime.date) -> str:
return self.generate_file_name('terra', (str(date.year), str(date.month), str(date.day)), 'terra', 'json')
return self.generate_file_name('terra', (str(date.year).zfill(4), str(date.month).zfill(2), str(date.day).zfill(2)), 'terra', 'json')

def to_csv(self, rows: Sequence[Mapping[str, Any]]) -> str:
with io.StringIO('') as file:
Expand Down Expand Up @@ -616,7 +616,7 @@ def saveUsageData(self, date):
for day in self.days_of_month_up_to_and_including(date):
result = self.generateAccountSummary(self.accounts, day, day + datetime.timedelta(1))
rows += [
{"date": day, "amount_billed": sum(result[name].values()), "account_id": account_name_to_id[name], "account_name": name}
{"date": self.iso_date(day), "amount_billed": sum(result[name].values()), "account_id": account_name_to_id[name], "account_name": name}
for name in result.keys()
]
self.save_file(self.generate_billing_csv_file_name(date), self.to_csv(rows))
Expand Down Expand Up @@ -714,7 +714,7 @@ def saveUsageData(self, date: datetime.date):
for day in self.days_of_month_up_to_and_including(date):
results = group_by(self.doQuery(day), 'id', 'name', 'cost_today')
rows += [
{"date": day, "amount_billed": cost, "project_id": id, "project_name": name}
{"date": self.iso_date(day), "amount_billed": cost, "project_id": id, "project_name": name}
for (id, name, cost) in results if cost > 0
]
self.save_file(self.generate_billing_csv_file_name(date), self.to_csv(rows))
Expand Down

0 comments on commit 23f7d07

Please sign in to comment.