이혜인

Merge remote-tracking branch 'upstream/master' into feature/Megabox_Crawling

let express = require('express');
let app = express();
let request = require('request');
let bodyParser = require('body-parser');
const { response } = require('express');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
let today = new Date();
let year = today.getFullYear();
let month = ("0" + (1 + today.getMonth())).slice(-2);
let day = ("0" + today.getDate()).slice(-2);
let date = year + month + day-1;
//YYYYMMDD
//console.log(date);
let key = "";
let url = "http://kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json?key=" + key + "&targetDt=" + date + "&itemPerPage=";
//let rank = 5
//apiurl = url + date + "&itemPerPage=" +rank-> "출력할 박스오피스 순위(5: 5위 까지, 10 : 10위 까지.../기본, 최대 10)"
//console.log(url);
let options = {
'method' : 'GET',
'url' : url // + rank
};
app.get('/BoxOffice',(req, res) => {
options.url = url + req.body.rank;
//console.log(req.body.rank);
request(options, function (error, response, body){
if (error){
throw new Error(error);
}
let info = JSON.parse(body);
res.send(info);
});
})
// 박스오피스 순위 출력
let server = app.listen(80);
\ No newline at end of file
{
"name": "Testing BoxOffice API",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2"
}
}
\ No newline at end of file
This diff is collapsed. Click to expand it.
let express = require("express");
let app = express();
let bodyParser = require('body-parser');
app.get('', (req, res) => {
res.sendFile(__dirname + '/test.html');
});
app.listen(3907);
\ No newline at end of file
{
"name": "test01",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.17.1",
"express": "^4.15.2",
"express-session": "^1.15.2"
}
}
\ No newline at end of file
module.exports= {
html: function(title,style,list,body,control){
return `
<!doctype html>
<html>
<head>
<title>WEB - ${title}</title>
<meta charset="utf-8">
</head>
<body>
<h1><a href="/">WEB</a></h1>
<div id="map" style=${style}></div>
${list}
${control}
${body}
<p></p>
</body>
</html>
`;
}
}
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>키워드로 장소 검색하기</title>
</head>
<body>
<div id="map" style="width:100%;height:350px;"></div>
<script type="text/javascript" src="//dapi.kakao.com/v2/maps/sdk.js?appkey="></script>
<script>
// 마커를 클릭하면 장소명을 표출할 인포윈도우 입니다
let infowindow = new kakao.maps.InfoWindow({zIndex:1});
//지도를 표시할 div
let container = document.getElementById('map');
let options = {
center: new kakao.maps.LatLng(37.566826, 126.9786567),
level: 3
};
let map = new kakao.maps.Map(container, options);
// 장소 검색 객체를 생성합니다
let ps = new kakao.maps.services.Places();
// 키워드로 장소를 검색합니다
ps.keywordSearch('시청역', placesSearchCB);
// 키워드 검색 완료 시 호출되는 콜백함수 입니다
function placesSearchCB (data, status, pagination) {
if (status === kakao.maps.services.Status.OK) {
// 검색된 장소 위치를 기준으로 지도 범위를 재설정하기위해
// LatLngBounds 객체에 좌표를 추가합니다
let bounds = new kakao.maps.LatLngBounds();
for (let i=0; i<data.length; i++) {
displayMarker(data[i]);
bounds.extend(new kakao.maps.LatLng(data[i].y, data[i].x));
}
// 검색된 장소 위치를 기준으로 지도 범위를 재설정합니다
map.setBounds(bounds);
}
}
// 지도에 마커를 표시하는 함수입니다
function displayMarker(place) {
// 마커를 생성하고 지도에 표시합니다
let marker = new kakao.maps.Marker({
map: map,
position: new kakao.maps.LatLng(place.y, place.x)
});
// 마커에 클릭이벤트를 등록합니다
kakao.maps.event.addListener(marker, 'click', function() {
// 마커를 클릭하면 장소명이 인포윈도우에 표출됩니다
infowindow.setContent('<div style="padding:5px;font-size:12px;">' + place.place_name + '</div>');
infowindow.open(map, marker);
});
}
</script>
</body>
</html>
\ No newline at end of file
var express = require('express');
var config = require('./config.json')
var app = express();
var client_id = config.SearchClientID;
var client_secret = config.SearchClientSecret;
var SearchWord;
var MovieSearchParse;
var movietitlelist;
var movielist;
app.post('/search/movie', function (req, res) {SearchWord = req.query.query; res.send(SearchWord)})
app.get('/search/movie', function (req, res) {
var api_url = 'https://openapi.naver.com/v1/search/movie?query=' + encodeURI(SearchWord);
var request = require('request');
var options = {
url: api_url,
headers: {'X-Naver-Client-Id':client_id, 'X-Naver-Client-Secret': client_secret}
};
request.get(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
res.writeHead(200, {'Content-Type': 'text/json;charset=utf-8'});
MovieSearchParse = JSON.parse(body);
//movietitlelist =MovieSearchParse.items[0].title.replace(/<[^>]*>?/g, '');
movietitlelist = MovieSearchParse.items.map((x)=>{
x.title = x.title.replace(/<[^>]*>?/g, '');
return x.title;
});
movielist = MovieSearchParse.items.map((x)=>{
x.title = x.title.replace(/<[^>]*>?/g, '');
return x;
});
console.log(movielist);
res.end(body);
} else {
res.status(response.statusCode).end();
console.log('error = ' + response.statusCode);
}
});
});
app.listen(3000, function () {
console.log('http://127.0.0.1:3000/search/movie?query=검색어 app listening on port 3000!');
});
{
"dependencies": {
"express": "^4.18.1",
"request": "^2.88.2"
}
}