forked from copperlabs/api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_dump.sh
executable file
·30 lines (25 loc) · 972 Bytes
/
data_dump.sh
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
#!/bin/bash
# set -x
enterprise_name=$1
start_date=$2 # Provide in format: YYYY-MM-DD, ex: 2020-09-25
finish_date=$3 # Provide in format: YYYY-MM-DD, ex: 2020-09-25
granularity=$4
output_base_dir="generated/${enterprise_name}"
report_date=`date "+%Y%m%d"`
days=$(( (`gdate -d $finish_date +%s` - `gdate -d $start_date +%s`) / (24*3600) ))
for i in $(eval echo "{0..$days}")
do
bucket=`date -j -v +${i}d -f "%Y-%m-%d" "${start_date}" "+%Y-%m-%d"`
sdate="${bucket}"
fdate=`date -j -v +$((i+1))d -f "%Y-%m-%d" "${start_date}" "+%Y-%m-%d"` # go over 1 hour to blindly handle time changes
echo $bucket
output_dir="${output_base_dir}/${bucket}"
mkdir -p ${output_dir}
python copper-enterprise-client.py \
--output-dir ${output_dir} \
--csv-output-file meter_summary.csv \
meter usage \
--granularity ${granularity} ${sdate} ${fdate}
done
cd generated
zip -r ${enterprise_name}.${report_date}.zip ${enterprise_name}