맹주환

Update .gitignore(related node.js) and Add function that gets date/time to put API GET method

1 +# Logs
2 +logs
3 +*.log
4 +npm-debug.log*
5 +yarn-debug.log*
6 +yarn-error.log*
7 +lerna-debug.log*
8 +.pnpm-debug.log*
9 +
10 +# Diagnostic reports (https://nodejs.org/api/report.html)
11 +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12 +
13 +# Runtime data
14 +pids
15 +*.pid
16 +*.seed
17 +*.pid.lock
18 +
19 +# Directory for instrumented libs generated by jscoverage/JSCover
20 +lib-cov
21 +
22 +# Coverage directory used by tools like istanbul
23 +coverage
24 +*.lcov
25 +
26 +# nyc test coverage
27 +.nyc_output
28 +
29 +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30 +.grunt
31 +
32 +# Bower dependency directory (https://bower.io/)
33 +bower_components
34 +
35 +# node-waf configuration
36 +.lock-wscript
37 +
38 +# Compiled binary addons (https://nodejs.org/api/addons.html)
39 +build/Release
40 +
41 +# Dependency directories
42 +node_modules/
43 +jspm_packages/
44 +
45 +# Snowpack dependency directory (https://snowpack.dev/)
46 +web_modules/
47 +
48 +# TypeScript cache
49 +*.tsbuildinfo
50 +
51 +# Optional npm cache directory
52 +.npm
53 +
54 +# Optional eslint cache
55 +.eslintcache
56 +
57 +# Optional stylelint cache
58 +.stylelintcache
59 +
60 +# Microbundle cache
61 +.rpt2_cache/
62 +.rts2_cache_cjs/
63 +.rts2_cache_es/
64 +.rts2_cache_umd/
65 +
66 +# Optional REPL history
67 +.node_repl_history
68 +
69 +# Output of 'npm pack'
70 +*.tgz
71 +
72 +# Yarn Integrity file
73 +.yarn-integrity
74 +
75 +# dotenv environment variables file
76 +.env.development.local
77 +.env.test.local
78 +.env.production.local
79 +.env.local
80 +
81 +# parcel-bundler cache (https://parceljs.org/)
82 +.cache
83 +.parcel-cache
84 +
85 +# Next.js build output
86 +.next
87 +out
88 +
89 +# Nuxt.js build / generate output
90 +.nuxt
91 +dist
92 +
93 +# Gatsby files
94 +.cache/
95 +# Comment in the public line in if your project uses Gatsby and not Next.js
96 +# https://nextjs.org/blog/next-9-1#public-directory-support
97 +# public
98 +
99 +# vuepress build output
100 +.vuepress/dist
101 +
102 +# vuepress v2.x temp and cache directory
103 +.temp
104 +.cache
105 +
106 +# Serverless directories
107 +.serverless/
108 +
109 +# FuseBox cache
110 +.fusebox/
111 +
112 +# DynamoDB Local files
113 +.dynamodb/
114 +
115 +# TernJS port file
116 +.tern-port
117 +
118 +# Stores VSCode versions used for testing VSCode extensions
119 +.vscode-test
120 +
121 +# yarn v2
122 +.yarn/cache
123 +.yarn/unplugged
124 +.yarn/build-state.yml
125 +.yarn/install-state.gz
126 +.pnp.*
...\ No newline at end of file ...\ No newline at end of file
1 -var request = require('request'); 1 +const request = require('request');
2 - 2 +const moment = require('moment');
3 -var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getUltraSrtNcst'; 3 +require('moment-timezone');
4 -var queryParams = '?' + encodeURIComponent('serviceKey') + '=서비스키'; /* Service Key*/ 4 +moment.tz.setDefault("Asia/seoul");
5 +let today = new String(get_base_date());
6 +let time = new String(get_base_time());
7 +var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst';
8 +var queryParams = '?' + encodeURIComponent('serviceKey') + '=API KEY'; /* Service Key*/
5 queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ 9 queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */
6 -queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ 10 +queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('10'); /* */
7 -queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('XML'); /* */ 11 +queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */
8 -queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent('20210628'); /* */ 12 +queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(today); /* */
9 -queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('0600'); /* */ 13 +queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2000'); /* */
10 queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent('55'); /* */ 14 queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent('55'); /* */
11 queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent('127'); /* */ 15 queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent('127'); /* */
12 16
17 +
18 +function get_base_date() // 날짜 추출 함수
19 +{
20 + // 0000~0210 사이 시간대에 조회시 전일(date -1)로 변경
21 + let date =moment().format('YYYYMMDD');
22 + let time = new String(moment().format('HHmm'));
23 + if ('0000'<=time && time<'0210'){date -= 1}
24 + return date
25 +}
26 +
27 +function get_base_time() // 시간 추출 함수
28 +{
29 + //단기예보
30 + //- Base_time : 0200, 0500, 0800, 1100, 1400, 1700, 2000, 2300 (1일 8회)
31 + //- API 제공 시간(~이후) : 02:10, 05:10, 08:10, 11:10, 14:10, 17:10, 20:10, 23:10
32 + //- 시간대 맞추기
33 + let time = new String(moment().format('HHmm'));
34 + if ('0000'<=time && time<'0210'){time = '2300'}
35 + else if ('0210'<=time && time<'0510'){time = '0200'}
36 + else if ('0510'<=time && time<'0810'){time = '0500'}
37 + else if ('0810'<=time && time<'1110'){time = '0800'}
38 + else if ('1110'<=time && time<'1410'){time = '1100'}
39 + else if ('1410'<=time && time<'1710'){time = '1400'}
40 + else if ('1710'<=time && time<'2010'){time = '1700'}
41 + else if ('2010'<=time && time<'2310'){time = '2010'}
42 + else if ('2310'<=time && time<'2359'){time = '2300'}
43 + return time
44 + }
45 +
13 request({ 46 request({
14 url: url + queryParams, 47 url: url + queryParams,
15 method: 'GET' 48 method: 'GET'
16 }, function (error, response, body) { 49 }, function (error, response, body) {
17 //console.log('Status', response.statusCode); 50 //console.log('Status', response.statusCode);
18 //console.log('Headers', JSON.stringify(response.headers)); 51 //console.log('Headers', JSON.stringify(response.headers));
19 - //console.log('Reponse received', body); 52 + console.log('Reponse received', body);
20 }); 53 });
54 +
55 +
56 +
57 +
58 +// 소스출처 : http://www.kma.go.kr/weather/forecast/digital_forecast.jsp 내부에 있음
59 +// 기상청에서 이걸 왜 공식적으로 공개하지 않을까?
60 +//
61 +// (사용 예)
62 +// var rs = dfs_xy_conv("toLL","60","127");
63 +// console.log(rs.lat, rs.lng);
64 +//
65 +
66 + //<!--
67 + //
68 + // LCC DFS 좌표변환을 위한 기초 자료
69 + //
70 + var RE = 6371.00877; // 지구 반경(km)
71 + var GRID = 5.0; // 격자 간격(km)
72 + var SLAT1 = 30.0; // 투영 위도1(degree)
73 + var SLAT2 = 60.0; // 투영 위도2(degree)
74 + var OLON = 126.0; // 기준점 경도(degree)
75 + var OLAT = 38.0; // 기준점 위도(degree)
76 + var XO = 43; // 기준점 X좌표(GRID)
77 + var YO = 136; // 기1준점 Y좌표(GRID)
78 + //
79 + // LCC DFS 좌표변환 ( code : "toXY"(위경도->좌표, v1:위도, v2:경도), "toLL"(좌표->위경도,v1:x, v2:y) )
80 + //
81 +
82 +
83 + function dfs_xy_conv(code, v1, v2) {
84 + var DEGRAD = Math.PI / 180.0;
85 + var RADDEG = 180.0 / Math.PI;
86 +
87 + var re = RE / GRID;
88 + var slat1 = SLAT1 * DEGRAD;
89 + var slat2 = SLAT2 * DEGRAD;
90 + var olon = OLON * DEGRAD;
91 + var olat = OLAT * DEGRAD;
92 +
93 + var sn = Math.tan(Math.PI * 0.25 + slat2 * 0.5) / Math.tan(Math.PI * 0.25 + slat1 * 0.5);
94 + sn = Math.log(Math.cos(slat1) / Math.cos(slat2)) / Math.log(sn);
95 + var sf = Math.tan(Math.PI * 0.25 + slat1 * 0.5);
96 + sf = Math.pow(sf, sn) * Math.cos(slat1) / sn;
97 + var ro = Math.tan(Math.PI * 0.25 + olat * 0.5);
98 + ro = re * sf / Math.pow(ro, sn);
99 + var rs = {};
100 + if (code == "toXY") {
101 + rs['lat'] = v1;
102 + rs['lng'] = v2;
103 + var ra = Math.tan(Math.PI * 0.25 + (v1) * DEGRAD * 0.5);
104 + ra = re * sf / Math.pow(ra, sn);
105 + var theta = v2 * DEGRAD - olon;
106 + if (theta > Math.PI) theta -= 2.0 * Math.PI;
107 + if (theta < -Math.PI) theta += 2.0 * Math.PI;
108 + theta *= sn;
109 + rs['x'] = Math.floor(ra * Math.sin(theta) + XO + 0.5);
110 + rs['y'] = Math.floor(ro - ra * Math.cos(theta) + YO + 0.5);
111 + }
112 + else {
113 + rs['x'] = v1;
114 + rs['y'] = v2;
115 + var xn = v1 - XO;
116 + var yn = ro - v2 + YO;
117 + ra = Math.sqrt(xn * xn + yn * yn);
118 + if (sn < 0.0) - ra;
119 + var alat = Math.pow((re * sf / ra), (1.0 / sn));
120 + alat = 2.0 * Math.atan(alat) - Math.PI * 0.5;
121 +
122 + if (Math.abs(xn) <= 0.0) {
123 + theta = 0.0;
124 + }
125 + else {
126 + if (Math.abs(yn) <= 0.0) {
127 + theta = Math.PI * 0.5;
128 + if (xn < 0.0) - theta;
129 + }
130 + else theta = Math.atan2(xn, yn);
131 + }
132 + var alon = theta / sn + olon;
133 + rs['lat'] = alat * RADDEG;
134 + rs['lng'] = alon * RADDEG;
135 + }
136 + return rs;
137 + }
...\ No newline at end of file ...\ No newline at end of file
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 { 1 {
2 "dependencies": { 2 "dependencies": {
3 - "http": "^0.0.1-security" 3 + "http": "^0.0.1-security",
4 + "moment": "^2.29.1",
5 + "moment-timezone": "^0.5.34",
6 + "request": "^2.88.2"
4 } 7 }
5 } 8 }
......