Files
notifications-admin/app/utils/s3_csv.py
Alex Janousek 8d33f28b76 Refactored reports to use pregenerated docs instead (#2831)
* Refactored reports to use pregenerated docs instead

* Fixed e2e test

* Fixed anothr bug

* Cleanup

* Fixed timezone conversion

* Updated ref files

* Updated reference files, refreshed ui/ux for report generation. Buttons toggle on and off based on if report exists

* Fixed linting errors, removed pytz

* Fixed test failure

* e2e test fix

* Speeding up unit tests

* Removed python time library that was causing performance issues with unit tests

* Updated poetry lock

* Unit test improvements

* Made change that ken reccomended
2025-08-15 15:02:54 -04:00

51 lines
1.3 KiB
Python

import csv
import io
from app.utils.csv import convert_report_date_to_preferred_timezone
def convert_s3_csv_timestamps(csv_content):
if isinstance(csv_content, bytes):
csv_content = csv_content.decode("utf-8")
reader = csv.reader(io.StringIO(csv_content))
time_column_index = None
try:
header = next(reader)
for i, col in enumerate(header):
if col.strip().lower() == "time":
time_column_index = i
break
output = io.StringIO()
writer = csv.writer(output)
writer.writerow(header)
yield output.getvalue()
output.truncate(0)
output.seek(0)
except StopIteration:
return
if time_column_index is None:
for row in reader:
writer.writerow(row)
yield output.getvalue()
output.truncate(0)
output.seek(0)
return
for row in reader:
if len(row) > time_column_index and row[time_column_index]:
try:
row[time_column_index] = convert_report_date_to_preferred_timezone(
row[time_column_index]
)
except Exception: # nosec B110
pass
writer.writerow(row)
yield output.getvalue()
output.truncate(0)
output.seek(0)