-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonthly_report.py
More file actions
45 lines (37 loc) · 1.46 KB
/
monthly_report.py
File metadata and controls
45 lines (37 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import ruamel.yaml
from datetime import datetime, timedelta, date
import dateutil.relativedelta
import missing_record.generate_html
import missing_record.generate_missing_data_csvs
import missing_record.send_email
import os
# Rewrite config file dates
config_file_path = "config_files/monthly_config.yaml"
yaml = ruamel.yaml.YAML()
with open(config_file_path) as fp:
data = yaml.load(fp)
finish_date = datetime.today() #date(2025,5,1)
data["start"] = (
finish_date + dateutil.relativedelta.relativedelta(months=-1)
).strftime("%Y-%m-%d") + " 00:00"
data["end"] = (finish_date - timedelta(days=1)).strftime("%Y-%m-%d") + " 23:59:59"
with open(config_file_path, "w") as fp:
yaml.dump(data, fp)
# Make and send reports
missing_record.generate_missing_data_csvs.generate(config_file_path)
missing_record.generate_html.generate(config_file_path)
destination_folder = (
r"\\ares\Hydrology\Hydrology Regions\Missing Record Reporting\monthly_reports"
+ f"\\{finish_date.strftime('%Y-%m-%d')}"
)
os.makedirs(destination_folder, exist_ok=True)
missing_record.send_email.copy_files(destination_folder)
missing_record.send_email.send(
"<p>Monthly missing record report</p>"
"<p>This can be viewed with colours at:</p>"
r"<p>\\ares\Hydrology\Hydrology Regions\Missing Record Reporting\monthly_reports</p>",
"monthly missing record report",
)
missing_record.generate_html.record_sql(
"./output_csv/output.csv", "./output_csv/output_totals.csv", data["end"]
)