Merge remote-tracking branch 'upstream/master' into feature/Megabox_Crawling
Showing
9 changed files
with
230 additions
and
0 deletions
BoxOffice/app.js
0 → 100644
1 | +let express = require('express'); | ||
2 | +let app = express(); | ||
3 | +let request = require('request'); | ||
4 | +let bodyParser = require('body-parser'); | ||
5 | +const { response } = require('express'); | ||
6 | + | ||
7 | +app.use(bodyParser.urlencoded({ extended: false })); | ||
8 | +app.use(bodyParser.json()); | ||
9 | + | ||
10 | + | ||
11 | +let today = new Date(); | ||
12 | +let year = today.getFullYear(); | ||
13 | +let month = ("0" + (1 + today.getMonth())).slice(-2); | ||
14 | +let day = ("0" + today.getDate()).slice(-2); | ||
15 | +let date = year + month + day-1; | ||
16 | +//YYYYMMDD | ||
17 | + | ||
18 | +//console.log(date); | ||
19 | + | ||
20 | +let key = ""; | ||
21 | +let url = "http://kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=" + key + "&targetDt=" + date + "&itemPerPage="; | ||
22 | +//let rank = 5 | ||
23 | +//apiurl = url + date + "&itemPerPage=" +rank-> "출력할 박스오피스 순위(5: 5위 까지, 10 : 10위 까지.../기본, 최대 10)" | ||
24 | +//console.log(url); | ||
25 | + | ||
26 | +let options = { | ||
27 | + 'method' : 'GET', | ||
28 | + 'url' : url // + rank | ||
29 | +}; | ||
30 | + | ||
31 | + | ||
32 | + | ||
33 | +app.get('/BoxOffice',(req, res) => { | ||
34 | + options.url = url + req.body.rank; | ||
35 | + //console.log(req.body.rank); | ||
36 | + request(options, function (error, response, body){ | ||
37 | + if (error){ | ||
38 | + throw new Error(error); | ||
39 | + } | ||
40 | + let info = JSON.parse(body); | ||
41 | + res.send(info); | ||
42 | + }); | ||
43 | +}) | ||
44 | + | ||
45 | +// 박스오피스 순위 출력 | ||
46 | + | ||
47 | + | ||
48 | + | ||
49 | + | ||
50 | + | ||
51 | + | ||
52 | +let server = app.listen(80); | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
BoxOffice/package.json
0 → 100644
1 | +{ | ||
2 | + "name": "Testing BoxOffice API", | ||
3 | + "version": "1.0.0", | ||
4 | + "description": "", | ||
5 | + "main": "index.js", | ||
6 | + "scripts": { | ||
7 | + "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | + }, | ||
9 | + "author": "", | ||
10 | + "license": "ISC", | ||
11 | + "dependencies": { | ||
12 | + "body-parser": "^1.17.1", | ||
13 | + "express": "^4.15.2" | ||
14 | + } | ||
15 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
LICENSE
0 → 100644
This diff is collapsed. Click to expand it.
MapAPI/app.js
0 → 100644
MapAPI/package.json
0 → 100644
1 | +{ | ||
2 | + "name": "test01", | ||
3 | + "version": "1.0.0", | ||
4 | + "description": "", | ||
5 | + "main": "index.js", | ||
6 | + "scripts": { | ||
7 | + "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | + }, | ||
9 | + "author": "", | ||
10 | + "license": "ISC", | ||
11 | + "dependencies": { | ||
12 | + "body-parser": "^1.17.1", | ||
13 | + "express": "^4.15.2", | ||
14 | + "express-session": "^1.15.2" | ||
15 | + } | ||
16 | + } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
MapAPI/template.js
0 → 100644
1 | +module.exports= { | ||
2 | + html: function(title,style,list,body,control){ | ||
3 | + return ` | ||
4 | + <!doctype html> | ||
5 | + <html> | ||
6 | + <head> | ||
7 | + <title>WEB - ${title}</title> | ||
8 | + <meta charset="utf-8"> | ||
9 | + </head> | ||
10 | + <body> | ||
11 | + <h1><a href="/">WEB</a></h1> | ||
12 | + <div id="map" style=${style}></div> | ||
13 | + ${list} | ||
14 | + ${control} | ||
15 | + ${body} | ||
16 | + <p></p> | ||
17 | + </body> | ||
18 | + </html> | ||
19 | + `; | ||
20 | + } | ||
21 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
MapAPI/test.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html> | ||
3 | +<head> | ||
4 | + <meta charset="utf-8"/> | ||
5 | + <title>키워드로 장소 검색하기</title> | ||
6 | +</head> | ||
7 | +<body> | ||
8 | + <div id="map" style="width:100%;height:350px;"></div> | ||
9 | + <script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey="></script> | ||
10 | + <script> | ||
11 | + // 마커를 클릭하면 장소명을 표출할 인포윈도우 입니다 | ||
12 | + let infowindow = new kakao.maps.InfoWindow({zIndex:1}); | ||
13 | + //지도를 표시할 div | ||
14 | + let container = document.getElementById('map'); | ||
15 | + let options = { | ||
16 | + center: new kakao.maps.LatLng(37.566826, 126.9786567), | ||
17 | + level: 3 | ||
18 | + }; | ||
19 | + let map = new kakao.maps.Map(container, options); | ||
20 | + // 장소 검색 객체를 생성합니다 | ||
21 | + let ps = new kakao.maps.services.Places(); | ||
22 | + // 키워드로 장소를 검색합니다 | ||
23 | + ps.keywordSearch('시청역', placesSearchCB); | ||
24 | + | ||
25 | + // 키워드 검색 완료 시 호출되는 콜백함수 입니다 | ||
26 | + function placesSearchCB (data, status, pagination) { | ||
27 | + if (status === kakao.maps.services.Status.OK) { | ||
28 | + // 검색된 장소 위치를 기준으로 지도 범위를 재설정하기위해 | ||
29 | + // LatLngBounds 객체에 좌표를 추가합니다 | ||
30 | + let bounds = new kakao.maps.LatLngBounds(); | ||
31 | + | ||
32 | + for (let i=0; i<data.length; i++) { | ||
33 | + displayMarker(data[i]); | ||
34 | + bounds.extend(new kakao.maps.LatLng(data[i].y, data[i].x)); | ||
35 | + } | ||
36 | + | ||
37 | + // 검색된 장소 위치를 기준으로 지도 범위를 재설정합니다 | ||
38 | + map.setBounds(bounds); | ||
39 | + } | ||
40 | + } | ||
41 | + // 지도에 마커를 표시하는 함수입니다 | ||
42 | + function displayMarker(place) { | ||
43 | + | ||
44 | + // 마커를 생성하고 지도에 표시합니다 | ||
45 | + let marker = new kakao.maps.Marker({ | ||
46 | + map: map, | ||
47 | + position: new kakao.maps.LatLng(place.y, place.x) | ||
48 | + }); | ||
49 | + | ||
50 | + // 마커에 클릭이벤트를 등록합니다 | ||
51 | + kakao.maps.event.addListener(marker, 'click', function() { | ||
52 | + // 마커를 클릭하면 장소명이 인포윈도우에 표출됩니다 | ||
53 | + infowindow.setContent('<div style="padding:5px;font-size:12px;">' + place.place_name + '</div>'); | ||
54 | + infowindow.open(map, marker); | ||
55 | + }); | ||
56 | + } | ||
57 | + | ||
58 | + | ||
59 | + </script> | ||
60 | +</body> | ||
61 | +</html> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
SearchAPI/app.js
0 → 100644
1 | +var express = require('express'); | ||
2 | +var config = require('./config.json') | ||
3 | +var app = express(); | ||
4 | +var client_id = config.SearchClientID; | ||
5 | +var client_secret = config.SearchClientSecret; | ||
6 | + | ||
7 | + | ||
8 | +var SearchWord; | ||
9 | +var MovieSearchParse; | ||
10 | +var movietitlelist; | ||
11 | +var movielist; | ||
12 | +app.post('/search/movie', function (req, res) {SearchWord = req.query.query; res.send(SearchWord)}) | ||
13 | +app.get('/search/movie', function (req, res) { | ||
14 | + var api_url = 'https://openapi.naver.com/v1/search/movie?query=' + encodeURI(SearchWord); | ||
15 | + var request = require('request'); | ||
16 | + var options = { | ||
17 | + url: api_url, | ||
18 | + headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret} | ||
19 | + }; | ||
20 | + request.get(options, function (error, response, body) { | ||
21 | + if (!error && response.statusCode == 200) { | ||
22 | + res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'}); | ||
23 | + | ||
24 | + | ||
25 | + MovieSearchParse = JSON.parse(body); | ||
26 | + //movietitlelist =MovieSearchParse.items[0].title.replace(/<[^>]*>?/g, ''); | ||
27 | + movietitlelist = MovieSearchParse.items.map((x)=>{ | ||
28 | + x.title = x.title.replace(/<[^>]*>?/g, ''); | ||
29 | + return x.title; | ||
30 | + }); | ||
31 | + movielist = MovieSearchParse.items.map((x)=>{ | ||
32 | + x.title = x.title.replace(/<[^>]*>?/g, ''); | ||
33 | + return x; | ||
34 | + }); | ||
35 | + console.log(movielist); | ||
36 | + | ||
37 | + res.end(body); | ||
38 | + } else { | ||
39 | + res.status(response.statusCode).end(); | ||
40 | + console.log('error = ' + response.statusCode); | ||
41 | + } | ||
42 | + }); | ||
43 | +}); | ||
44 | + | ||
45 | + | ||
46 | + app.listen(3000, function () { | ||
47 | + console.log('http://127.0.0.1:3000/search/movie?query=검색어 app listening on port 3000!'); | ||
48 | + }); | ||
49 | + |
-
Please register or login to post a comment