last_detail.js 3.53 KB
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')
const fs = require('fs')
const test3 = require('./crawling_br_onair_date')
const test4 = require('./crawling_time')
var util = require('util')
var EventEmitter = require('events').EventEmitter;

br_datalist = []

var driver_2 = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome()).setChromeOptions(Options)
.build();
var returnfunction = function() {
    var self= this
    this.on('ok1',function() {
        return br_datalist
    })
}
var driver_3 = new webdriver.Builder()
.forBrowser('chrome')
.withCapabilities(webdriver.Capabilities.chrome()).setChromeOptions(Options)
.build();
//module.exports = {
    var search_detail_time = function  (name) {
        var self = this
        this.on('ok',function() {
            if(br_datalist[1] == "방영중") {
                if(fs.existsSync("./log/"+name+"_time_detail.txt")) {
                    const detail = fs.readFileSync("./log/"+name+"_time_detail.txt");
                    detail_time_list = detail.toString().split(',');
                    br_datalist.push(detail_time_list[0])
                    br_datalist.push(detail_time_list[1])
                    br_datalist.push(detail_time_list[2])
                }
                else {
                    test4.search_broadcasting_time(driver_3,br_datalist[0],br_datalist[3],name,function(){
                            const detail = fs.readFileSync("./log/"+name+"_time_detail.txt");
                            detail_time_list = detail.toString().split(',');
                            br_datalist.push(detail_time_list[0])
                            br_datalist.push(detail_time_list[1])
                            br_datalist.push(detail_time_list[2])
                    })
                }
            }
        })
        
    }
//}

util.inherits(returnfunction,EventEmitter);
util.inherits(search_detail_time,EventEmitter);
return_ = new returnfunction();


var detail_time_list = []

//isonair('https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=%EB%9F%B0%EB%8B%9D%EB%A7%A8&oquery=%EB%9F%B0%EB%8B%9D%EB%A7%A8&tqi=UtvQ%2FlpySDVssa%2BpmFNssssstfG-043752',"런닝맨")
module.exports = {
     isonair : function (url,string) {
        search_detail = new search_detail_time(string)
        
        return new Promise(function(resolve,reject) {
            if(fs.existsSync("./log/"+string+"_br_isonair.txt")) {
                const img_src_br = fs.readFileSync("./log/"+string+"_br_isonair.txt");
                br_datalist = img_src_br.toString().split(',');
                search_detail.emit('ok')
                setTimeout(() => {
                    resolve(br_datalist)
                }, 5000);
                
            }
      
            else {
                test3.search_onairanddate(driver_2,url,string,function() {
                    const img_src_br = fs.readFileSync("./log/"+string+"_br_isonair.txt");
                    br_datalist = img_src_br.toString().split(',');
                    search_detail.emit('ok')
                    setTimeout(() => {
                        resolve(br_datalist)
                    }, 5000);
                    
                })
            }
        })
    }
}