강상위

DB - timetable connected

- 디비에서 정보를 가져와 나만의 시간표 표시완료
var async = require('async');
var webdriver = require('selenium-webdriver');
var options = {desiredCapabilities: {browserName: 'chrome'}};
var JASON = require('jason')
const {Builder, By, Key, until} = require('selenium-webdriver');
var iconv = require('iconv-lite')
const fs = require('fs')
datalist = []
module.exports = {
search_onairanddate: function(driver,string,callback) {
let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=" + string
driver
.get(url1).then(() => {
driver
.findElements(webdriver.By.className('brcs_detail'))
.then(broad_info => {
broad_info[0].findElement(webdriver.By.tagName('dl'))
.then(more_data => {
more_data.findElement(webdriver.By.tagName('dd'))
.then(one_line => {
one_line.findElement(webdriver.By.className("inline"))
.then(isbroad => {
isbroad.getText()
.then(isbroad_string => {
broadcasting=isbroad_string.substring(0,4)
isbroad = isbroad_string.substring(18,21)
br_date = isbroad_string.substring(23,24)
br_date = br_date + "요일"
br_time = isbroad_string.substring(26,34)
datalist.push(broadcasting,isbroad,br_date,br_time)
fs.writeFileSync("./log/"+string+"_br_isonair.txt", '\ufeff' + datalist, {encoding: 'utf8'});
for(var i =0; i<100; ) {
if() {
i++
}
}
callback()
})
})
})
})
})
})
driver.findElement(webdriver.By.className('brcs_thumb'))
.then(brcs_thumb => {
brcs_thumb.findElements(webdriver.By.tagName('img'))
.then( img => {
img[0].getAttribute('src')
.then(img_src => {
datalist.push(img_src)
})
})
})
}
}
\ No newline at end of file
var async = require('async');
var webdriver = require('selenium-webdriver');
var options = {desiredCapabilities: {browserName: 'chrome'}};
const {Builder, By, Key, until} = require('selenium-webdriver');
const fs = require('fs')
const screen = {
width: 640,
height: 480
};
var a=8000
var img_src_list = []
var text_list = []
var testStartRunTime = 0;
var testruntime = 0;
var time = 0;
module.exports = {
search_broadcasting :function(driver,url,name,callback) {
function testRunTimer() {
var today = new Date(); // 현재시간 얻기
var runTime = today.getTime(); // 밀리세컨드 ( 1970/01/01 부터 현재까지의 시간을 밀리세컨드로 나타냄 )
var rtn = 0;
if (testStartRunTime == 0) {
testStartRunTime = runTime;
} else {
rtn = (runTime - testStartRunTime) / 1000;
testStartRunTime = 0;
}
return rtn;
}
driver
.get("http://"+url)
.then(() => {
driver.findElement(webdriver.By.id('pagination_76'))
.then ( paginationBtn => {
paginationBtn.findElements(webdriver.By.className('bt_next'))
.then(Btn_next => {
driver.findElement(webdriver.By.id('listUI_76'))
.then(contentsUI => {
clickandget(function() {
Btn_next[0].click()
setTimeout(() => {
clickandget(function() {
Btn_next[0].click()
setTimeout(() => {
clickandget(function() {
Btn_next[0].click()
setTimeout(() => {
clickandget(function(){
Btn_next[0].click()
setTimeout(() => {
clickandget(function(){
fs.writeFileSync("./log/"+name+"_img_src_br.txt", '\ufeff' + img_src_list, {encoding: 'utf8'});
fs.writeFileSync("./log/"+name+"_title_br.txt", '\ufeff' + text_list, {encoding: 'utf8'});
setTimeout(() => {
callback()
}, 500);
})
}, testruntime*1000+800);
})
}, testruntime*1000+800);
},testruntime*1000+800)
}, testruntime*1000+800);
})
}, testruntime*1000+800);
})
function clickandget(_callback) {
testRunTimer()
Btn_next[0].isDisplayed().then(function(state) {
if(state) {
contentsUI.findElements(webdriver.By.tagName('li'))
.then(elems => {
elems.forEach(elem => {
elem.findElements(webdriver.By.tagName('img'))
.then(img => {
img[0].getAttribute('src')
.then(img_src => {
elem.findElements(webdriver.By.className('tit'))
.then (titles => {
titles.forEach(title => {
title.getText()
.then(text => {
text_list.push(text)
img_src_list.push(img_src)
if(text_list.length % 5 == 0) {
var testruntime = testRunTimer();
time = time+testruntime*1000
_callback()
}
})
})
})
})
})
})
})
}
else {
fs.writeFileSync("./log/"+name+"_img_src_br.txt", '\ufeff' + img_src_list, {encoding: 'utf8'});
fs.writeFileSync("./log/"+name+"_title_br.txt", '\ufeff' + text_list, {encoding: 'utf8'});
setTimeout(() => {
callback()
}, 500);
}
},function(err) {
fs.writeFileSync("./log/"+name+"_img_src_br.txt", '\ufeff' + img_src_list, {encoding: 'utf8'});
fs.writeFileSync("./log/"+name+"_title_br.txt", '\ufeff' + text_list, {encoding: 'utf8'});
setTimeout(() => {
callback()
}, 500);
})
}
})
})
})
})
function sleep (time) {
return new Promise((resolve) => setTimeout(resolve, time));
}
}
}
//var driver = new webdriver.Builder()
//.forBrowser('chrome')
//.withCapabilities(webdriver.Capabilities.chrome())
//.build();
//search_broadcasting(driver,"people.search.naver.com/search.naver?where=nexearch&sm=tab_ppn&query=유재석&os=94702&ie=utf8&key=PeopleService","유재석",function() {
// console.log("B")
//})
\ No newline at end of file
var async = require('async');
var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome')
var Options = new chrome.Options();
Options.addArguments('headless')
Options.addArguments('disable-gpu')
const fs = require('fs')
var check = 0
var testStartRunTime = 0;
var testruntime = 0;
const {Builder, By, Key, until} = require('selenium-webdriver');
var next_link_list = []
var src_list = []
var text_list = []
var return_list = []
module.exports = {
first_search :function (driver,string,callback) {
function testRunTimer() {
var today = new Date(); // 현재시간 얻기
var runTime = today.getTime(); // 밀리세컨드 ( 1970/01/01 부터 현재까지의 시간을 밀리세컨드로 나타냄 )
var rtn = 0;
if (testStartRunTime == 0) {
testStartRunTime = runTime;
} else {
rtn = (runTime - testStartRunTime) / 1000;
testStartRunTime = 0;
}
return rtn;
}
let url1 = "https://people.search.naver.com/search.naver?sm=tab_hty&where=nexearch&query="+string+"&ie=utf8&x=0&y=0"
driver
.get(url1).then(() => {
testRunTimer()
driver
.findElements(webdriver.By.className('result_profile'))
.then(profiles => {
profiles.forEach(profile => {
profile.findElements(webdriver.By.className('thmb'))
.then(links=> {
links.forEach(link => {
link.getAttribute('href')
.then(next_link => {
profile.findElements(webdriver.By.className('thmb_img'))
.then((imgs) => {
imgs.forEach(img => {
img.getAttribute('src')
.then(src => {
next_link_list.push(next_link)
src_list.push(src)
//text_list.push(text)
testruntime += testRunTimer()
setTimeout(function() {
check++;
if(check==1) {
//return_list.push(text_list)
setTimeout(function() {
fs.writeFileSync("./log/"+string+"_next_link.txt", '\ufeff' + next_link_list, {encoding: 'utf8'});
fs.writeFileSync("./log/"+string+"_img_src.txt", '\ufeff' + src_list, {encoding: 'utf8'});
callback()
},500)
}
},testruntime*1000+1000)
})
})
})
})
})
})
})
})
})
}
}
\ No newline at end of file
var webdriver = require('selenium-webdriver');
const {Builder, By, Key, until} = require('selenium-webdriver');
const fs = require('fs')
var arr = []
var result_arr = []
var temp = []
var i=0
var check = 0
module.exports = {
search_broadcasting_time : function(driver,broadcast,day,findtitle, callback) {
let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=0&ie=utf8&query="+broadcast+"+"+day+"+편성표"
driver
.get(url1).then(() => {
driver
.findElements(webdriver.By.className('cont_inner type_day _scheduleArea'))
.then(contentsearch_section=> {
contentsearch_section[0].findElements(webdriver.By.tagName('tbody'))
.then(tbody => {
tbody[0].findElements(webdriver.By.tagName('tr'))
.then(trs => {
trs.forEach(tr => {
tr.getText()
.then(content => {
if(content.indexOf(findtitle) != -1) {
arr = content.toString().split('\n')
str(function() {
i++
if(i==2) {
fs.writeFileSync("./log/"+findtitle+"_time_detail.txt", '\ufeff' + result_arr, {encoding: 'utf8'});
callback()
}
})
function str(_callback) {
temp[i+0] = arr[0] + " " + arr[1].substr(0,2) + "분"
temp[i+1] = arr[1].substr(3)
result_arr.push(temp[i+0],temp[i+1])
if(arr.length == 3) {
temp[i+2] = arr[0] + " " + arr[2].substr(0,2) + "분"
temp[i+3] = arr[2].substr(3)
result_arr.push(temp[i+2],temp[i+3])
i++
}
setTimeout(() => {
_callback()
}, 500);
}
}
})
})
})
})
})
})
}
}
\ No newline at end of file
SBS ,방영중,일요일,오후 04:50
\ No newline at end of file
16시 50분,런닝맨 1부,17시 40분,런닝맨 2부
\ No newline at end of file
https://search.pstatic.net/common?type=a&size=60x76&quality=95&src=http://sstatic.naver.net/people/portrait/201808/20180828141741978.jpg,https://search.pstatic.net/common?type=a&size=60x76&quality=95&src=http://people.phinf.naver.net/20150328_223/1427473846485vwRXc_JPEG/chosun_400093103.jpg
\ No newline at end of file
https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/65/99/10/57_659910_poster_image_1506416659493.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/75/90/39/57_8759039_poster_image_1542880871064.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/75/91/55/57_8759155_poster_image_1540263433873.png,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/77/64/63/57_8776463_poster_image_1539219518133.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/66/33/78/57_8663378_poster_image_1534389778374.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/09/95/73/57_8099573_poster_image_1523413341476.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/44/21/84/57_6442184_poster_image_1514533716001.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/78/49/00/57_2784900_poster_image_1444978089345.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/44/71/54/57_2447154_poster_image_1433400789533.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/86/80/32/57_1868032_poster_image_1417592147530.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/67/49/81/57_674981_poster_image_1537158466551.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/0/0/164/164267.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/66/10/22/57_661022_poster_image_1457491725216.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/0/0/154/154271.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/0/0/154/154273.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/0/0/162/162685.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/0/0/159/159015.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/0/0/159/159705.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/0/0/160/160020.jpg,https://search.pstatic.net/common?type=mfullfill&size=96x138&quality=95&src=http://sstatic.naver.net/keypage/image/dss/57/65/91/74/57_659174_poster_image_1442911837885.jpg
\ No newline at end of file
https://people.search.naver.com/search.naver?where=nexearch&sm=tab_ppn&query=%EC%9C%A0%EC%9E%AC%EC%84%9D&os=94702&ie=utf8&key=PeopleService,https://people.search.naver.com/search.naver?where=nexearch&sm=tab_ppn&query=%EC%9C%A0%EC%9E%AC%EC%84%9D&os=362156&ie=utf8&key=PeopleService
\ No newline at end of file
무한도전,요즘애들,미추리 8-1000,해피투게더 4,유 퀴즈 온 더 블럭,범인은 바로 너!,투유 프로젝트 - 슈가맨 2,투유 프로젝트 - 슈가맨,동상이몽, 괜찮아 괜찮아!,나는 남자다,런닝맨,패밀리가 떴다 1,해피투게더 3,옛날 TV,하자 GO!,X맨 일요일이 좋다,강력추천 토요일,해피투게더 2,느낌표,공감토크쇼 놀러와
\ No newline at end of file
var async = require('async');
var webdriver = require('selenium-webdriver');
//var options = {desiredCapabilities: {browserName: 'chrome'}};
var chrome = require('selenium-webdriver/chrome')
var Options = new chrome.Options();
Options.addArguments('headless')
Options.addArguments('disable-gpu')
var test1 = require('./crawling_samename')
const fs = require('fs')
const test2 = require('./crawling_broadcasting')
const test3 = require('./crawling_br_onair_date')
const test4 = require('./crawling_time')
var util = require('util')
var EventEmitter = require('events').EventEmitter;
var next_link_Array = []
var img_src_Array = []
const {Builder, By, Key, until} = require('selenium-webdriver');
var driver = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeOptions(Options)
.build();
var driver_1 = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeOptions(Options)
.build()
var driver_2 = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeOptions(Options)
.build();
var driver_3 = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeOptions(Options)
.build();
var First_Search = function(name) {
var self=this;
this.on('input', function() {
if(fs.existsSync("./log/"+name+"_next_link.txt")) {
const next_link = fs.readFileSync("./log/"+name+"_next_link.txt");
const img_src = fs.readFileSync("./log/"+name+"_img_src.txt");
next_link_Array = next_link.toString().split(',');
img_src_Array = img_src.toString().split(',');
driver.quit()
console.log(next_link_Array)
console.log(img_src_Array)
setTimeout(function() {
br_search.emit('click')
},1000)
}
else {
test1.first_search(driver,name,function() {
const next_link = fs.readFileSync("./log/"+name+"_next_link.txt");
const img_src = fs.readFileSync("./log/"+name+"_img_src.txt");
next_link_Array = next_link.toString().split(',');
img_src_Array = img_src.toString().split(',');
br_search = new broadcasting_search(next_link_Array,"유재석",0)
console.log(next_link_Array)
console.log(img_src_Array)
driver.quit()
setTimeout(function() {
br_search.emit('click')
},1000)
})
}
})
}
util.inherits(First_Search,EventEmitter);
first_search1 = new First_Search("유재석")
first_search1.emit('input')
var img_src_br_list = []
var title_list = []
var broadcasting_search = function(next_link,name,num) {
var self=this;
this.on('click', function() {
if(fs.existsSync("./log/"+name+"_img_src_br.txt")) {
const img_src_br = fs.readFileSync("./log/"+name+"_img_src_br.txt");
img_src_br_list = img_src_br.toString().split(',');
const title_br = fs.readFileSync("./log/"+name+"_title_br.txt");
title_list = title_br.toString().split(',');
driver_1.quit()
console.log(img_src_br_list)
console.log(title_list)
is_onair.emit('click_1')
}
else {
test2.search_broadcasting(driver_1,next_link[num].substr(9),name,function() {
const img_src_br = fs.readFileSync("./log/"+name+"_img_src_br.txt");
img_src_br_list = img_src_br.toString().split(',');
const title_br = fs.readFileSync("./log/"+name+"_title_br.txt");
title_list = title_br.toString().split(',');
driver_1.quit()
console.log(img_src_br_list)
console.log(title_list)
is_onair.emit('click_1')
})
}
})
}
util.inherits(broadcasting_search,EventEmitter);
br_search = new broadcasting_search(next_link_Array,"유재석",0)
br_datalist = []
var isonair = function(num) {
var self = this
this.on('click_1',function() {
if(fs.existsSync("./log/"+title_list[num]+"_br_isonair.txt")) {
const img_src_br = fs.readFileSync("./log/"+title_list[num]+"_br_isonair.txt");
br_datalist = img_src_br.toString().split(',');
br_datalist[0] = br_datalist[0].trim()
console.log(br_datalist)
Search_detail_time.emit('click_2')
}
else {
test3.search_onairanddate(driver_2,title_list[num],function() {
const img_src_br = fs.readFileSync("./log/"+title_list[num]+"_br_isonair.txt");
br_datalist = img_src_br.toString().split(',');
br_datalist[0] = br_datalist[0].trim()
console.log(br_datalist)
Search_detail_time.emit('click_2')
})
}
})
}
util.inherits(isonair,EventEmitter);
is_onair = new isonair(11)
var detail_time_list = []
var search_detail_time = function(num) {
var self = this;
this.on('click_2',function() {
if(br_datalist[1] == "방영중") {
if(fs.existsSync("./log/"+title_list[num]+"_time_detail.txt")) {
const detail = fs.readFileSync("./log/"+title_list[num]+"_time_detail.txt");
detail_time_list = detail.toString().split(',');
console.log(detail_time_list)
}
else {
test4.search_broadcasting_time(driver_3,br_datalist[0],br_datalist[2],title_list[num],function(){
const detail = fs.readFileSync("./log/"+title_list[num]+"_time_detail.txt");
detail_time_list = detail.toString().split(',');
console.log(detail_time_list)
})
}
}
})
}
util.inherits(search_detail_time,EventEmitter);
Search_detail_time = new search_detail_time(11);
This diff is collapsed. Click to expand it.
{
"name": "cheerio",
"version": "1.0.0",
"description": "",
"main": "practice.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"async": "^2.6.1",
"events": "^3.0.0",
"fs": "0.0.1-security",
"iconv-lite": "^0.4.24",
"jason": "^2.0.0",
"json": "^9.0.6",
"selenium-webdriver": "^3.6.0",
"util": "^0.11.1",
"webdriverio": "^4.14.0"
}
}
var async = require('async');
var webdriver = require('selenium-webdriver');
//var options = {desiredCapabilities: {browserName: 'chrome'}};
var chrome = require('selenium-webdriver/chrome')
var Options = new chrome.Options();
Options.addArguments('headless')
Options.addArguments('disable-gpu')
var test1 = require('./crawling_samename')
const fs = require('fs')
var util = require('util')
var EventEmitter = require('events').EventEmitter;
var next_link_Array = []
var img_src_Array = []
const {Builder, By, Key, until} = require('selenium-webdriver');
var driver = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome())
.setChromeOptions(Options)
.build();
var result_arr = []
module.exports = {
First_Search :function(name) {
return new Promise(function(resolve,reject) {
if(fs.existsSync("./log/"+name+"_next_link.txt")) {
const next_link = fs.readFileSync("./log/"+name+"_next_link.txt");
const img_src = fs.readFileSync("./log/"+name+"_img_src.txt");
next_link_Array = next_link.toString().split(',');
img_src_Array = img_src.toString().split(',');
driver.quit()
result_arr.push(next_link_Array)
result_arr.push(img_src_Array)
console.log(next_link_Array)
console.log(img_src_Array)
console.log(result_arr)
return result_arr
}
else {
test1.first_search(driver,name,function() {
const next_link = fs.readFileSync("./log/"+name+"_next_link.txt");
const img_src = fs.readFileSync("./log/"+name+"_img_src.txt");
next_link_Array = next_link.toString().split(',');
img_src_Array = img_src.toString().split(',');
br_search = new broadcasting_search(next_link_Array,"유재석",0)
result_arr.push(next_link_Array)
result_arr.push(img_src_Array)
console.log(next_link_Array)
console.log(img_src_Array)
driver.quit()
return result_arr
})
}
})
}
//util.inherits(First_Search,EventEmitter);
//first_search1 = new First_Search("유재석")
//first_search1.emit('input')
}
//다른 파일에서 호출하는 방법
//var a=require("./sane_name_search")
//var arr = []
//a.First_Search("(검색어 입력)").then(aa => {
// arr=a
// console.log(arr)
//})
......@@ -6,7 +6,7 @@ var mongoose = require('mongoose');
var passport = require('passport');
//DB연결
mongoose.connect('mongodb://username:pwd@host/dbname');
mongoose.connect('mongodb://00:00@000/000');
mongoose.Promise = global.Promise;
var db = mongoose.connection;
......@@ -24,6 +24,10 @@ db.once('open', function()
// DB모델정의
var Users = require('./models/users');
var Timetables = require('./models/timetables');
// Client-Browser와의 공유
//app.use("/static", express.static("public"));
// session
app.use(session({
......@@ -48,7 +52,7 @@ app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
// router import
var router = require('./routing')(app, Users);
var router = require('./routing')(app, Users, Timetables);
var server = app.listen(23023, function()
{
......
This file is too large to display.
var mongoose = require('mongoose');
var timetableSchema = mongoose.Schema
(
{
user_id: String,
pname: String,
pweekday: Number,
start_hour: Number,
start_min: Number
}
);
module.exports = mongoose.model('timetable',timetableSchema);
This diff is collapsed. Click to expand it.
......@@ -13,17 +13,25 @@
"author": "",
"license": "ISC",
"dependencies": {
"async": "^2.6.1",
"bcrypt-nodejs": "0.0.3",
"body-parser": "^1.18.3",
"cheerio": "^1.0.0-rc.2",
"ejs": "^2.6.1",
"events": "^3.0.0",
"express": "^4.16.4",
"express-session": "^1.15.6",
"fs": "0.0.1-security",
"iconv": "^2.3.1",
"iconv-lite": "^0.4.24",
"jason": "^2.0.0",
"json": "^9.0.6",
"mongoose": "^5.3.14",
"passport": "^0.4.0",
"passport-local": "^1.0.0",
"request": "^2.88.0",
"selenium-webdriver": "^4.0.0-alpha.1"
"selenium-webdriver": "^4.0.0-alpha.1",
"util": "^0.11.1",
"webdriverio": "^4.14.1"
}
}
......
{
hi: "hi"
}
\ No newline at end of file
(function(exports)
{
var item;
exports.sharingIn = function(temp)
{
item = temp;
return item;
};
exports.sharingOut = function()
{
return item;
};
})(typeof exports === "undefined" ? this["share"]={}: exports);
\ No newline at end of file
module.exports = function(app, Users)
module.exports = function(app, Users, Timetables)
{
var passport = require('passport');
......@@ -122,22 +122,89 @@ module.exports = function(app, Users)
res.render("programs", {programs: program_list});
});
// 나만의 시간표
app.get("/timetable", function(req, res)
// 나만의 시간표에 추가 - 로그인 필수
app.get("/addtt", function(req, res)
{
if(req.isAuthenticated())
{
// 유저가 선택한 프로그램 정보 입력
var program = new Timetables();
program.user_id = req.user;
program.pname = "짠내투어";
program.pweekday = 6;
program.start_hour = 20;
program.start_min = 20;
var program_list =
[
// DB저장
program.save(function(err)
{
if(err)
{
content: '런닝맨',
endDate: new Date(2018, 11, 9, 5, 45),
startDate: new Date(2018, 11, 9, 1, 30),
disabled: true
console.log(err);
res.send("Error!")
}
];
else
{
console.log("TT Add Success");
res.redirect('/timetable');
}
});
}
// 로그인 중이 아니라면
else res.redirect("/");
});
res.render("timetable", {pl: JSON.stringify(program_list)});
});
// 나만의 시간표 - 로그인 필수
app.get("/timetable", function(req, res)
{
if(req.isAuthenticated())
{
// 유저별 프로그램 리스트 만들기
var program_list = [];
// 디비에서 유저아이디에 맞는 programs 가져오기
// 디비정보 가져오는 것은 동기로 설정
function temp(callback)
{
Timetables.find({user_id: req.user},function(err, programs)
{
if(err)
{
console.log(err);
res.send("Error!");
}
else
{
programs.forEach(val =>
{
// 시간조정 로직
e_wd = new Date().getDay();
e_year = new Date().getFullYear();
e_month = new Date().getMonth();
e_date = new Date().getDate() + val.pweekday - e_wd;
differ = val.pweekday - e_wd;
// 실질적인 프로그램 리스트 만들기
program_list.push([val.pname, e_year, e_month, e_date, val.start_hour, val.start_min, e_year, e_month, e_date, val.start_hour+2, val.start_min]);
console.log(program_list);
});
}
callback();
});
}
temp(function()
{
res.render("timetable", {pl: JSON.stringify(program_list)});
});
}
// 로그인 중이 아니라면
else res.redirect("/");
});
}
......
......@@ -2,38 +2,39 @@
<div id="wrapper">
<div id="myScheduler"></div>
</div>
<script>
setTimeout(() =>
YUI().use('aui-scheduler',
function(Y)
{
YUI().use('aui-scheduler',
function(Y)
{
// code goes here
// code goes here
var temp = <%-pl %>;
//console.log(<%- pl %>);
var events = [];
var events =
[
temp.forEach(val =>
{
events.push(
{
content: '<%- pl[0].content%>',
endDate: new Date(2018, 11, 9, 5, 30),
startDate: new Date(2018, 11, 9, 1, 30),
content: val[0],
startDate: new Date(val[1], val[2], val[3], val[4], val[5]),
endDate: new Date(val[6], val[7], val[8], val[9], val[10]),
disabled: true
}
];
);
});
var weekView = new Y.SchedulerWeekView();
var weekView = new Y.SchedulerWeekView();
myScheduler = new Y.Scheduler(
{
boundingBox: '#myScheduler',
date: new Date(Date.now().getYear, Date.now().getMonth, Date.now().getDay),
items: events,
render: true,
views: [weekView]
}
);
myScheduler = new Y.Scheduler(
{
boundingBox: '#myScheduler',
date: new Date(Date.now().getYear, Date.now().getMonth, Date.now().getDay),
items: events,
render: true,
views: [weekView]
}
);
});
}, 1000);
</script>
\ No newline at end of file
});
</script>
......
......@@ -3,4 +3,5 @@
<a href="/main"><button>검색</button></a>
<a href="/mypage"><button>마이페이지</button></a>
<a href="/timetable"><button>나만의시간표</button></a>
<a href="/ttlist"><button>시간표수정</button></a>
</div>
\ No newline at end of file
......