Skip to content

Commit

Permalink
- Improved usability
Browse files Browse the repository at this point in the history
- Improved debug mode
  • Loading branch information
onotch committed Jan 10, 2021
1 parent 44c5b59 commit 0bd02a0
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion archive/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $(document).ready(function() {

const START_YEAR = 2021;

const JOB_SCHEDULED_TIME_MIN = 45;
const JOB_SCHEDULED_TIME_MIN = 40;

const AUTO_PLAY_STATUS = {
STOP : 0,
Expand Down
2 changes: 1 addition & 1 deletion cron.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
45 2,5,8,11,14,17,20,23 * * * cd /Users/hoge/get_gpv/; ./get_gpv.sh
40 2,5,8,11,14,17,20,23 * * * cd /Users/hoge/get_gpv/; ./get_gpv.sh
16 changes: 8 additions & 8 deletions get_gpv.plist
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,49 @@
<key>Hour</key>
<integer>2</integer>
<key>Minute</key>
<integer>45</integer>
<integer>40</integer>
</dict>
<dict>
<key>Hour</key>
<integer>5</integer>
<key>Minute</key>
<integer>45</integer>
<integer>40</integer>
</dict>
<dict>
<key>Hour</key>
<integer>8</integer>
<key>Minute</key>
<integer>45</integer>
<integer>40</integer>
</dict>
<dict>
<key>Hour</key>
<integer>11</integer>
<key>Minute</key>
<integer>45</integer>
<integer>40</integer>
</dict>
<dict>
<key>Hour</key>
<integer>14</integer>
<key>Minute</key>
<integer>45</integer>
<integer>40</integer>
</dict>
<dict>
<key>Hour</key>
<integer>17</integer>
<key>Minute</key>
<integer>45</integer>
<integer>40</integer>
</dict>
<dict>
<key>Hour</key>
<integer>20</integer>
<key>Minute</key>
<integer>45</integer>
<integer>40</integer>
</dict>
<dict>
<key>Hour</key>
<integer>23</integer>
<key>Minute</key>
<integer>45</integer>
<integer>40</integer>
</dict>
<key>WorkingDirectory</key>
<string>/Users/hoge/get_gpv</string>
Expand Down
27 changes: 24 additions & 3 deletions get_gpv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ if [ ! -d ${LOG_DIR} ]; then
mkdir -p ${LOG_DIR}
fi

# GPV update time: 2:30, 5:30, 8:30, 11:30, 14:30, 17:30, 20:30, 23:30
hour_delta=$((`date +'%k'`%3+3))
if [ ${hour_delta} = 5 ] && [ `date +'%-M'` -ge 30 ]; then
hour_delta=2
Expand All @@ -58,6 +59,12 @@ readonly HOUR=`date -d "$((hour_delta)) hours ago" +"%k"`
readonly LOG_FILE_PATH="${LOG_DIR}/error_log_`date +'%Y%m%d'`.txt"
debug_echo "LOG_FILE_PATH=${LOG_FILE_PATH}"

file_count_success=0
file_count_fail=0
file_count_exist=0
file_count_html_fail=0
total_file_size=0

for type in ${TYPE[@]}
do
for area in ${AREA[@]}
Expand All @@ -76,27 +83,41 @@ do
do
filename=`grep "fnl\[$((i+1))\]" ${TMP_HTML_FILE} | awk -F'["]' '{print $2}'`
debug_echo "filename=${filename}"
save_hour=`printf %02d $((HOUR+i))`
save_file_path="${save_dir}/msm_${type}_${area}_${YEAR}${MONTH}${DAY}${save_hour}.png"
save_file_path=${save_dir}/msm_${type}_${area}_${YEAR}${MONTH}${DAY}`printf %02d $((HOUR+i))`.png

if [ ! -e ${save_file_path} ]; then
curl -s -o ${save_file_path} ${GPV_URL}/msm/${filename}

if [ ! -e ${save_file_path} ]; then
file_count_fail=$((file_count_fail+1))
echo "`date +'%F %T'` : failed to download ${filename}" >> ${LOG_FILE_PATH}
debug_echo "failed to download ${filename}"
else
debug_echo "${save_file_path} has been downloaded"
file_count_success=$((file_count_success+1))
file_size=`wc -c ${save_file_path} | awk '{print $1}'`
total_file_size=$((total_file_size + file_size))
file_size_p=`printf "%'d" ${file_size}`
debug_echo "${save_file_path} (${file_size_p} bytes) has been downloaded"
fi
else
file_count_exist=$((file_count_exist+1))
debug_echo "${save_file_path} already exists"
fi
done
else
file_count_html_fail=$((file_count_html_fail+1))
echo "`date +'%F %T'` : failed to download ${url_html}" >> ${LOG_FILE_PATH}
debug_echo "failed to download ${url_html}"
fi

rm ${TMP_HTML_FILE} > /dev/null 2>&1
done
done

debug_echo "--- RESULT ---"
file_size_p=`printf "%'d" ${total_file_size}`
debug_echo "Succes: ${file_count_success}"
debug_echo "Fail: ${file_count_fail}"
debug_echo "Already exist: ${file_count_exist}"
debug_echo "HTML not found: ${file_count_html_fail}"
debug_echo "Total download file size: ${file_size_p} bytes"

0 comments on commit 0bd02a0

Please sign in to comment.