-
Notifications
You must be signed in to change notification settings - Fork 4
/
cron_informe_cnmc_canvi_comer.py
67 lines (57 loc) · 2.01 KB
/
cron_informe_cnmc_canvi_comer.py
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Generate Report CNMC Canvi comercalitzadora
import argparse
from datetime import datetime
import calendar
import dbconfig
from consolemsg import step
import base64
from erppeek import Client
def generate_report(year, month, agent, sequence):
report_name = "SI_{}_{}_{}{}_{}.xml".format(
agent,
"E",
year,
month,
sequence,
)
report_name_csv = "SI_{}_{}_{}{}_{}.csv".format(
agent,
"E",
year,
month,
sequence,
)
date_time_start = datetime.strptime(str(year) + "-" + str(month) + "-01", "%Y-%m-%d")
last_day_month = str(calendar.monthrange(int(year), int(month))[1])
date_time_end = datetime.strptime(
str(year) + "-" + str(month) + "-" + last_day_month, "%Y-%m-%d"
)
print { # noqa: E999
"file_type": "SI",
"start_date": date_time_start.strftime("%Y-%m-%d"),
"end_date": date_time_end.strftime("%Y-%m-%d"),
}
c = Client(**dbconfig.erppeek)
step("Collecting data...")
wiz = c.WizardCnmcXmlReport.create(
{
"file_type": "SI",
"start_date": date_time_start.strftime("%Y-%m-%d"),
"end_date": date_time_end.strftime("%Y-%m-%d"),
}
)
wiz.action_generate_file()
step("Writing {}...".format(report_name))
with open("/tmp/" + report_name, "w") as f:
f.write(base64.b64decode(wiz.file))
step("Writing {}...".format(report_name_csv))
with open("/tmp/" + report_name_csv, "w") as f:
f.write(base64.b64decode(wiz.file_csv))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Generates switching monthly report")
parser.add_argument("year", metavar="YEAR")
parser.add_argument("month", metavar="MONTH")
parser.add_argument("sequence", metavar="SEQUENCE", nargs="?")
parser.add_argument("--agent", metavar="AGENT", nargs="?", default="R2-415", help="Agent code ")
args = parser.parse_args()
generate_report(args.year, args.month, args.agent, args.sequence)