File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change 2
2
import calendar
3
3
import io
4
4
import csv
5
+ from functools import lru_cache
5
6
6
7
from datagov_metrics .s3_util import put_data_to_s3
7
8
import requests
19
20
analytics = build ("analyticsdata" , "v1beta" , credentials = credentials )
20
21
properties = analytics .properties ()
21
22
22
-
23
+ @ lru_cache ()
23
24
def date_range_last_month ():
24
25
last_month = datetime .today ().replace (day = 1 ) - timedelta (days = 1 )
25
26
last_day = calendar .monthrange (last_month .year , last_month .month )[1 ]
@@ -187,11 +188,15 @@ def write_data_to_csv(response):
187
188
188
189
def main ():
189
190
reports = setup_reports ()
191
+ end_date = date_range_last_month ()[0 ]["endDate" ] # for example, 2024-10-31
190
192
for report in reports :
191
193
print (f"Fetching report: { report } " )
192
194
fetched_report = fetch_report (reports [report ])
193
195
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 )
195
200
196
201
197
202
if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments