Skip to content

Commit 6463553

Browse files
authored
Merge pull request #4983 from GSA/metrics-file-with-date
add date to S3 so receiving end knows report time
2 parents 36f85d8 + 4dd05b6 commit 6463553

File tree

1 file changed

+7
-2
lines changed
  • metrics/datagov_metrics

1 file changed

+7
-2
lines changed

metrics/datagov_metrics/ga.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import calendar
33
import io
44
import csv
5+
from functools import lru_cache
56

67
from datagov_metrics.s3_util import put_data_to_s3
78
import requests
@@ -19,7 +20,7 @@
1920
analytics = build("analyticsdata", "v1beta", credentials=credentials)
2021
properties = analytics.properties()
2122

22-
23+
@lru_cache()
2324
def date_range_last_month():
2425
last_month = datetime.today().replace(day=1) - timedelta(days=1)
2526
last_day = calendar.monthrange(last_month.year, last_month.month)[1]
@@ -187,11 +188,15 @@ def write_data_to_csv(response):
187188

188189
def main():
189190
reports = setup_reports()
191+
end_date = date_range_last_month()[0]["endDate"] # for example, 2024-10-31
190192
for report in reports:
191193
print(f"Fetching report: {report}")
192194
fetched_report = fetch_report(reports[report])
193195
csv_data = write_data_to_csv(fetched_report)
194-
put_data_to_s3(f"{report}.csv", csv_data)
196+
put_data_to_s3(f"{report}.{end_date}.csv", csv_data)
197+
198+
# This file get refreshed every time at the end of report generation
199+
put_data_to_s3("report-end-date.txt", end_date)
195200

196201

197202
if __name__ == "__main__":

0 commit comments

Comments
 (0)