w-dwdata-tweq 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/.editorconfig +9 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc.js +55 -0
  4. package/.jsdoc +25 -0
  5. package/LICENSE +21 -0
  6. package/README.md +48 -0
  7. package/SECURITY.md +5 -0
  8. package/babel.config.js +16 -0
  9. package/dist/w-dwdata-tweq.umd.js +8 -0
  10. package/dist/w-dwdata-tweq.umd.js.map +1 -0
  11. package/docs/WDwdataTweq.mjs.html +318 -0
  12. package/docs/fonts/Montserrat/Montserrat-Bold.eot +0 -0
  13. package/docs/fonts/Montserrat/Montserrat-Bold.ttf +0 -0
  14. package/docs/fonts/Montserrat/Montserrat-Bold.woff +0 -0
  15. package/docs/fonts/Montserrat/Montserrat-Bold.woff2 +0 -0
  16. package/docs/fonts/Montserrat/Montserrat-Regular.eot +0 -0
  17. package/docs/fonts/Montserrat/Montserrat-Regular.ttf +0 -0
  18. package/docs/fonts/Montserrat/Montserrat-Regular.woff +0 -0
  19. package/docs/fonts/Montserrat/Montserrat-Regular.woff2 +0 -0
  20. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.eot +0 -0
  21. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.svg +978 -0
  22. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.ttf +0 -0
  23. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff +0 -0
  24. package/docs/fonts/Source-Sans-Pro/sourcesanspro-light-webfont.woff2 +0 -0
  25. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.eot +0 -0
  26. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.svg +1049 -0
  27. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.ttf +0 -0
  28. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff +0 -0
  29. package/docs/fonts/Source-Sans-Pro/sourcesanspro-regular-webfont.woff2 +0 -0
  30. package/docs/global.html +781 -0
  31. package/docs/index.html +84 -0
  32. package/docs/scripts/collapse.js +39 -0
  33. package/docs/scripts/commonNav.js +28 -0
  34. package/docs/scripts/linenumber.js +25 -0
  35. package/docs/scripts/nav.js +12 -0
  36. package/docs/scripts/polyfill.js +4 -0
  37. package/docs/scripts/prettify/Apache-License-2.0.txt +202 -0
  38. package/docs/scripts/prettify/lang-css.js +2 -0
  39. package/docs/scripts/prettify/prettify.js +28 -0
  40. package/docs/scripts/search.js +99 -0
  41. package/docs/styles/jsdoc.css +776 -0
  42. package/docs/styles/prettify.css +80 -0
  43. package/g.downloadEqs.mjs +16 -0
  44. package/g.mjs +53 -0
  45. package/g.parseData.mjs +26 -0
  46. package/package.json +34 -0
  47. package/script.txt +17 -0
  48. package/src/WDwdataTweq.mjs +246 -0
  49. package/src/cropPic.mjs +15 -0
  50. package/src/downloadEqs.mjs +124 -0
  51. package/src/downloadFile.mjs +77 -0
  52. package/src/downloadPics.mjs +57 -0
  53. package/src/parseData.mjs +152 -0
  54. package/test/WDwdataTweq.test.mjs +150 -0
  55. package/toolg/addVersion.mjs +4 -0
  56. package/toolg/cleanFolder.mjs +4 -0
  57. package/toolg/gDistRollup.mjs +26 -0
  58. package/toolg/modifyReadme.mjs +4 -0
