From 4ea733e2f4cbf9fd67a3349ba5c84897aeb538b3 Mon Sep 17 00:00:00 2001 From: onotch Date: Sat, 9 Jan 2021 15:29:31 +0900 Subject: [PATCH] improved timing to acquire images --- cron.conf | 2 +- get_gpv.plist | 32 ++++++++++++++++---------------- get_gpv.sh | 17 +++++++++-------- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/cron.conf b/cron.conf index d614860..95b2147 100644 --- a/cron.conf +++ b/cron.conf @@ -1 +1 @@ -5 0,3,6,9,12,15,18,21 * * * cd /Users/hoge/get_gpv/; /bin/sh get_gpv.sh +35 2,5,8,11,14,17,20,23 * * * cd /Users/hoge/get_gpv/; ./get_gpv.sh diff --git a/get_gpv.plist b/get_gpv.plist index ff96d99..682376b 100644 --- a/get_gpv.plist +++ b/get_gpv.plist @@ -12,51 +12,51 @@ StartCalendarInterval Hour - 0 + 2 Minute - 5 + 35 Hour - 3 - Minute 5 + Minute + 35 Hour - 6 + 8 Minute - 5 + 35 Hour - 9 + 11 Minute - 5 + 35 Hour - 12 + 14 Minute - 5 + 35 Hour - 15 + 17 Minute - 5 + 35 Hour - 18 + 20 Minute - 5 + 35 Hour - 21 + 23 Minute - 5 + 35 WorkingDirectory /Users/hoge/get_gpv diff --git a/get_gpv.sh b/get_gpv.sh index 4317d97..524b7b5 100755 --- a/get_gpv.sh +++ b/get_gpv.sh @@ -33,15 +33,16 @@ if [ ! -d ${LOG_DIR} ]; then mkdir -p ${LOG_DIR} fi -year=`date -d '3 hours ago' +'%Y'` -month=`date -d '3 hours ago' +'%m'` -day=`date -d '3 hours ago' +'%d'` -hour=`date -d '3 hours ago' +'%H'` +hour_delta=$((`date +'%k'`%3+3)) +year=`date -d "$((hour_delta)) hours ago" +"%Y"` +month=`date -d "$((hour_delta)) hours ago" +"%m"` +day=`date -d "$((hour_delta)) hours ago" +"%d"` +hour=`date -d "$((hour_delta)) hours ago" +"%k"` log_file_path="${LOG_DIR}/error_log_`date +'%Y%m%d'`.txt" for type in ${TYPE[@]}; do for area in ${AREA[@]}; do - url_html=${GPV_URL}/msm_${type}_${area}_${year}${month}${day}${hour}.html + url_html=${GPV_URL}/msm_${type}_${area}_${year}${month}${day}`printf %02d ${hour}`.html response=`curl -s -o ${TMP_HTML_FILE} -w "%{http_code}" ${url_html}` if [ ${response} = "200" ]; then @@ -50,9 +51,9 @@ for type in ${TYPE[@]}; do mkdir -p ${save_dir} fi - for ((i=1; i<=3; i++)); do - filename=`grep "fnl\[${i}\]" ${TMP_HTML_FILE} | awk -F'["]' '{print $2}'` - save_hour=`date -d "$((4-i)) hours ago" +"%H"` + for ((i=0; i<3; i++)); do + filename=`grep "fnl\[$((i+1))\]" ${TMP_HTML_FILE} | awk -F'["]' '{print $2}'` + save_hour=`printf %02d $((hour+i))` save_file_path="${save_dir}/msm_${type}_${area}_${year}${month}${day}${save_hour}.png" curl -s -o ${save_file_path} ${GPV_URL}/msm/${filename}