강상위

DB - timetable connected

- 디비에서 정보를 가져와 나만의 시간표 표시완료
1 -var async = require('async');
2 -var webdriver = require('selenium-webdriver');
3 -var options = {desiredCapabilities: {browserName: 'chrome'}};
4 -var JASON = require('jason')
5 -const {Builder, By, Key, until} = require('selenium-webdriver');
6 -var iconv = require('iconv-lite')
7 -const fs = require('fs')
8 -
9 -datalist = []
10 -
11 -module.exports = {
12 - search_onairanddate: function(driver,string,callback) {
13 - let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=1&ie=utf8&query=" + string
14 - driver
15 - .get(url1).then(() => {
16 - driver
17 - .findElements(webdriver.By.className('brcs_detail'))
18 - .then(broad_info => {
19 - broad_info[0].findElement(webdriver.By.tagName('dl'))
20 - .then(more_data => {
21 - more_data.findElement(webdriver.By.tagName('dd'))
22 - .then(one_line => {
23 - one_line.findElement(webdriver.By.className("inline"))
24 - .then(isbroad => {
25 - isbroad.getText()
26 - .then(isbroad_string => {
27 - broadcasting=isbroad_string.substring(0,4)
28 - isbroad = isbroad_string.substring(18,21)
29 - br_date = isbroad_string.substring(23,24)
30 - br_date = br_date + "요일"
31 - br_time = isbroad_string.substring(26,34)
32 - datalist.push(broadcasting,isbroad,br_date,br_time)
33 -
34 - fs.writeFileSync("./log/"+string+"_br_isonair.txt", '\ufeff' + datalist, {encoding: 'utf8'});
35 - for(var i =0; i<100; ) {
36 -
37 - if() {
38 - i++
39 - }
40 - }
41 - callback()
42 - })
43 - })
44 - })
45 - })
46 - })
47 - })
48 - driver.findElement(webdriver.By.className('brcs_thumb'))
49 - .then(brcs_thumb => {
50 - brcs_thumb.findElements(webdriver.By.tagName('img'))
51 - .then( img => {
52 - img[0].getAttribute('src')
53 - .then(img_src => {
54 - datalist.push(img_src)
55 - })
56 - })
57 - })
58 - }
59 -}
...\ No newline at end of file ...\ No newline at end of file
1 -var async = require('async');
2 -var webdriver = require('selenium-webdriver');
3 -var options = {desiredCapabilities: {browserName: 'chrome'}};
4 -const {Builder, By, Key, until} = require('selenium-webdriver');
5 -const fs = require('fs')
6 -const screen = {
7 - width: 640,
8 - height: 480
9 -};
10 -var a=8000
11 -var img_src_list = []
12 -var text_list = []
13 -var testStartRunTime = 0;
14 -var testruntime = 0;
15 -var time = 0;
16 -module.exports = {
17 - search_broadcasting :function(driver,url,name,callback) {
18 - function testRunTimer() {
19 - var today = new Date(); // 현재시간 얻기
20 - var runTime = today.getTime(); // 밀리세컨드 ( 1970/01/01 부터 현재까지의 시간을 밀리세컨드로 나타냄 )
21 - var rtn = 0;
22 -
23 - if (testStartRunTime == 0) {
24 - testStartRunTime = runTime;
25 - } else {
26 - rtn = (runTime - testStartRunTime) / 1000;
27 - testStartRunTime = 0;
28 - }
29 - return rtn;
30 - }
31 - driver
32 - .get("http://"+url)
33 - .then(() => {
34 - driver.findElement(webdriver.By.id('pagination_76'))
35 - .then ( paginationBtn => {
36 - paginationBtn.findElements(webdriver.By.className('bt_next'))
37 - .then(Btn_next => {
38 - driver.findElement(webdriver.By.id('listUI_76'))
39 - .then(contentsUI => {
40 - clickandget(function() {
41 - Btn_next[0].click()
42 - setTimeout(() => {
43 - clickandget(function() {
44 - Btn_next[0].click()
45 - setTimeout(() => {
46 - clickandget(function() {
47 - Btn_next[0].click()
48 - setTimeout(() => {
49 - clickandget(function(){
50 - Btn_next[0].click()
51 - setTimeout(() => {
52 - clickandget(function(){
53 - fs.writeFileSync("./log/"+name+"_img_src_br.txt", '\ufeff' + img_src_list, {encoding: 'utf8'});
54 - fs.writeFileSync("./log/"+name+"_title_br.txt", '\ufeff' + text_list, {encoding: 'utf8'});
55 - setTimeout(() => {
56 - callback()
57 - }, 500);
58 - })
59 - }, testruntime*1000+800);
60 - })
61 - }, testruntime*1000+800);
62 -
63 - },testruntime*1000+800)
64 - }, testruntime*1000+800);
65 - })
66 - }, testruntime*1000+800);
67 - })
68 - function clickandget(_callback) {
69 - testRunTimer()
70 - Btn_next[0].isDisplayed().then(function(state) {
71 - if(state) {
72 - contentsUI.findElements(webdriver.By.tagName('li'))
73 - .then(elems => {
74 - elems.forEach(elem => {
75 - elem.findElements(webdriver.By.tagName('img'))
76 - .then(img => {
77 - img[0].getAttribute('src')
78 - .then(img_src => {
79 - elem.findElements(webdriver.By.className('tit'))
80 - .then (titles => {
81 - titles.forEach(title => {
82 - title.getText()
83 - .then(text => {
84 - text_list.push(text)
85 - img_src_list.push(img_src)
86 - if(text_list.length % 5 == 0) {
87 - var testruntime = testRunTimer();
88 - time = time+testruntime*1000
89 - _callback()
90 - }
91 - })
92 - })
93 - })
94 - })
95 - })
96 - })
97 - })
98 - }
99 - else {
100 - fs.writeFileSync("./log/"+name+"_img_src_br.txt", '\ufeff' + img_src_list, {encoding: 'utf8'});
101 - fs.writeFileSync("./log/"+name+"_title_br.txt", '\ufeff' + text_list, {encoding: 'utf8'});
102 - setTimeout(() => {
103 - callback()
104 - }, 500);
105 - }
106 - },function(err) {
107 - fs.writeFileSync("./log/"+name+"_img_src_br.txt", '\ufeff' + img_src_list, {encoding: 'utf8'});
108 - fs.writeFileSync("./log/"+name+"_title_br.txt", '\ufeff' + text_list, {encoding: 'utf8'});
109 - setTimeout(() => {
110 - callback()
111 - }, 500);
112 - })
113 - }
114 - })
115 - })
116 - })
117 - })
118 - function sleep (time) {
119 - return new Promise((resolve) => setTimeout(resolve, time));
120 - }
121 - }
122 -}
123 -
124 -//var driver = new webdriver.Builder()
125 -//.forBrowser('chrome')
126 -//.withCapabilities(webdriver.Capabilities.chrome())
127 -//.build();
128 -
129 -//search_broadcasting(driver,"people.search.naver.com/search.naver?where=nexearch&sm=tab_ppn&query=유재석&os=94702&ie=utf8&key=PeopleService","유재석",function() {
130 -// console.log("B")
131 -//})
...\ No newline at end of file ...\ No newline at end of file
1 -var async = require('async');
2 -var webdriver = require('selenium-webdriver');
3 -var chrome = require('selenium-webdriver/chrome')
4 -var Options = new chrome.Options();
5 -Options.addArguments('headless')
6 -Options.addArguments('disable-gpu')
7 -const fs = require('fs')
8 -var check = 0
9 -var testStartRunTime = 0;
10 -var testruntime = 0;
11 -
12 -const {Builder, By, Key, until} = require('selenium-webdriver');
13 -
14 -var next_link_list = []
15 -var src_list = []
16 -var text_list = []
17 -var return_list = []
18 -
19 -module.exports = {
20 - first_search :function (driver,string,callback) {
21 -
22 - function testRunTimer() {
23 - var today = new Date(); // 현재시간 얻기
24 - var runTime = today.getTime(); // 밀리세컨드 ( 1970/01/01 부터 현재까지의 시간을 밀리세컨드로 나타냄 )
25 - var rtn = 0;
26 -
27 - if (testStartRunTime == 0) {
28 - testStartRunTime = runTime;
29 - } else {
30 - rtn = (runTime - testStartRunTime) / 1000;
31 - testStartRunTime = 0;
32 - }
33 - return rtn;
34 - }
35 - let url1 = "https://people.search.naver.com/search.naver?sm=tab_hty&where=nexearch&query="+string+"&ie=utf8&x=0&y=0"
36 - driver
37 - .get(url1).then(() => {
38 - testRunTimer()
39 - driver
40 - .findElements(webdriver.By.className('result_profile'))
41 - .then(profiles => {
42 - profiles.forEach(profile => {
43 - profile.findElements(webdriver.By.className('thmb'))
44 - .then(links=> {
45 - links.forEach(link => {
46 - link.getAttribute('href')
47 - .then(next_link => {
48 - profile.findElements(webdriver.By.className('thmb_img'))
49 - .then((imgs) => {
50 - imgs.forEach(img => {
51 - img.getAttribute('src')
52 - .then(src => {
53 - next_link_list.push(next_link)
54 - src_list.push(src)
55 - //text_list.push(text)
56 - testruntime += testRunTimer()
57 - setTimeout(function() {
58 - check++;
59 - if(check==1) {
60 - //return_list.push(text_list)
61 - setTimeout(function() {
62 - fs.writeFileSync("./log/"+string+"_next_link.txt", '\ufeff' + next_link_list, {encoding: 'utf8'});
63 - fs.writeFileSync("./log/"+string+"_img_src.txt", '\ufeff' + src_list, {encoding: 'utf8'});
64 - callback()
65 - },500)
66 - }
67 - },testruntime*1000+1000)
68 - })
69 - })
70 - })
71 - })
72 - })
73 - })
74 - })
75 - })
76 - })
77 - }
78 -}
...\ No newline at end of file ...\ No newline at end of file
1 -var webdriver = require('selenium-webdriver');
2 -const {Builder, By, Key, until} = require('selenium-webdriver');
3 -const fs = require('fs')
4 -
5 - var arr = []
6 - var result_arr = []
7 - var temp = []
8 - var i=0
9 - var check = 0
10 -module.exports = {
11 - search_broadcasting_time : function(driver,broadcast,day,findtitle, callback) {
12 - let url1 = "https://search.naver.com/search.naver?sm=top_hty&fbm=0&ie=utf8&query="+broadcast+"+"+day+"+편성표"
13 - driver
14 - .get(url1).then(() => {
15 - driver
16 - .findElements(webdriver.By.className('cont_inner type_day _scheduleArea'))
17 - .then(contentsearch_section=> {
18 - contentsearch_section[0].findElements(webdriver.By.tagName('tbody'))
19 - .then(tbody => {
20 - tbody[0].findElements(webdriver.By.tagName('tr'))
21 - .then(trs => {
22 - trs.forEach(tr => {
23 - tr.getText()
24 - .then(content => {
25 - if(content.indexOf(findtitle) != -1) {
26 - arr = content.toString().split('\n')
27 - str(function() {
28 - i++
29 - if(i==2) {
30 - fs.writeFileSync("./log/"+findtitle+"_time_detail.txt", '\ufeff' + result_arr, {encoding: 'utf8'});
31 - callback()
32 - }
33 - })
34 - function str(_callback) {
35 - temp[i+0] = arr[0] + " " + arr[1].substr(0,2) + "분"
36 - temp[i+1] = arr[1].substr(3)
37 - result_arr.push(temp[i+0],temp[i+1])
38 - if(arr.length == 3) {
39 - temp[i+2] = arr[0] + " " + arr[2].substr(0,2) + "분"
40 - temp[i+3] = arr[2].substr(3)
41 - result_arr.push(temp[i+2],temp[i+3])
42 - i++
43 - }
44 - setTimeout(() => {
45 - _callback()
46 - }, 500);
47 -
48 - }
49 - }
50 - })
51 - })
52 - })
53 - })
54 - })
55 - })
56 - }
57 -}
...\ No newline at end of file ...\ No newline at end of file
1 -SBS ,방영중,일요일,오후 04:50
...\ No newline at end of file ...\ No newline at end of file
1 -16시 50분,런닝맨 1부,17시 40분,런닝맨 2부
...\ No newline at end of file ...\ No newline at end of file
1 -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 ...\ No newline at end of file
1 -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 ...\ No newline at end of file
1 -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 ...\ No newline at end of file
1 -무한도전,요즘애들,미추리 8-1000,해피투게더 4,유 퀴즈 온 더 블럭,범인은 바로 너!,투유 프로젝트 - 슈가맨 2,투유 프로젝트 - 슈가맨,동상이몽, 괜찮아 괜찮아!,나는 남자다,런닝맨,패밀리가 떴다 1,해피투게더 3,옛날 TV,하자 GO!,X맨 일요일이 좋다,강력추천 토요일,해피투게더 2,느낌표,공감토크쇼 놀러와
...\ No newline at end of file ...\ No newline at end of file
1 -var async = require('async');
2 -var webdriver = require('selenium-webdriver');
3 -//var options = {desiredCapabilities: {browserName: 'chrome'}};
4 -var chrome = require('selenium-webdriver/chrome')
5 -var Options = new chrome.Options();
6 -Options.addArguments('headless')
7 -Options.addArguments('disable-gpu')
8 -var test1 = require('./crawling_samename')
9 -const fs = require('fs')
10 -const test2 = require('./crawling_broadcasting')
11 -const test3 = require('./crawling_br_onair_date')
12 -const test4 = require('./crawling_time')
13 -var util = require('util')
14 -var EventEmitter = require('events').EventEmitter;
15 -
16 -var next_link_Array = []
17 -var img_src_Array = []
18 -
19 -const {Builder, By, Key, until} = require('selenium-webdriver');
20 -var driver = new webdriver.Builder()
21 -.forBrowser('chrome')
22 -.withCapabilities(webdriver.Capabilities.chrome())
23 -.setChromeOptions(Options)
24 -.build();
25 -
26 -var driver_1 = new webdriver.Builder()
27 -.forBrowser('chrome')
28 -.withCapabilities(webdriver.Capabilities.chrome())
29 -.setChromeOptions(Options)
30 -.build()
31 -var driver_2 = new webdriver.Builder()
32 -.forBrowser('chrome')
33 -.withCapabilities(webdriver.Capabilities.chrome())
34 -.setChromeOptions(Options)
35 -.build();
36 -
37 -var driver_3 = new webdriver.Builder()
38 -.forBrowser('chrome')
39 -.withCapabilities(webdriver.Capabilities.chrome())
40 -.setChromeOptions(Options)
41 -.build();
42 -var First_Search = function(name) {
43 - var self=this;
44 - this.on('input', function() {
45 -
46 - if(fs.existsSync("./log/"+name+"_next_link.txt")) {
47 - const next_link = fs.readFileSync("./log/"+name+"_next_link.txt");
48 - const img_src = fs.readFileSync("./log/"+name+"_img_src.txt");
49 - next_link_Array = next_link.toString().split(',');
50 - img_src_Array = img_src.toString().split(',');
51 - driver.quit()
52 - console.log(next_link_Array)
53 - console.log(img_src_Array)
54 -
55 - setTimeout(function() {
56 - br_search.emit('click')
57 - },1000)
58 -
59 - }
60 - else {
61 - test1.first_search(driver,name,function() {
62 - const next_link = fs.readFileSync("./log/"+name+"_next_link.txt");
63 - const img_src = fs.readFileSync("./log/"+name+"_img_src.txt");
64 - next_link_Array = next_link.toString().split(',');
65 - img_src_Array = img_src.toString().split(',');
66 - br_search = new broadcasting_search(next_link_Array,"유재석",0)
67 - console.log(next_link_Array)
68 - console.log(img_src_Array)
69 - driver.quit()
70 - setTimeout(function() {
71 - br_search.emit('click')
72 - },1000)
73 - })
74 - }
75 - })
76 -}
77 -util.inherits(First_Search,EventEmitter);
78 -first_search1 = new First_Search("유재석")
79 -first_search1.emit('input')
80 -
81 -var img_src_br_list = []
82 -var title_list = []
83 -var broadcasting_search = function(next_link,name,num) {
84 - var self=this;
85 - this.on('click', function() {
86 - if(fs.existsSync("./log/"+name+"_img_src_br.txt")) {
87 - const img_src_br = fs.readFileSync("./log/"+name+"_img_src_br.txt");
88 - img_src_br_list = img_src_br.toString().split(',');
89 - const title_br = fs.readFileSync("./log/"+name+"_title_br.txt");
90 - title_list = title_br.toString().split(',');
91 - driver_1.quit()
92 - console.log(img_src_br_list)
93 - console.log(title_list)
94 - is_onair.emit('click_1')
95 - }
96 - else {
97 - test2.search_broadcasting(driver_1,next_link[num].substr(9),name,function() {
98 - const img_src_br = fs.readFileSync("./log/"+name+"_img_src_br.txt");
99 - img_src_br_list = img_src_br.toString().split(',');
100 - const title_br = fs.readFileSync("./log/"+name+"_title_br.txt");
101 - title_list = title_br.toString().split(',');
102 -
103 - driver_1.quit()
104 - console.log(img_src_br_list)
105 - console.log(title_list)
106 - is_onair.emit('click_1')
107 - })
108 - }
109 - })
110 -}
111 -util.inherits(broadcasting_search,EventEmitter);
112 -br_search = new broadcasting_search(next_link_Array,"유재석",0)
113 -
114 -br_datalist = []
115 -var isonair = function(num) {
116 - var self = this
117 - this.on('click_1',function() {
118 - if(fs.existsSync("./log/"+title_list[num]+"_br_isonair.txt")) {
119 - const img_src_br = fs.readFileSync("./log/"+title_list[num]+"_br_isonair.txt");
120 - br_datalist = img_src_br.toString().split(',');
121 - br_datalist[0] = br_datalist[0].trim()
122 - console.log(br_datalist)
123 - Search_detail_time.emit('click_2')
124 - }
125 -
126 - else {
127 - test3.search_onairanddate(driver_2,title_list[num],function() {
128 - const img_src_br = fs.readFileSync("./log/"+title_list[num]+"_br_isonair.txt");
129 - br_datalist = img_src_br.toString().split(',');
130 - br_datalist[0] = br_datalist[0].trim()
131 - console.log(br_datalist)
132 - Search_detail_time.emit('click_2')
133 - })
134 - }
135 - })
136 -}
137 -
138 -util.inherits(isonair,EventEmitter);
139 -is_onair = new isonair(11)
140 -
141 -var detail_time_list = []
142 -var search_detail_time = function(num) {
143 - var self = this;
144 - this.on('click_2',function() {
145 - if(br_datalist[1] == "방영중") {
146 - if(fs.existsSync("./log/"+title_list[num]+"_time_detail.txt")) {
147 - const detail = fs.readFileSync("./log/"+title_list[num]+"_time_detail.txt");
148 - detail_time_list = detail.toString().split(',');
149 - console.log(detail_time_list)
150 - }
151 - else {
152 - test4.search_broadcasting_time(driver_3,br_datalist[0],br_datalist[2],title_list[num],function(){
153 - const detail = fs.readFileSync("./log/"+title_list[num]+"_time_detail.txt");
154 - detail_time_list = detail.toString().split(',');
155 - console.log(detail_time_list)
156 - })
157 -
158 - }
159 - }
160 - })
161 -}
162 -
163 -util.inherits(search_detail_time,EventEmitter);
164 -Search_detail_time = new search_detail_time(11);
This diff is collapsed. Click to expand it.
1 -{
2 - "name": "cheerio",
3 - "version": "1.0.0",
4 - "description": "",
5 - "main": "practice.js",
6 - "scripts": {
7 - "test": "echo \"Error: no test specified\" && exit 1"
8 - },
9 - "author": "",
10 - "license": "ISC",
11 - "dependencies": {
12 - "async": "^2.6.1",
13 - "events": "^3.0.0",
14 - "fs": "0.0.1-security",
15 - "iconv-lite": "^0.4.24",
16 - "jason": "^2.0.0",
17 - "json": "^9.0.6",
18 - "selenium-webdriver": "^3.6.0",
19 - "util": "^0.11.1",
20 - "webdriverio": "^4.14.0"
21 - }
22 -}
1 -var async = require('async');
2 -var webdriver = require('selenium-webdriver');
3 -//var options = {desiredCapabilities: {browserName: 'chrome'}};
4 -var chrome = require('selenium-webdriver/chrome')
5 -var Options = new chrome.Options();
6 -Options.addArguments('headless')
7 -Options.addArguments('disable-gpu')
8 -var test1 = require('./crawling_samename')
9 -const fs = require('fs')
10 -var util = require('util')
11 -var EventEmitter = require('events').EventEmitter;
12 -
13 -var next_link_Array = []
14 -var img_src_Array = []
15 -
16 -const {Builder, By, Key, until} = require('selenium-webdriver');
17 -var driver = new webdriver.Builder()
18 -.forBrowser('chrome')
19 -.withCapabilities(webdriver.Capabilities.chrome())
20 -.setChromeOptions(Options)
21 -.build();
22 -
23 -var result_arr = []
24 -module.exports = {
25 - First_Search :function(name) {
26 - return new Promise(function(resolve,reject) {
27 - if(fs.existsSync("./log/"+name+"_next_link.txt")) {
28 - const next_link = fs.readFileSync("./log/"+name+"_next_link.txt");
29 - const img_src = fs.readFileSync("./log/"+name+"_img_src.txt");
30 - next_link_Array = next_link.toString().split(',');
31 - img_src_Array = img_src.toString().split(',');
32 - driver.quit()
33 - result_arr.push(next_link_Array)
34 - result_arr.push(img_src_Array)
35 - console.log(next_link_Array)
36 - console.log(img_src_Array)
37 - console.log(result_arr)
38 -
39 - return result_arr
40 - }
41 - else {
42 - test1.first_search(driver,name,function() {
43 - const next_link = fs.readFileSync("./log/"+name+"_next_link.txt");
44 - const img_src = fs.readFileSync("./log/"+name+"_img_src.txt");
45 - next_link_Array = next_link.toString().split(',');
46 - img_src_Array = img_src.toString().split(',');
47 - br_search = new broadcasting_search(next_link_Array,"유재석",0)
48 - result_arr.push(next_link_Array)
49 - result_arr.push(img_src_Array)
50 - console.log(next_link_Array)
51 - console.log(img_src_Array)
52 - driver.quit()
53 - return result_arr
54 - })
55 - }
56 -
57 - })
58 -
59 - }
60 -//util.inherits(First_Search,EventEmitter);
61 -//first_search1 = new First_Search("유재석")
62 -//first_search1.emit('input')
63 -}
64 -
65 -
66 -
67 -//다른 파일에서 호출하는 방법
68 -//var a=require("./sane_name_search")
69 -
70 -//var arr = []
71 -
72 -//a.First_Search("(검색어 입력)").then(aa => {
73 -// arr=a
74 -// console.log(arr)
75 -//})
76 -
...@@ -6,7 +6,7 @@ var mongoose = require('mongoose'); ...@@ -6,7 +6,7 @@ var mongoose = require('mongoose');
6 var passport = require('passport'); 6 var passport = require('passport');
7 7
8 //DB연결 8 //DB연결
9 -mongoose.connect('mongodb://username:pwd@host/dbname'); 9 +mongoose.connect('mongodb://00:00@000/000');
10 mongoose.Promise = global.Promise; 10 mongoose.Promise = global.Promise;
11 var db = mongoose.connection; 11 var db = mongoose.connection;
12 12
...@@ -24,6 +24,10 @@ db.once('open', function() ...@@ -24,6 +24,10 @@ db.once('open', function()
24 24
25 // DB모델정의 25 // DB모델정의
26 var Users = require('./models/users'); 26 var Users = require('./models/users');
27 +var Timetables = require('./models/timetables');
28 +
29 +// Client-Browser와의 공유
30 +//app.use("/static", express.static("public"));
27 31
28 // session 32 // session
29 app.use(session({ 33 app.use(session({
...@@ -48,7 +52,7 @@ app.use(bodyParser.json()); ...@@ -48,7 +52,7 @@ app.use(bodyParser.json());
48 app.use(bodyParser.urlencoded({extended: true})); 52 app.use(bodyParser.urlencoded({extended: true}));
49 53
50 // router import 54 // router import
51 -var router = require('./routing')(app, Users); 55 +var router = require('./routing')(app, Users, Timetables);
52 56
53 var server = app.listen(23023, function() 57 var server = app.listen(23023, function()
54 { 58 {
......
This file is too large to display.
1 +var mongoose = require('mongoose');
2 +
3 +var timetableSchema = mongoose.Schema
4 +(
5 + {
6 + user_id: String,
7 + pname: String,
8 + pweekday: Number,
9 + start_hour: Number,
10 + start_min: Number
11 + }
12 +);
13 +
14 +module.exports = mongoose.model('timetable',timetableSchema);
15 +
This diff is collapsed. Click to expand it.
...@@ -13,17 +13,25 @@ ...@@ -13,17 +13,25 @@
13 "author": "", 13 "author": "",
14 "license": "ISC", 14 "license": "ISC",
15 "dependencies": { 15 "dependencies": {
16 + "async": "^2.6.1",
16 "bcrypt-nodejs": "0.0.3", 17 "bcrypt-nodejs": "0.0.3",
17 "body-parser": "^1.18.3", 18 "body-parser": "^1.18.3",
18 "cheerio": "^1.0.0-rc.2", 19 "cheerio": "^1.0.0-rc.2",
19 "ejs": "^2.6.1", 20 "ejs": "^2.6.1",
21 + "events": "^3.0.0",
20 "express": "^4.16.4", 22 "express": "^4.16.4",
21 "express-session": "^1.15.6", 23 "express-session": "^1.15.6",
24 + "fs": "0.0.1-security",
22 "iconv": "^2.3.1", 25 "iconv": "^2.3.1",
26 + "iconv-lite": "^0.4.24",
27 + "jason": "^2.0.0",
28 + "json": "^9.0.6",
23 "mongoose": "^5.3.14", 29 "mongoose": "^5.3.14",
24 "passport": "^0.4.0", 30 "passport": "^0.4.0",
25 "passport-local": "^1.0.0", 31 "passport-local": "^1.0.0",
26 "request": "^2.88.0", 32 "request": "^2.88.0",
27 - "selenium-webdriver": "^4.0.0-alpha.1" 33 + "selenium-webdriver": "^4.0.0-alpha.1",
34 + "util": "^0.11.1",
35 + "webdriverio": "^4.14.1"
28 } 36 }
29 } 37 }
......
1 +{
2 + hi: "hi"
3 +}
...\ No newline at end of file ...\ No newline at end of file
1 +(function(exports)
2 +{
3 + var item;
4 + exports.sharingIn = function(temp)
5 + {
6 + item = temp;
7 + return item;
8 + };
9 + exports.sharingOut = function()
10 + {
11 + return item;
12 + };
13 +})(typeof exports === "undefined" ? this["share"]={}: exports);
...\ No newline at end of file ...\ No newline at end of file
1 -module.exports = function(app, Users) 1 +module.exports = function(app, Users, Timetables)
2 { 2 {
3 var passport = require('passport'); 3 var passport = require('passport');
4 4
...@@ -122,22 +122,89 @@ module.exports = function(app, Users) ...@@ -122,22 +122,89 @@ module.exports = function(app, Users)
122 res.render("programs", {programs: program_list}); 122 res.render("programs", {programs: program_list});
123 }); 123 });
124 124
125 - // 나만의 시간표 125 + // 나만의 시간표에 추가 - 로그인 필수
126 + app.get("/addtt", function(req, res)
127 + {
128 + if(req.isAuthenticated())
129 + {
130 + // 유저가 선택한 프로그램 정보 입력
131 + var program = new Timetables();
132 + program.user_id = req.user;
133 + program.pname = "짠내투어";
134 + program.pweekday = 6;
135 + program.start_hour = 20;
136 + program.start_min = 20;
137 +
138 + // DB저장
139 + program.save(function(err)
140 + {
141 + if(err)
142 + {
143 + console.log(err);
144 + res.send("Error!")
145 + }
146 + else
147 + {
148 + console.log("TT Add Success");
149 + res.redirect('/timetable');
150 + }
151 + });
152 + }
153 + // 로그인 중이 아니라면
154 + else res.redirect("/");
155 + });
156 +
157 +
158 +
159 +
160 + // 나만의 시간표 - 로그인 필수
126 app.get("/timetable", function(req, res) 161 app.get("/timetable", function(req, res)
127 { 162 {
128 163
129 - var program_list = 164 + if(req.isAuthenticated())
130 - [ 165 + {
166 + // 유저별 프로그램 리스트 만들기
167 + var program_list = [];
168 +
169 + // 디비에서 유저아이디에 맞는 programs 가져오기
170 + // 디비정보 가져오는 것은 동기로 설정
171 + function temp(callback)
172 + {
173 + Timetables.find({user_id: req.user},function(err, programs)
131 { 174 {
132 - content: '런닝맨', 175 + if(err)
133 - endDate: new Date(2018, 11, 9, 5, 45), 176 + {
134 - startDate: new Date(2018, 11, 9, 1, 30), 177 + console.log(err);
135 - disabled: true 178 + res.send("Error!");
179 + }
180 + else
181 + {
182 + programs.forEach(val =>
183 + {
184 + // 시간조정 로직
185 + e_wd = new Date().getDay();
186 + e_year = new Date().getFullYear();
187 + e_month = new Date().getMonth();
188 + e_date = new Date().getDate() + val.pweekday - e_wd;
189 + differ = val.pweekday - e_wd;
190 +
191 + // 실질적인 프로그램 리스트 만들기
192 + 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]);
193 + console.log(program_list);
194 + });
195 + }
196 + callback();
197 + });
136 } 198 }
137 - ];
138 199
200 + temp(function()
201 + {
139 res.render("timetable", {pl: JSON.stringify(program_list)}); 202 res.render("timetable", {pl: JSON.stringify(program_list)});
140 }); 203 });
204 + }
205 + // 로그인 중이 아니라면
206 + else res.redirect("/");
207 + });
141 208
142 } 209 }
143 210
......
...@@ -2,25 +2,27 @@ ...@@ -2,25 +2,27 @@
2 <div id="wrapper"> 2 <div id="wrapper">
3 <div id="myScheduler"></div> 3 <div id="myScheduler"></div>
4 </div> 4 </div>
5 +
5 <script> 6 <script>
6 - setTimeout(() =>
7 - {
8 YUI().use('aui-scheduler', 7 YUI().use('aui-scheduler',
9 function(Y) 8 function(Y)
10 { 9 {
11 // code goes here 10 // code goes here
11 + var temp = <%-pl %>;
12 12
13 - //console.log(<%- pl %>); 13 + var events = [];
14 14
15 - var events = 15 + temp.forEach(val =>
16 - [ 16 + {
17 + events.push(
17 { 18 {
18 - content: '<%- pl[0].content%>', 19 + content: val[0],
19 - endDate: new Date(2018, 11, 9, 5, 30), 20 + startDate: new Date(val[1], val[2], val[3], val[4], val[5]),
20 - startDate: new Date(2018, 11, 9, 1, 30), 21 + endDate: new Date(val[6], val[7], val[8], val[9], val[10]),
21 disabled: true 22 disabled: true
22 } 23 }
23 - ]; 24 + );
25 + });
24 26
25 var weekView = new Y.SchedulerWeekView(); 27 var weekView = new Y.SchedulerWeekView();
26 28
...@@ -35,5 +37,4 @@ ...@@ -35,5 +37,4 @@
35 ); 37 );
36 38
37 }); 39 });
38 - }, 1000);
39 </script> 40 </script>
......
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
3 <a href="/main"><button>검색</button></a> 3 <a href="/main"><button>검색</button></a>
4 <a href="/mypage"><button>마이페이지</button></a> 4 <a href="/mypage"><button>마이페이지</button></a>
5 <a href="/timetable"><button>나만의시간표</button></a> 5 <a href="/timetable"><button>나만의시간표</button></a>
6 + <a href="/ttlist"><button>시간표수정</button></a>
6 </div> 7 </div>
...\ No newline at end of file ...\ No newline at end of file
......