@@ -0,0 +1,80 @@
1
+ .pln {
2
+ color: #ddd;
3
+ }
4
+
5
+ /* string content */
6
+ .str {
7
+ color: #61ce3c;
8
+ }
9
+
10
+ /* a keyword */
11
+ .kwd {
12
+ color: #fbde2d;
13
+ }
14
+
15
+ /* a comment */
16
+ .com {
17
+ color: #aeaeae;
18
+ }
19
+
20
+ /* a type name */
21
+ .typ {
22
+ color: #8da6ce;
23
+ }
24
+
25
+ /* a literal value */
26
+ .lit {
27
+ color: #fbde2d;
28
+ }
29
+
30
+ /* punctuation */
31
+ .pun {
32
+ color: #ddd;
33
+ }
34
+
35
+ /* lisp open bracket */
36
+ .opn {
37
+ color: #000000;
38
+ }
39
+
40
+ /* lisp close bracket */
41
+ .clo {
42
+ color: #000000;
43
+ }
44
+
45
+ /* a markup tag name */
46
+ .tag {
47
+ color: #8da6ce;
48
+ }
49
+
50
+ /* a markup attribute name */
51
+ .atn {
52
+ color: #fbde2d;
53
+ }
54
+
55
+ /* a markup attribute value */
56
+ .atv {
57
+ color: #ddd;
58
+ }
59
+
60
+ /* a declaration */
61
+ .dec {
62
+ color: #EF5050;
63
+ }
64
+
65
+ /* a variable name */
66
+ .var {
67
+ color: #c82829;
68
+ }
69
+
70
+ /* a function name */
71
+ .fun {
72
+ color: #4271ae;
73
+ }
74
+
75
+ /* Specify class=linenums on a pre to get line numbering */
76
+ ol.linenums {
77
+ margin-top: 0;
78
+ margin-bottom: 0;
79
+ padding-bottom: 2px;
80
+ }
@@ -0,0 +1,16 @@
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+ import _ from 'lodash-es'
4
+ import w from 'wsemi'
5
+ import downloadEqs from './src/downloadEqs.mjs'
6
+
7
+
8
+ let yearStart = 2025
9
+ let yearEnd = 2025
10
+ let v = await downloadEqs(yearStart, yearEnd)
11
+ console.log('v', v)
12
+
13
+ fs.writeFileSync(`./year_${yearStart}_${yearEnd}_eq.json`, JSON.stringify(v, null, 2), 'utf8')
14
+
15
+
16
+ //node g.downloadEqs.mjs
package/g.mjs ADDED
@@ -0,0 +1,53 @@
1
+ // import path from 'path'
2
+ // import fs from 'fs'
3
+ // import _ from 'lodash-es'
4
+ import w from 'wsemi'
5
+ import WDwdataTweq from './src/WDwdataTweq.mjs'
6
+
7
+
8
+ //fdDwAttime
9
+ let fdDwAttime = `./_dwAttime`
10
+ w.fsCleanFolder(fdDwAttime)
11
+
12
+ //fdDwCurrent
13
+ let fdDwCurrent = `./_dwCurrent`
14
+ w.fsCleanFolder(fdDwCurrent)
15
+
16
+ //fdResult
17
+ let fdResult = './_result'
18
+ w.fsCleanFolder(fdResult)
19
+
20
+ let yearStart = 2022
21
+ let yearEnd = 2022
22
+ let opt = {
23
+ fdDwAttime,
24
+ fdDwCurrent,
25
+ fdResult,
26
+ // funDownload,
27
+ // funGetCurrent,
28
+ // funRemove,
29
+ // funAdd,
30
+ // funModify,
31
+ }
32
+ let ev = await WDwdataTweq(yearStart, yearEnd, opt)
33
+ .catch((err) => {
34
+ console.log(err)
35
+ })
36
+ ev.on('change', (msg) => {
37
+ delete msg.type
38
+ console.log('change', msg)
39
+ })
40
+ // change { event: 'start', msg: 'running...' }
41
+ // change { event: 'proc-callfun-download', msg: 'start...' }
42
+ // change { event: 'proc-callfun-download', msg: 'done' }
43
+ // change { event: 'proc-callfun-getCurrent', msg: 'start...' }
44
+ // change { event: 'proc-callfun-getCurrent', msg: 'done' }
45
+ // change { event: 'compare', msg: 'start...' }
46
+ // change { event: 'compare', msg: 'done' }
47
+ // change { event: 'proc-add-callfun-add', id: '111001', msg: 'start...' }
48
+ // change { event: 'proc-add-callfun-add', id: '111001', msg: 'done' }
49
+ // change { event: 'proc-add-callfun-add', id: '111002', msg: 'start...' }
50
+ // change { event: 'proc-add-callfun-add', id: '111002', msg: 'done' }
51
+ // ...
52
+
53
+ //node g.mjs
@@ -0,0 +1,26 @@
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+ import _ from 'lodash-es'
4
+ import w from 'wsemi'
5
+ import parseData from './src/parseData.mjs'
6
+
7
+
8
+ let yearStart = 2025
9
+ let yearEnd = 2025
10
+ let fp = `./year_${yearStart}_${yearEnd}_eq.json`
11
+ let j = fs.readFileSync(fp, 'utf8')
12
+ let v = JSON.parse(j)
13
+
14
+ let eqs = parseData(v)
15
+ console.log('eqs', eqs, _.size(eqs))
16
+
17
+ let eq = _.filter(eqs, (v) => {
18
+ return v.tag === '2024040307580971019'
19
+ })
20
+ eq = eq[0]
21
+ console.log('eq', eq)
22
+
23
+ fs.writeFileSync(`./year_${yearStart}_${yearEnd}_eqs.json`, JSON.stringify(eqs, null, 2), 'utf8')
24
+
25
+
26
+ //node g.parseData.mjs
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "w-dwdata-tweq",
3
+ "version": "1.0.0",
4
+ "main": "dist/w-dwdata-tweq.umd.js",
5
+ "dependencies": {
6
+ "axios": "^1.11.0",
7
+ "lodash-es": "^4.17.21",
8
+ "sharp": "^0.34.3",
9
+ "w-dwdata-builder": "^1.0.1",
10
+ "wsemi": "^1.8.18"
11
+ },
12
+ "devDependencies": {
13
+ "w-package-tools": "^1.1.2"
14
+ },
15
+ "scripts": {
16
+ "test": "mocha --parallel --timeout 60000",
17
+ "deploy": "gh-pages -d docs"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/yuda-lyu/w-dwdata-tweq.git"
22
+ },
23
+ "keywords": [
24
+ "package",
25
+ "tool",
26
+ "download",
27
+ "data",
28
+ "tw",
29
+ "eq",
30
+ "nodejs"
31
+ ],
32
+ "author": "yuda-lyu(semisphere)",
33
+ "license": "MIT"
34
+ }
package/script.txt ADDED
@@ -0,0 +1,17 @@
1
+ #node toolg/addVersion.mjs
2
+ node toolg/modifyReadme.mjs
3
+
4
+ node toolg/cleanFolder.mjs
5
+ ./node_modules/.bin/jsdoc -c .jsdoc
6
+
7
+ node toolg/gDistRollup.mjs
8
+
9
+ git add . -A
10
+ git commit -m 'modify: '
11
+ git push origin master:master
12
+
13
+ npm run deploy
14
+
15
+ #npm test
16
+
17
+ #npm publish
@@ -0,0 +1,246 @@
1
+ import fs from 'fs'
2
+ import get from 'lodash-es/get.js'
3
+ import each from 'lodash-es/each.js'
4
+ import reverse from 'lodash-es/reverse.js'
5
+ import isestr from 'wsemi/src/isestr.mjs'
6
+ import isfun from 'wsemi/src/isfun.mjs'
7
+ import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
8
+ import fsCleanFolder from 'wsemi/src/fsCleanFolder.mjs'
9
+ import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
10
+ import fsDeleteFolder from 'wsemi/src/fsDeleteFolder.mjs'
11
+ import fsTreeFolder from 'wsemi/src/fsTreeFolder.mjs'
12
+ import WDwdataBuilder from 'w-dwdata-builder/src/WDwdataBuilder.mjs'
13
+ import downloadEqs from './downloadEqs.mjs'
14
+ import parseData from './parseData.mjs'
15
+ import downloadPics from './downloadPics.mjs'
16
+ import cropPic from './cropPic.mjs'
17
+
18
+
19
+ /**
20
+ * 下載台灣氣象署地震資料
21
+ *
22
+ * @param {Integer} yearStart 輸入數據開始年整數
23
+ * @param {Integer} yearEnd 輸入數據結束年整數
24
+ * @param {Object} [opt={}] 輸入設定物件,預設{}
25
+ * @param {String} [opt.keyId] 輸入各筆數據之主鍵字串,預設keyId
26
+ * @param {String} [opt.fdDwAttime] 輸入當前下載數據資料夾字串,預設'./_dwAttime'
27
+ * @param {String} [opt.fdDwCurrent] 輸入已下載數據資料夾字串,預設'./_dwCurrent'
28
+ * @param {String} [opt.fdResult] 輸入已下載數據所連動生成數據資料夾字串,預設'./_result'
29
+ * @param {String} [opt.fdTaskCpSrc] 輸入任務狀態之來源端資料夾字串,預設'./_taskCpSrc'
30
+ * @param {Function} [opt.funDownload] 輸入自定義下載函數,回傳資料陣列
31
+ * @param {Function} [opt.funGetCurrent] 輸入自定義取得當前資料函數,回傳資料陣列
32
+ * @param {Function} [opt.funAdd] 輸入當有新資料時,需要連動處理之函數
33
+ * @param {Function} [opt.funModify] 輸入當有資料需更新時,需要連動處理之函數
34
+ * @param {Function} [opt.funRemove] 輸入當有資料需刪除時,需要連動處理之函數
35
+ * @returns {Object} 回傳事件物件,可呼叫函數on監聽change事件
36
+ * @example
37
+ *
38
+ * import WDwdataTweq from './src/WDwdataTweq.mjs'
39
+ *
40
+ * let yearStart = 2022
41
+ * let yearEnd = 2022
42
+ * let opt = {}
43
+ * let ev = await WDwdataTweq(yearStart, yearEnd, opt)
44
+ * .catch((err) => {
45
+ * console.log(err)
46
+ * })
47
+ * ev.on('change', (msg) => {
48
+ * delete msg.type
49
+ * console.log('change', msg)
50
+ * })
51
+ * // change { event: 'start', msg: 'running...' }
52
+ * // change { event: 'proc-callfun-download', msg: 'start...' }
53
+ * // change { event: 'proc-callfun-download', msg: 'done' }
54
+ * // change { event: 'proc-callfun-getCurrent', msg: 'start...' }
55
+ * // change { event: 'proc-callfun-getCurrent', msg: 'done' }
56
+ * // change { event: 'compare', msg: 'start...' }
57
+ * // change { event: 'compare', msg: 'done' }
58
+ * // change { event: 'proc-add-callfun-add', id: '111001', msg: 'start...' }
59
+ * // change { event: 'proc-add-callfun-add', id: '111001', msg: 'done' }
60
+ * // change { event: 'proc-add-callfun-add', id: '111002', msg: 'start...' }
61
+ * // change { event: 'proc-add-callfun-add', id: '111002', msg: 'done' }
62
+ * // ...
63
+ *
64
+ */
65
+ let WDwdataTweq = async(yearStart, yearEnd, opt = {}) => {
66
+
67
+ //keyId
68
+ let keyId = get(opt, 'keyId')
69
+ if (!isestr(keyId)) {
70
+ keyId = `id`
71
+ }
72
+
73
+ //fdDwAttime
74
+ let fdDwAttime = get(opt, 'fdDwAttime')
75
+ if (!isestr(fdDwAttime)) {
76
+ fdDwAttime = `./_dwAttime`
77
+ }
78
+ if (!fsIsFolder(fdDwAttime)) {
79
+ fsCreateFolder(fdDwAttime)
80
+ }
81
+
82
+ //fdDwCurrent
83
+ let fdDwCurrent = get(opt, 'fdDwCurrent')
84
+ if (!isestr(fdDwCurrent)) {
85
+ fdDwCurrent = `./_dwCurrent`
86
+ }
87
+ if (!fsIsFolder(fdDwCurrent)) {
88
+ fsCreateFolder(fdDwCurrent)
89
+ }
90
+
91
+ //fdResult
92
+ let fdResult = get(opt, 'fdResult')
93
+ if (!isestr(fdResult)) {
94
+ fdResult = './_result'
95
+ }
96
+ if (!fsIsFolder(fdResult)) {
97
+ fsCreateFolder(fdResult)
98
+ }
99
+
100
+ //fdTaskCpSrc
101
+ let fdTaskCpSrc = get(opt, 'fdTaskCpSrc')
102
+ if (!isestr(fdTaskCpSrc)) {
103
+ fdTaskCpSrc = './_taskCpSrc'
104
+ }
105
+ if (!fsIsFolder(fdTaskCpSrc)) {
106
+ fsCreateFolder(fdTaskCpSrc)
107
+ }
108
+
109
+ //funDownload
110
+ let funDownload = get(opt, 'funDownload')
111
+
112
+ //funGetCurrent
113
+ let funGetCurrent = get(opt, 'funGetCurrent')
114
+
115
+ //funAdd
116
+ let funAdd = get(opt, 'funAdd')
117
+
118
+ //funModify
119
+ let funModify = get(opt, 'funModify')
120
+
121
+ //funRemove
122
+ let funRemove = get(opt, 'funRemove')
123
+
124
+ //funDownloadDef
125
+ let funDownloadDef = async() => {
126
+
127
+ //downloadEqs
128
+ let v = await downloadEqs(yearStart, yearEnd)
129
+ // console.log('downloadEqs', v)
130
+
131
+ //parseData
132
+ let eqs = parseData(v)
133
+ // console.log('eqsAtt', eqsAtt, size(eqsAtt))
134
+
135
+ //reverse
136
+ eqs = reverse(eqs)
137
+
138
+ each(eqs, (v) => {
139
+
140
+ let fp = `${fdDwAttime}/${v[keyId]}.json`
141
+
142
+ fs.writeFileSync(fp, JSON.stringify(v), 'utf8')
143
+
144
+ })
145
+
146
+ return eqs
147
+ }
148
+ if (!isfun(funDownload)) {
149
+ funDownload = funDownloadDef
150
+ }
151
+
152
+ //funGetCurrentDef
153
+ let funGetCurrentDef = async() => {
154
+
155
+ //vfps
156
+ let vfps = fsTreeFolder(fdDwCurrent, 1)
157
+ // console.log('vfps', vfps)
158
+
159
+ //eqs
160
+ let eqs = []
161
+ each(vfps, (v) => {
162
+
163
+ let j = fs.readFileSync(v.path, 'utf8')
164
+ let eq = JSON.parse(j)
165
+
166
+ eqs.push(eq)
167
+
168
+ })
169
+
170
+ return eqs
171
+ }
172
+ if (!isfun(funGetCurrent)) {
173
+ funGetCurrent = funGetCurrentDef
174
+ }
175
+
176
+ //funRemoveDef
177
+ let funRemoveDef = async(v) => {
178
+
179
+ let fd = `${fdResult}/${v[keyId]}`
180
+
181
+ if (fsIsFolder(fd)) {
182
+ fsDeleteFolder(fd)
183
+ }
184
+
185
+ }
186
+ if (!isfun(funRemove)) {
187
+ funRemove = funRemoveDef
188
+ }
189
+
190
+ //funAddDef
191
+ let funAddDef = async(v) => {
192
+
193
+ let fd = `${fdResult}/${v[keyId]}`
194
+
195
+ if (fsIsFolder(fd)) {
196
+ fsCleanFolder(fd)
197
+ }
198
+
199
+ await downloadPics(fd, v)
200
+
201
+ let fnIn = 'picEqReport.gif'
202
+ let fpIn = `${fd}/${fnIn}`
203
+ let fnOut = 'picEqIntensityList.gif'
204
+ let fpOut = `${fd}/${fnOut}`
205
+ await cropPic(fpIn, fpOut, 364, 199, 276, 204)
206
+
207
+ }
208
+ if (!isfun(funAdd)) {
209
+ funAdd = funAddDef
210
+ }
211
+
212
+ //funModifyDef
213
+ let funModifyDef = async(v) => {
214
+
215
+ let fd = `${fdResult}/${v[keyId]}`
216
+
217
+ if (fsIsFolder(fd)) {
218
+ fsCleanFolder(fd)
219
+ }
220
+
221
+ await downloadPics(fd, v)
222
+
223
+ }
224
+ if (!isfun(funModify)) {
225
+ funModify = funModifyDef
226
+ }
227
+
228
+ //WDwdataBuilder
229
+ let optBdr = {
230
+ fdDwAttime,
231
+ fdDwCurrent,
232
+ fdResult,
233
+ fdTaskCpSrc,
234
+ funDownload,
235
+ funGetCurrent,
236
+ funRemove,
237
+ funAdd,
238
+ funModify,
239
+ }
240
+ let ev = await WDwdataBuilder(optBdr)
241
+
242
+ return ev
243
+ }
244
+
245
+
246
+ export default WDwdataTweq
@@ -0,0 +1,15 @@
1
+ import sharp from 'sharp'
2
+
3
+
4
+ let cropPic = async (fpIn, fpOut, left, top, width, height) => {
5
+
6
+ await sharp(fpIn, {
7
+ animated: false, //設定非動畫
8
+ })
9
+ .extract({ left, top, width, height })
10
+ .toFile(fpOut)
11
+
12
+ }
13
+
14
+
15
+ export default cropPic
@@ -0,0 +1,124 @@
1
+ import map from 'lodash-es/map.js'
2
+ import join from 'lodash-es/join.js'
3
+ import axios from 'axios'
4
+
5
+
6
+ let stringify = (obj) => {
7
+
8
+ let rs = map(obj, (value, key) => {
9
+ // null or undefined 處理成空字串
10
+ let v = value == null ? '' : value
11
+ return `${encodeURIComponent(key)}=${encodeURIComponent(v)}`
12
+ })
13
+
14
+ let c = join(rs, '&')
15
+
16
+ return c
17
+ }
18
+
19
+
20
+ let downloadEqs = async(yearStart, yearEnd) => {
21
+
22
+ let url = 'https://scweb.cwa.gov.tw/zh-tw/earthquake/ajaxhandler'
23
+
24
+ let txtSDate = `${yearStart}-1-1`
25
+ // let txtEDate = `${yearEnd}-12-31` //ot().format('YYYY')
26
+ let txtEDate = `${yearEnd + 1}-1-1` //ot().format('YYYY')
27
+
28
+ let postData = {
29
+ 'draw': 6, //DataTables的請求序號, 網頁使用時會自動遞增
30
+ 'columns[0][data]': 0,
31
+ 'columns[0][name]': 'EventNo',
32
+ 'columns[0][searchable]': false,
33
+ 'columns[0][orderable]': true,
34
+ 'columns[0][search][value]': '',
35
+ 'columns[0][search][regex]': false,
36
+ 'columns[1][data]': 1,
37
+ 'columns[1][name]': 'MaxIntensity',
38
+ 'columns[1][searchable]': true,
39
+ 'columns[1][orderable]': true,
40
+ 'columns[1][search][value]': '',
41
+ 'columns[1][search][regex]': false,
42
+ 'columns[2][data]': 2,
43
+ 'columns[2][name]': 'OriginTime',
44
+ 'columns[2][searchable]': true,
45
+ 'columns[2][orderable]': true,
46
+ 'columns[2][search][value]': '',
47
+ 'columns[2][search][regex]': false,
48
+ 'columns[3][data]': 3,
49
+ 'columns[3][name]': 'MagnitudeValue',
50
+ 'columns[3][searchable]': true,
51
+ 'columns[3][orderable]': true,
52
+ 'columns[3][search][value]': '',
53
+ 'columns[3][search][regex]': false,
54
+ 'columns[4][data]': 4,
55
+ 'columns[4][name]': 'Depth',
56
+ 'columns[4][searchable]': true,
57
+ 'columns[4][orderable]': true,
58
+ 'columns[4][search][value]': '',
59
+ 'columns[4][search][regex]': false,
60
+ 'columns[5][data]': 5,
61
+ 'columns[5][name]': 'Description',
62
+ 'columns[5][searchable]': true,
63
+ 'columns[5][orderable]': true,
64
+ 'columns[5][search][value]': '',
65
+ 'columns[5][search][regex]': false,
66
+ 'columns[6][data]': 6,
67
+ 'columns[6][name]': 'Description',
68
+ 'columns[6][searchable]': true,
69
+ 'columns[6][orderable]': true,
70
+ 'columns[6][search][value]': '',
71
+ 'columns[6][search][regex]': false,
72
+ 'order[0][column]': 2,
73
+ 'order[0][dir]': 'desc',
74
+ 'start': 0,
75
+ 'length': -1, //全部資料
76
+ 'search[value]': '',
77
+ 'search[regex]': false,
78
+ 'Search': '',
79
+ txtSDate,
80
+ txtEDate,
81
+ 'txtSscale': '',
82
+ 'txtEscale': '',
83
+ 'txtSdepth': '',
84
+ 'txtEdepth': '',
85
+ 'txtLonS': '',
86
+ 'txtLonE': '',
87
+ 'txtLatS': '',
88
+ 'txtLatE': '',
89
+ 'ddlCity': '',
90
+ 'ddlTown': '',
91
+ 'ddlCitySta': '',
92
+ 'ddlStation': '',
93
+ 'txtIntensityB': '',
94
+ 'txtIntensityE': '',
95
+ 'txtLon': '',
96
+ 'txtLat': '',
97
+ 'txtKM': '',
98
+ 'ddlStationName': '------',
99
+ 'cblEventNo': 'Y',
100
+ 'txtSDatePWS': '',
101
+ 'txtEDatePWS': '',
102
+ 'txtSscalePWS': '',
103
+ 'txtEscalePWS': '',
104
+ 'ddlMark': '',
105
+ }
106
+
107
+ let r = null
108
+ try {
109
+ let res = await axios.post(url, stringify(postData), {
110
+ headers: {
111
+ 'Content-Type': 'application/x-www-form-urlencoded',
112
+ },
113
+ })
114
+ r = res.data
115
+ }
116
+ catch (err) {
117
+ console.log(err)
118
+ }
119
+
120
+ return r
121
+ }
122
+
123
+
124
+ export default downloadEqs
@@ -0,0 +1,77 @@
1
+ import { writeFile } from 'fs/promises'
2
+ import get from 'lodash-es/get.js'
3
+ import isp0int from 'wsemi/src/isp0int.mjs'
4
+ import cdbl from 'wsemi/src/cdbl.mjs'
5
+ import cint from 'wsemi/src/cint.mjs'
6
+ import delay from 'wsemi/src/delay.mjs'
7
+
8
+
9
+ let core = async (url, fp) => {
10
+
11
+ //fetch
12
+ let res = await fetch(url)
13
+
14
+ //check
15
+ if (!res.ok) {
16
+ throw new Error(`can not download file, status[${res.status}]: ${res.statusText}`)
17
+ }
18
+
19
+ //buffer
20
+ let arrayBuffer = await res.arrayBuffer()
21
+ let buffer = Buffer.from(arrayBuffer)
22
+
23
+ //writeFile
24
+ await writeFile(fp, buffer)
25
+
26
+ }
27
+
28
+
29
+ let downloadFile = async (url, fp, opt = {}) => {
30
+
31
+ //retries
32
+ let retries = get(opt, 'retries')
33
+ if (!isp0int(retries)) {
34
+ retries = 3
35
+ }
36
+ retries = cint(retries)
37
+
38
+ //timeDelay
39
+ let timeDelay = get(opt, 'retrietimeDelays')
40
+ if (!isp0int(timeDelay)) {
41
+ timeDelay = 1000
42
+ }
43
+ timeDelay = cdbl(timeDelay)
44
+
45
+ let state = 'error'
46
+ let errFin = null
47
+ let resFin = null
48
+ for (let i = 1; i <= retries; i++) {
49
+
50
+ //core
51
+ await core(url, fp)
52
+ .then((res) => {
53
+ resFin = res
54
+ state = 'success'
55
+ })
56
+ .catch((err) => {
57
+ errFin = err
58
+ })
59
+
60
+ //delay
61
+ await delay(timeDelay)
62
+
63
+ //check
64
+ if (resFin !== null) {
65
+ break
66
+ }
67
+
68
+ }
69
+
70
+ if (state === 'error') {
71
+ throw new Error(errFin)
72
+ }
73
+ return resFin
74
+ }
75
+
76
+
77
+ export default downloadFile