-
Notifications
You must be signed in to change notification settings - Fork 1
/
execupdateV3.sh
executable file
·210 lines (188 loc) · 5.47 KB
/
execupdateV3.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash -l
####n
# Stop Covid19nara
# The Script to make JSON
####
# アップデートフラグ:更新あれば1
UPDATE_FLAG=0
BATCH_FLAG=0
# 公開用のディレクトリ
TGT_JSON_DIR="../html/api/"
# 奈良県の感染データ
TJSON_datapref="data.json"
TEMP_datapref="./data/data.json"
TEMP_dataprefSaved=${TEMP_datapref}"_saved"
# 奈良県のニュース
TJSON_newspref="news.json"
TEMP_newspref="./data/news.json"
TEMP_newsprefSaved=${TEMP_newspref}"_saved"
# 奈良市の感染データ
TJSON_datacity="data_naracity.json"
TEMP_datacity="./data/data_naracity.json"
TEMP_datacitySaved=${TEMP_datacity}"_saved"
# 奈良市のニュース
TJSON_newscity="news_naracity.json"
TEMP_newscity="./data/news_naracity.json"
TEMP_newscitySaved=${TEMP_newscity}"_saved"
TEMPFILE1="./updatetmp1.$$"
TEMPFILE2="./updatetmp2.$$"
####
# ファイル比較:loastUpdate以外
####
function CheckDiff()
{
if [ ! -e $1 ]; then
echo 1;
elif [ ! -e $2 ]; then
echo 1;
else
grep -v lastUpdate $1 > ${TEMPFILE1}
grep -v lastUpdate $2 > ${TEMPFILE2}
diff ${TEMPFILE1} ${TEMPFILE2} > /dev/null 2>&1
if [ $? -ne 0 ] ; then
echo 1
else
echo 0
fi
rm -f $TEMPFILE1 $TEMPFILE2
fi
}
####
# Yes/no check
####
YN_CHECK()
{
echo $1
while true; do
read -p ' [Y/N] ' Answer
case $Answer in
'' | [Yy]* )
break;
;;
[Nn]* )
echo " CANCELed."
exit;
;;
* )
echo Please answer YES or NO.
esac
done
}
####
# usage_exit
####
usage_exit()
{
echo " JSON Update Scrpit for stopcvoid19.code4nara.org"
echo " usage: ${0} [-b]"
echo " -b : Batch-Deploy mode"
exit;
}
########
# Main
########
####
# Option Check
####
while getopts "hb" OPT
do
case $OPT in
h) usage_exit ;;
b) BATCH_FLAG=1 ;;
esac
done
####
# 奈良県/奈良市のサイトスクレイピング:新着情報の抽出実行
####
echo "-- Scraping news from Nara Pref"
cmd="python3 ./scraping_naraNews.py -p ${TEMP_newspref} -c ${TEMP_newscity} > /dev/null 2>&1"
echo " exec: " ${cmd}
eval ${cmd}
# 保存データと比較し変更があれば公開場所にコピー
ret=`CheckDiff ${TEMP_newspref} ${TEMP_newsprefSaved}`
if [ $ret == "1" ] ; then
echo "II ${TJSON_newspref} Found updete : News in Prefecture"
UPDATE_FLAG=1
# コピーを保存し公開フォルダにコピー
cp ${TEMP_newspref} ${TEMP_newsprefSaved}
cp ${TEMP_newspref} ${TGT_JSON_DIR}${TJSON_newspref}
fi
# 保存データと比較し変更があれば公開場所にコピー
#ret=`CheckDiff ${TEMP_newscity} ${TEMP_newscitySaved}`
#if [ $ret == "1" ] ; then
# echo "II ${TJSON_newscity} Found updete : News in City"
# UPDATE_FLAG=1
# # コピーを保存し公開フォルダにコピー
# cp ${TEMP_newscity} ${TEMP_newscitySaved}
# cp ${TEMP_newscity} ${TGT_JSON_DIR}${TJSON_newscity}
#fi
####
# 奈良県感染データ更新
####
echo "-- Making data.json from Excel"
cmd="python3 ./convert_naraprefV3.py > /dev/null 2>&1"
echo " exec: " ${cmd}
eval ${cmd}
# 保存データと比較し変更があれば公開場所にコピー
ret=`CheckDiff ${TEMP_datapref} ${TEMP_dataprefSaved}`
if [ $ret == "1" ] ; then
echo "II ${TJSON_datapref} Found updete : Prefecture Data"
UPDATE_FLAG=1
# コピーを保存し公開フォルダにコピー
cp ${TEMP_datapref} ${TEMP_dataprefSaved}
jq -c . ${TEMP_datapref} > ${TGT_JSON_DIR}${TJSON_datapref}
fi
####
# 奈良市感染データ更新:グーグルスプレッドシート参照
####
#echo "-- Making naracity.json from GoogleSpreadSheet"
#cmd="python3 ./convert_naracityV2.py > /dev/null 2>&1"
#echo " exec: " ${cmd}
#eval ${cmd}
## 保存データと比較し変更があれば公開場所にコピー
#ret=`CheckDiff ${TEMP_datacity} ${TEMP_datacitySaved}`
#if [ $ret == "1" ] ; then
# echo "II ${TJSON_datacity} Found updete : Nara City Data"
# UPDATE_FLAG=1
# # コピーを保存し公開フォルダにコピー
# cp ${TEMP_datacity} ${TEMP_datacitySaved}
# cp ${TEMP_datacity} ${TGT_JSON_DIR}${TJSON_datacity}
#fi
####
# サイトデプロイ:要環境変数 GITHUB_TOKEN
####
if [ ${UPDATE_FLAG} == 1 ]; then
echo "II Exec Github Action for data update."
date +" at %Y/%m/%d %H:%m:%S"
# バッチモードならば自動実行/バッチモード以外は Y/N チェック
if [ ${BATCH_FLAG} == 1 ]; then
## 開発サイトへのデプロイ
#cmd="bash ./githubDeployment.sh -b"
#echo " exec: " ${cmd}
#eval ${cmd}
# テストサイトへのデプロイ
#cmd="bash ./githubDeployment.sh -b -r staging -e gh-pages"
#echo " exec: " ${cmd}
#eval ${cmd}
# 本番サイトへのデプロイ
cmd="bash ./githubDeployment.sh -b -r master -e production"
echo " exec: " ${cmd}
eval ${cmd}
else
# 開発サイトのデプロイ
cmd="bash ./githubDeployment.sh -b"
echo " exec CMD: " ${cmd}
YN_CHECK "QQ Run Development Deploy to netlify ?"
#eval ${cmd}
# テストサイトへのデプロイ
cmd="bash ./githubDeployment.sh -b -r staging -e gh-pages"
echo " exec CMD: " ${cmd}
YN_CHECK "QQ Run Staging Deploy to covid19-staging ?"
eval ${cmd}
# 本番サイトのデプロイ
cmd="bash ./githubDeployment.sh -b -r master -e production"
echo " exec CMD: " ${cmd}
YN_CHECK "QQ Run Master Deploy to stopcovid19.code4nara.org ?"
eval ${cmd}
fi
fi