Showing
1 changed file
with
0 additions
and
115 deletions
weather_briefing/server/weather.js
deleted
100644 → 0
1 | -var request = require('request'); | ||
2 | -let express = require('express'); | ||
3 | -let app=express(); | ||
4 | -let bodyParser = require('body-parser'); | ||
5 | -let session = require('express-session'); | ||
6 | -let cors = require('cors'); | ||
7 | - | ||
8 | -app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})) | ||
9 | -app.use(bodyParser.urlencoded({ extended: false })); | ||
10 | -app.use(bodyParser.json()); | ||
11 | -app.use(cors()); | ||
12 | -//nx,ny구하기 | ||
13 | - | ||
14 | -//변수들 | ||
15 | -let curaddress; | ||
16 | -var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'; | ||
17 | -var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/ | ||
18 | - | ||
19 | -//오늘의 날짜 구하기 | ||
20 | -let base; | ||
21 | - | ||
22 | -let today=new Date(); | ||
23 | -let CurDay=today.getFullYear().toString(); | ||
24 | -if(today.getMonth()<9){ | ||
25 | - CurDay+="0"+(today.getMonth()+1).toString(); | ||
26 | -} | ||
27 | -else{ | ||
28 | - CurDay+=(today.getMonth()+1).toString(); | ||
29 | -} | ||
30 | -if(today.getDate()<10){ | ||
31 | - base=CurDay+"0"+(today.getDate()-1).toString(); | ||
32 | - CurDay+="0"+today.getDate().toString(); | ||
33 | -} | ||
34 | -else{ | ||
35 | - base=CurDay+(today.getDate()-1).toString(); | ||
36 | - CurDay+=today.getDate().toString(); | ||
37 | -} | ||
38 | -console.log(base); | ||
39 | -//nx,ny구하기 | ||
40 | -const xlsx=require('xlsx') | ||
41 | -const excel=xlsx.readFile('location.xlsx'); | ||
42 | -const sheet=excel.SheetNames[0]; | ||
43 | -const first=excel.Sheets[sheet]; | ||
44 | -const jsonData=xlsx.utils.sheet_to_json(first,{defval:""}); | ||
45 | -let nx,ny; | ||
46 | -app.post('/api/address', (req, res) => { | ||
47 | - let i=0; | ||
48 | - while(i<3788){ | ||
49 | - if(jsonData[i].address1==req.body.address1 && jsonData[i].address2==req.body.address2 && jsonData[i].address3==req.body.address3){ | ||
50 | - nx=jsonData[i].nx; | ||
51 | - ny=jsonData[i].ny; | ||
52 | - curaddress=jsonData[i]; | ||
53 | - res.json({nx, ny}); | ||
54 | - break; | ||
55 | - } | ||
56 | - i+=1; | ||
57 | - } | ||
58 | -}); | ||
59 | - | ||
60 | -let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; | ||
61 | -//입력받기 | ||
62 | -app.post('/api/weather',(req,res)=>{ | ||
63 | - const nx = req.body.dotX; | ||
64 | - const ny = req.body.dotY; | ||
65 | - | ||
66 | - queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ | ||
67 | - queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ | ||
68 | - queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ | ||
69 | - queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(base); /* */ | ||
70 | - queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2300'); /* */ | ||
71 | - queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/ | ||
72 | - queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/ | ||
73 | - | ||
74 | - request({ | ||
75 | - url: url + queryParams, | ||
76 | - method: 'GET' | ||
77 | - }, function (error, response, body) { | ||
78 | - let ex=JSON.parse(body); | ||
79 | - let item=ex.response.body.items.item; | ||
80 | - | ||
81 | - let i=0; | ||
82 | - let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; | ||
83 | - while(item[i].fcstDate==CurDay){ | ||
84 | - if(item[i].category=='POP' || item[i].category=='TMP'){ | ||
85 | - a.push(item[i]); | ||
86 | - } | ||
87 | - i+=1; | ||
88 | - } | ||
89 | - let result=[]; | ||
90 | - i=0; | ||
91 | - let Json; | ||
92 | - while(i<a.length){ | ||
93 | - if(a[i].fcstValue<=8){ | ||
94 | - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:0}; | ||
95 | - } | ||
96 | - else if(a[i].fcstValue>8 && a[i].fcstValue<=12){ | ||
97 | - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:1}; | ||
98 | - } | ||
99 | - else if(a[i].fcstValue>12 && a[i].fcstValue<=18){ | ||
100 | - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:2}; | ||
101 | - } | ||
102 | - else if(a[i].fcstValue>18 && a[i].fcstValue<=23){ | ||
103 | - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:3}; | ||
104 | - } | ||
105 | - else{ | ||
106 | - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:4}; | ||
107 | - }; | ||
108 | - result.push(Json); | ||
109 | - i+=2; | ||
110 | - } | ||
111 | - res.json(result); | ||
112 | - });//pop:강수확률 tmp:한시간 기온 | ||
113 | -}); | ||
114 | - | ||
115 | -app.listen(4000, () => console.log('Server On 4000')); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment