Showing
3 changed files
with
14 additions
and
316 deletions
weather_briefing/server/clothes.js
deleted
100644 → 0
1 | -let express = require('express'); | ||
2 | -let bodyParser = require('body-parser'); | ||
3 | -let mongo = require('mongoose'); | ||
4 | - | ||
5 | -let cors = require('cors'); | ||
6 | -let app = express(); | ||
7 | -app.use(cors()); | ||
8 | - | ||
9 | - | ||
10 | -const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority'; | ||
11 | -//const uri = 'mongodb+srv://tahmkench:dkrldnsl7@cluster0.vzipl.mongodb.net/?retryWrites=true&w=majority'; | ||
12 | - | ||
13 | -let hi = mongo.connect(uri, (err) => { | ||
14 | - if (err) { | ||
15 | - console.log(err.message); | ||
16 | - } else { | ||
17 | - console.log('Succesfully Connected!'); | ||
18 | - } | ||
19 | -}); | ||
20 | -var clothesSchema = new mongo.Schema({ | ||
21 | - gender: Number, | ||
22 | - weather: Number, | ||
23 | - top: Array, | ||
24 | - bottom:Array | ||
25 | -}); | ||
26 | - | ||
27 | -var Clothes = mongo.model('clothes', clothesSchema); | ||
28 | - | ||
29 | -app.use(bodyParser.json()); | ||
30 | -app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); | ||
31 | - | ||
32 | - | ||
33 | - | ||
34 | -app.post('/api/clothes', (req, res) => { | ||
35 | - | ||
36 | - Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => { | ||
37 | - let randt=Math.floor(Math.random()*clothes.top.length); | ||
38 | - let randb=Math.floor(Math.random()*clothes.bottom.length); | ||
39 | - if (err) return res.status(500).json({ MatchingSuccess: false }); | ||
40 | - else if (clothes) { | ||
41 | - if(req.body.rain==1) return res.status(200).json({top:"../../../../src/img/"+ clothes.top[randt]+".jpg",bottom:"../../../../src/img/"+ clothes.bottom[randb]+".jpg",umbrella:1,top1:clothes.top[randt],bottom1:clothes.bottom[randb]}) | ||
42 | - else return res.status(200).json({top:"../../../../src/img/"+ clothes.top[randt]+".jpg",bottom:"../../../../src/img/"+ clothes.bottom[randb]+".jpg",umbrella:0,top1:clothes.top[randt],bottom1:clothes.bottom[randb]}); | ||
43 | - | ||
44 | - } | ||
45 | - else return res.status(404).json({ MatchingSuccess: false }); | ||
46 | - }); | ||
47 | -}); | ||
48 | - | ||
49 | -app.listen(4000, () => console.log('Server On 4000')); | ||
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 | -// var express = require('express'); | ||
84 | -// var app = express(); | ||
85 | -// var client_id = 'EaHxnjlhHWNjVnHp2eF9'; | ||
86 | -// var client_secret = 'gPbFbMUxq_'; | ||
87 | -// app.get('/search/blog', function (req, res) { | ||
88 | -// var api_url = 'https://openapi.naver.com/v1/search/shop.json?query=' + encodeURI(req.query.query); // json 결과 | ||
89 | -// // var api_url = 'https://openapi.naver.com/v1/search/blog.xml?query=' + encodeURI(req.query.query); // xml 결과 | ||
90 | -// var request = require('request'); | ||
91 | -// var options = { | ||
92 | -// url: api_url, | ||
93 | -// headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret} | ||
94 | -// }; | ||
95 | -// request.get(options, function (error, response, body) { | ||
96 | -// if (!error && response.statusCode == 200) { | ||
97 | -// res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'}); | ||
98 | -// res.end(body); | ||
99 | -// } else { | ||
100 | -// res.status(response.statusCode).end(); | ||
101 | -// console.log('error = ' + response.statusCode); | ||
102 | -// } | ||
103 | -// }); | ||
104 | -// }); | ||
105 | -// app.listen(4000, function () { | ||
106 | -// console.log('http://127.0.0.1:3000/search/blog?query=검색어 app listening on port 3000!'); | ||
107 | -// }); | ||
108 | - | ||
109 | -// // | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -11,7 +11,7 @@ app.use(bodyParser.json()); | ... | @@ -11,7 +11,7 @@ app.use(bodyParser.json()); |
11 | app.use(cors()); | 11 | app.use(cors()); |
12 | 12 | ||
13 | let logid=null; | 13 | let logid=null; |
14 | -const uri = 'mongodb://sjieu17:tjrwls147714@cluster0-shard-00-00.lc6pe.mongodb.net:27017,cluster0-shard-00-01.lc6pe.mongodb.net:27017,cluster0-shard-00-02.lc6pe.mongodb.net:27017/?ssl=true&replicaSet=atlas-q8oxwv-shard-0&authSource=admin&retryWrites=true&w=majority'; | 14 | +const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority'; |
15 | // const uri = 'mongodb+srv://tahmkench:dkrldnsl7@cluster0.vzipl.mongodb.net/?retryWrites=true&w=majority'; | 15 | // const uri = 'mongodb+srv://tahmkench:dkrldnsl7@cluster0.vzipl.mongodb.net/?retryWrites=true&w=majority'; |
16 | 16 | ||
17 | let db = mongoose.connect(uri, (err) => { | 17 | let db = mongoose.connect(uri, (err) => { |
... | @@ -234,7 +234,6 @@ let mongo = require('mongoose'); | ... | @@ -234,7 +234,6 @@ let mongo = require('mongoose'); |
234 | 234 | ||
235 | // let cors = require('cors'); | 235 | // let cors = require('cors'); |
236 | // let app = express(); | 236 | // let app = express(); |
237 | -app.use(cors()); | ||
238 | 237 | ||
239 | 238 | ||
240 | // const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority'; | 239 | // const uri = 'mongodb+srv://sjieu17:tjrwls147714@cluster0.lc6pe.mongodb.net/weather_briefing?retryWrites=true&w=majority'; |
... | @@ -259,6 +258,19 @@ var Clothes = mongo.model('clothes', clothesSchema); | ... | @@ -259,6 +258,19 @@ var Clothes = mongo.model('clothes', clothesSchema); |
259 | app.use(bodyParser.json()); | 258 | app.use(bodyParser.json()); |
260 | app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); | 259 | app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); |
261 | 260 | ||
261 | +app.post('/api/clothes', (req, res) => { | ||
262 | + | ||
263 | + Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => { | ||
264 | + let randt=Math.floor(Math.random()*clothes.top.length); | ||
265 | + let randb=Math.floor(Math.random()*clothes.bottom.length); | ||
266 | + if (err) return res.status(500).json({ MatchingSuccess: false }); | ||
267 | + else if (clothes) { | ||
268 | + if(req.body.rain==1) return res.status(200).json({top:"../../../../src/img/"+ clothes.top[randt]+".jpg",bottom:"../../../../src/img/"+ clothes.bottom[randb]+".jpg",umbrella:1,top1:clothes.top[randt],bottom1:clothes.bottom[randb]}) | ||
269 | + else return res.status(200).json({top:"../../../../src/img/"+ clothes.top[randt]+".jpg",bottom:"../../../../src/img/"+ clothes.bottom[randb]+".jpg",umbrella:0,top1:clothes.top[randt],bottom1:clothes.bottom[randb]}); | ||
262 | 270 | ||
271 | + } | ||
272 | + else return res.status(404).json({ MatchingSuccess: false }); | ||
273 | + }); | ||
274 | +}); | ||
263 | 275 | ||
264 | app.listen(4000, () => console.log('Server On 4000')); | 276 | app.listen(4000, () => console.log('Server On 4000')); |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
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,tommorow; | ||
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 | - tommorow=CurDay+"0"+(today.getDate()+1).toString(); | ||
33 | - | ||
34 | - CurDay+="0"+today.getDate().toString(); | ||
35 | -} | ||
36 | -else{ | ||
37 | - base=CurDay+(today.getDate()-1).toString(); | ||
38 | - tommorow=CurDay+(today.getDate()+1).toString(); | ||
39 | - | ||
40 | - CurDay+=today.getDate().toString(); | ||
41 | -} | ||
42 | -console.log(tommorow); | ||
43 | -//nx,ny구하기 | ||
44 | -const xlsx=require('xlsx') | ||
45 | -const excel=xlsx.readFile('location.xlsx'); | ||
46 | -const sheet=excel.SheetNames[0]; | ||
47 | -const first=excel.Sheets[sheet]; | ||
48 | -const jsonData=xlsx.utils.sheet_to_json(first,{defval:""}); | ||
49 | -let nx,ny; | ||
50 | -app.post('/api/address', (req, res) => { | ||
51 | - let i=0; | ||
52 | - while(i<3788){ | ||
53 | - if(jsonData[i].address1==req.body.address1 && jsonData[i].address2==req.body.address2 && jsonData[i].address3==req.body.address3){ | ||
54 | - nx=jsonData[i].nx; | ||
55 | - ny=jsonData[i].ny; | ||
56 | - curaddress=jsonData[i]; | ||
57 | - res.json({nx, ny}); | ||
58 | - break; | ||
59 | - } | ||
60 | - i+=1; | ||
61 | - } | ||
62 | -}); | ||
63 | - | ||
64 | -let a3=[], a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; | ||
65 | -//입력받기 | ||
66 | -app.post('/api/weather',(req,res)=>{ | ||
67 | - let Nx = req.body.dotX; | ||
68 | - let Ny = req.body.dotY; | ||
69 | - var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/ | ||
70 | - var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'; | ||
71 | - | ||
72 | - queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ | ||
73 | - queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ | ||
74 | - queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ | ||
75 | - queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(base); /* */ | ||
76 | - queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2300'); /* */ | ||
77 | - queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(Nx); /*nx*/ | ||
78 | - queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(Ny); /*ny*/ | ||
79 | - | ||
80 | - request({ | ||
81 | - url: url + queryParams, | ||
82 | - method: 'GET' | ||
83 | - }, function (error, response, body) { | ||
84 | - let ex=JSON.parse(body); | ||
85 | - let item=ex.response.body.items.item; | ||
86 | - | ||
87 | - let i=0; | ||
88 | - let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; | ||
89 | - while(item[i].fcstDate==CurDay){ | ||
90 | - if(item[i].category=='POP' || item[i].category=='TMP'){ | ||
91 | - a.push(item[i]); | ||
92 | - } | ||
93 | - i+=1; | ||
94 | - } | ||
95 | - let result=[]; | ||
96 | - i=0; | ||
97 | - let Json; | ||
98 | - while(i<a.length){ | ||
99 | - if(a[i].fcstValue<=8){ | ||
100 | - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:0}; | ||
101 | - } | ||
102 | - else if(a[i].fcstValue>8 && a[i].fcstValue<=12){ | ||
103 | - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:1}; | ||
104 | - } | ||
105 | - else if(a[i].fcstValue>12 && a[i].fcstValue<=18){ | ||
106 | - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:2}; | ||
107 | - } | ||
108 | - else if(a[i].fcstValue>18 && a[i].fcstValue<=23){ | ||
109 | - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:3}; | ||
110 | - } | ||
111 | - else{ | ||
112 | - Json={today:CurDay,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:4}; | ||
113 | - }; | ||
114 | - result.push(Json); | ||
115 | - i+=2; | ||
116 | - } | ||
117 | - res.json(result); | ||
118 | - });//pop:강수확률 tmp:한시간 기온 | ||
119 | -}); | ||
120 | - | ||
121 | -app.post('/api/tomorrow',(req,res)=>{ | ||
122 | - const nx = req.body.dotX; | ||
123 | - const ny = req.body.dotY; | ||
124 | - var queryParams = '?' + encodeURIComponent('serviceKey') + '=3OcUyvx97Vx2YikiZ9IHyRQ6suapku7Xn8VlefQKQWrGIFOGaejhbevwagcubdHfSiQAqJwCV5lyIutw0%2BsppA%3D%3D'; /* Service Key*/ | ||
125 | - var url = 'http://apis.data.go.kr/1360000/VilageFcstInfoService_2.0/getVilageFcst'; | ||
126 | - | ||
127 | - queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('1'); /* */ | ||
128 | - queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('1000'); /* */ | ||
129 | - queryParams += '&' + encodeURIComponent('dataType') + '=' + encodeURIComponent('JSON'); /* */ | ||
130 | - queryParams += '&' + encodeURIComponent('base_date') + '=' + encodeURIComponent(base); /* */ | ||
131 | - queryParams += '&' + encodeURIComponent('base_time') + '=' + encodeURIComponent('2300'); /* */ | ||
132 | - queryParams += '&' + encodeURIComponent('nx') + '=' + encodeURIComponent(nx); /*nx*/ | ||
133 | - queryParams += '&' + encodeURIComponent('ny') + '=' + encodeURIComponent(ny); /*ny*/ | ||
134 | - | ||
135 | - request({ | ||
136 | - url: url + queryParams, | ||
137 | - method: 'GET' | ||
138 | - }, function (error, response, body) { | ||
139 | - let ex=JSON.parse(body); | ||
140 | - let item=ex.response.body.items.item; | ||
141 | - | ||
142 | - let i=0; | ||
143 | - let a=[];//, a4=[], a5=[], a6=[], a7=[], a8=[], a9=[], a10=[], a11=[], a12=[], a13=[], a14=[], a15=[], a16=[], a17=[], a18=[], a19=[], a20=[], a21=[], a22=[], a23=[]; | ||
144 | - while(item[i].fcstDate==tommorow||item[i].fcstDate==CurDay){ | ||
145 | - if((item[i].category=='POP' || item[i].category=='TMP') && item[i].fcstDate==tommorow){ | ||
146 | - a.push(item[i]); | ||
147 | - } | ||
148 | - i+=1; | ||
149 | - } | ||
150 | - let result=[]; | ||
151 | - i=0; | ||
152 | - let Json; | ||
153 | - while(i<a.length){ | ||
154 | - if(a[i].fcstValue<=8){ | ||
155 | - Json={today:tommorow,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:0}; | ||
156 | - } | ||
157 | - else if(a[i].fcstValue>8 && a[i].fcstValue<=12){ | ||
158 | - Json={today:tommorow,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:1}; | ||
159 | - } | ||
160 | - else if(a[i].fcstValue>12 && a[i].fcstValue<=18){ | ||
161 | - Json={today:tommorow,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:2}; | ||
162 | - } | ||
163 | - else if(a[i].fcstValue>18 && a[i].fcstValue<=23){ | ||
164 | - Json={today:tommorow,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:3}; | ||
165 | - } | ||
166 | - else{ | ||
167 | - Json={today:tommorow,time:a[i].fcstTime[0]+a[i].fcstTime[1],temperature:a[i].fcstValue,rainPer:a[i+1].fcstValue,weather:4}; | ||
168 | - }; | ||
169 | - result.push(Json); | ||
170 | - i+=2; | ||
171 | - } | ||
172 | - res.json(result); | ||
173 | - });//pop:강수확률 tmp:한시간 기온 | ||
174 | -}); | ||
175 | - | ||
176 | -var clothesSchema = new mongoose.Schema({ | ||
177 | - gender: Number, | ||
178 | - weather: Number, | ||
179 | - top: Array, | ||
180 | - bottom:Array | ||
181 | -}); | ||
182 | - | ||
183 | -var Clothes = mongoose.model('clothes', clothesSchema); | ||
184 | - | ||
185 | -app.use(bodyParser.json()); | ||
186 | -app.use(bodyParser.urlencoded({ limit: '1gb', extended: false })); | ||
187 | - | ||
188 | - | ||
189 | - | ||
190 | -app.post('/api/clothes', (req, res) => { | ||
191 | - | ||
192 | - Clothes.findOne({ gender: req.body.gender, weather: req.body.weather }, (err, clothes) => { | ||
193 | - let randt=Math.floor(Math.random()*clothes.top.length); | ||
194 | - let randb=Math.floor(Math.random()*clothes.bottom.length); | ||
195 | - if (err) return res.status(500).json({ MatchingSuccess: false }); | ||
196 | - else if (clothes) { | ||
197 | - if(req.body.rain==1) return res.status(200).json({top:"../../../../src/img/"+ clothes.top[randt]+".jpg",bottom:"../../../../src/img/"+ clothes.bottom[randb]+".jpg",umbrella:1,top1:clothes.top[randt],bottom1:clothes.bottom[randb]}) | ||
198 | - else return res.status(200).json({top:"../../../../src/img/"+ clothes.top[randt]+".jpg",bottom:"../../../../src/img/"+ clothes.bottom[randb]+".jpg",umbrella:0,top1:clothes.top[randt],bottom1:clothes.bottom[randb]}); | ||
199 | - | ||
200 | - } | ||
201 | - else return res.status(404).json({ MatchingSuccess: false }); | ||
202 | - }); | ||
203 | -}); | ||
204 | - | ||
205 | -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