장소원

Delete Search.js

Showing 1 changed file with 0 additions and 139 deletions
1 -
2 -var express = require('express');
3 -var app = express();
4 -var client_id = 'cnS9zzj0OZ3xPgHqtaLJ';
5 -var client_secret = 'oQGaxdr7aq';
6 -
7 -//data parsing
8 -var data='';
9 -var title='';
10 -var link='';
11 -var category='';
12 -var address='';
13 -var roadAddress='';
14 -
15 -//받아와야할 데이터
16 -var place = '성수역'; //사용자 위치
17 -var gender = 'female'; //사용자 성별
18 -var emotion = 'talking'; //사용자 감정
19 -var menu='';
20 -
21 -if(gender=='male'){
22 - if(emotion=='angry'){
23 - menu='술';
24 - }
25 - else if(emotion=='disgust'){
26 - menu='야식';
27 - }
28 - else if(emotion=='fear'){
29 - menu='한식';
30 - }
31 - else if(emotion=='laugh'){
32 - menu='치킨';
33 - }
34 - else if(emotion=='neutral'){
35 - menu='양식';
36 - }
37 - else if(emotion=='sad'){
38 - menu='중식';
39 - }
40 - else if(emotion=='surprise'){
41 - menu='일식';
42 - }
43 - else if(emotion=='smile'){
44 - menu='고기';
45 - }
46 - else if(emotion=='talking'){
47 - menu='술';
48 - }
49 - else{
50 - menu='';
51 - }
52 -}
53 -else if(gender=='female'){
54 - if(emotion=='angry'){
55 - menu='고기';
56 - }
57 - else if(emotion=='disgust'){
58 - menu='디저트';
59 - }
60 - else if(emotion=='fear'){
61 - menu='한식';
62 - }
63 - else if(emotion=='laugh'){
64 - menu='일식';
65 - }
66 - else if(emotion=='neutral'){
67 - menu='중식';
68 - }
69 - else if(emotion=='sad'){
70 - menu='야식';
71 - }
72 - else if(emotion=='surprise'){
73 - menu='중식';
74 - }
75 - else if(emotion=='smile'){
76 - menu='치킨';
77 - }
78 - else if(emotion=='talking'){
79 - menu='카페';
80 - }
81 - else{
82 - menu='';
83 - }
84 -}
85 -else{
86 - menu='';
87 -}
88 -
89 -var query= place + ' ' + menu + ' 맛집'; //검색 원하는 문자열
90 -var display = '1'; //검색 결과 출력 건수. 최대 5개
91 -var start = '1'; //검색 시작 위치. 1만 가능
92 -var sort = 'comment'; //정렬 옵션 (random : 유사도순, comment : 카페/블로그 리뷰 개수 순)
93 -
94 -app.get('/search/local', function (req, res) {
95 - var api_url = 'https://openapi.naver.com/v1/search/local?query=' + encodeURI(query)+ '&display='+encodeURI(display) + '&start='+encodeURI(start)+'&sort='+encodeURI(sort);
96 - var request = require('request');
97 - var options = {
98 - url: api_url,
99 - headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret}
100 - };
101 - request.get(options, function (error, response, body) {
102 - if (!error && response.statusCode == 200) {
103 - res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'});
104 - console.log(body);
105 -
106 - //데이터 파싱
107 - data=JSON.parse(body);
108 - title=data.items[0].title;
109 - console.log(title);
110 -
111 - link=data.items[0].link;
112 - console.log(link);
113 -
114 - category=data.items[0].category;
115 - console.log(category);
116 -
117 - address=data.items[0].address;
118 - console.log(address);
119 -
120 - roadAddress=data.items[0].roadAddress;
121 - console.log(roadAddress);
122 -
123 -
124 - res.end(body);
125 - } else {
126 - res.status(response.statusCode).end();
127 - console.log('error = ' + response.statusCode);
128 - }
129 - });
130 - });
131 -
132 - app.listen(3000, function () {
133 - console.log('app listening on port 3000!');
134 - console.log(query);
135 -
136 - });
137 -
138 -
139 -
...\ No newline at end of file ...\ No newline at end of file