최재은

Changed DB : Mysql & Add Database File

PORT=4500
MONGO_URI=mongodb://localhost/facebookbot
\ No newline at end of file
This diff could not be displayed because it is too large.
{"_id":{"$oid":"5cf0da0c7c7624ccbced2825"},"lecturename":"전공 기초","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2826"},"lecturename":"미분적분학","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2827"},"lecturename":"선형대수","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2828"},"lecturename":"확률 및 랜덤변수","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2829"},"lecturename":"미분방정식","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced282a"},"lecturename":"이산구조","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced282b"},"lecturename":"전공 필수","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced282c"},"lecturename":"웹/파이선프로그래밍","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced282d"},"lecturename":"객체지향프로그래밍","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced282e"},"lecturename":"논리회로","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced282f"},"lecturename":"컴퓨터구조","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2830"},"lecturename":"자료구조","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2831"},"lecturename":"운영체제","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2832"},"lecturename":"컴퓨터네트워크","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2833"},"lecturename":"소프트웨어공학","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2834"},"lecturename":"알고리즘분석","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2835"},"lecturename":"데이터베이스","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2836"},"lecturename":"오픈소스SW개발","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2837"},"lecturename":"IT기술영어 1","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2838"},"lecturename":"IT기술영어 2","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2839"},"lecturename":"IT기술영어 3","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced283a"},"lecturename":"캡스톤디자인 1","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced283b"},"lecturename":"캡스톤디자인 2","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced283c"},"lecturename":"졸업논문","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced283d"},"lecturename":"전공 선택","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced283e"},"lecturename":"문제해결","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced283f"},"lecturename":"형식언어 및컴파일러","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2840"},"lecturename":"파일처리","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2841"},"lecturename":"멀티미디어시스템","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2842"},"lecturename":"시스템분석 및 설계","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2843"},"lecturename":"프로그래밍언어구조론","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2844"},"lecturename":"JAVA프로그래밍","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2845"},"lecturename":"SW스타트업비즈니스","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2846"},"lecturename":"SW스타트업프로젝트","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2847"},"lecturename":"최신기술프로젝트 1","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2848"},"lecturename":"최신기술프로젝트 2","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2849"},"lecturename":"최신기술콜로키움 1","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced284a"},"lecturename":"최신기술콜로키움 2","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced284b"},"lecturename":"단기현장실습","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced284c"},"lecturename":"장기현장실습","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced284d"},"lecturename":"연구연수활동 1","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced284e"},"lecturename":"연구연수활동 2","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced284f"},"lecturename":"독립심화학습1 (컴퓨터공학과)","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2850"},"lecturename":"독립심화학습2 (컴퓨터공학과)","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2851"},"lecturename":"인공지능","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2852"},"lecturename":"머신러닝","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2853"},"lecturename":"빅데이터프로그래밍","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2854"},"lecturename":"클라우드컴퓨팅","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2855"},"lecturename":"데이터센터프로그래밍","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2856"},"lecturename":"네트워크분석및 설계","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2857"},"lecturename":"인터넷프로토콜및 프로그래밍","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2858"},"lecturename":"정보보호","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2859"},"lecturename":"모바일프로그래밍","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced285a"},"lecturename":"웹서비스프로그래밍","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced285b"},"lecturename":"리눅스시스템프로그래밍","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced285c"},"lecturename":"IoT디지털시스템","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced285d"},"lecturename":"IoT소프트웨어","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced285e"},"lecturename":"로봇소프트웨어","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced285f"},"lecturename":"영상처리","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2860"},"lecturename":"컴퓨터그래픽스","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2861"},"lecturename":"멀티미디어처리","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2862"},"lecturename":"인간-컴퓨터상호작용","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2863"},"lecturename":"UI/UX프로그래밍","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2864"},"lecturename":"컴퓨터비젼","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2865"},"lecturename":"디자인적사고","__v":{"$numberInt":"0"}}
{"_id":{"$oid":"5cf0da0c7c7624ccbced2866"},"lecturename":"신호와시스템","__v":{"$numberInt":"0"}}
const puppeteer = require('puppeteer');
const request = require('request');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://ce.khu.ac.kr/index.php?hCode=UNIVERSITY_02_01_01');
await page.screenshot({path: 'test.png'});
var lecture = [];
lecture = await page.evaluate(() => {
const anchors = Array.from(document.querySelectorAll('#conTD > td > div > table > tbody > tr > td:nth-child(2)'));
return anchors.map(anchor => anchor.textContent);
})
lecture.push("디자인적사고")
lecture.push("신호와시스템")
console.log(lecture)
var opts
var posturl = "mongodb://localhost/facebookbot" + "/lectures"
for(var i=0; i<lecture.length; i++){
console.log(lecture[i])
request.post('http://127.0.0.1:4500/lectures', {
form: {
lecturename: lecture[i]
}
})
}
await browser.close();
})();
\ No newline at end of file
const puppeteer = require('puppeteer');
const request = require('request');
const mysql = require('mysql');
const util = require('util');
var emojiStrip = require('emoji-strip')
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : '',
port : 3306,
database : 'facebookbot'
})
const query = util.promisify(connection.query).bind(connection);
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://ce.khu.ac.kr/index.php?hCode=UNIVERSITY_02_01_01');
await page.screenshot({path: 'test.png'});
var lecture = [];
lecture = await page.evaluate(() => {
const anchors = Array.from(document.querySelectorAll('#conTD > td > div > table > tbody > tr > td:nth-child(2)'));
return anchors.map(anchor => anchor.textContent);
})
lecture.push("디자인적사고")
lecture.push("신호와시스템")
for(var i=0; i<lecture.length; i++){
console.log(lecture[i])
await query('INSERT INTO lectures (lecturename) VALUES (?)',lecture[i])
}
const browser = await puppeteer.launch();
const page = await browser.newPage();
const et_id = "";
const et_pw = "";
const lecture = "";
await page.goto('https://everytime.kr/login');
await page.evaluate((id, pw) => {
document.querySelector("input[name=userid]").value = id;
......@@ -13,10 +47,22 @@ const puppeteer = require('puppeteer');
await console.log("로그인 정보 삽입 완료")
await page.click('#container > form > p.submit > input');
await page.waitFor(1000);
var lecary = [];
const rows = await query('SELECT * FROM lectures');
for(var i =0; i<rows.length; i++){
lecary.push(rows[i].lecturename)
}
console.log(lecary)
for(var i=0 ; i< lecary.length; i++){
var templecture = lecary[i];
console.log(lecture);
await page.goto('https://everytime.kr/lecture');
await page.evaluate((lec) => {
document.querySelector("input[name=keyword]").value = lec;
}, lecture);
}, templecture);
await page.click('#container > form > input.submit');
await page.waitFor(1000);
......@@ -25,10 +71,9 @@ const puppeteer = require('puppeteer');
}, 'lecture');
console.log(tempclass)
for (var i in tempclass) {
console.log(tempclass[i]);
await page.goto(tempclass[i]);
for (var j = 0; j < tempclass.length; j++) {
console.log(tempclass[j]);
await page.goto(tempclass[j]);
await page.waitFor(1000);
await page.waitForSelector('#container > div.side.head > h2');
const lecturename = await page.evaluate(() => {
......@@ -53,12 +98,17 @@ const puppeteer = require('puppeteer');
return anchors4.map(anchor4 => anchor4.textContent);
});
}
//콘솔에 출력한다.
console.log(lecturename.join('\n'));
console.log(proname.join('\n'));
console.log(avg_rate.join('\n'));
console.log(review);
review = review.toString()
review = emojiStrip(review)
await query('INSERT INTO reviews (lecturename,proname,avg_rate,review) VALUES (?,?,?,?)',[lecturename,proname,avg_rate,review])
}
}
await browser.close();
connection.end();
})();
\ No newline at end of file
......
const mongoose = require('mongoose');
const LectureSchema = new mongoose.Schema({
lecturename: { type: String, required: true, unique: true }
});
// // Create new review document
LectureSchema.statics.create = function (payload) {
// this === Model
const review = new this(payload);
// return Promise
return review.save();
};
// Find All
LectureSchema.statics.findAll = function () {
// return promise
// V4부터 exec() 필요없음
return this.find({});
};
// Find One by lecturename
LectureSchema.statics.findOneBylecturename = function (lecturename) {
return this.findOne({ lecturename });
};
// Update by lecturename
LectureSchema.statics.updateBylecturename = function (lecturename, payload) {
// { new: true }: return the modified document rather than the original. defaults to false
return this.findOneAndUpdate({ lecturename }, payload, { new: true });
};
// Delete by lecturename
LectureSchema.statics.deleteBylecturename = function (lecturename) {
return this.remove({ lecturename });
};
// Create Model & Export
module.exports = mongoose.model('Lecture', LectureSchema);
\ No newline at end of file
const mongoose = require('mongoose');
// Define Schemes
const reviewSchema = new mongoose.Schema({
lecturename: { type: String },
proname: { type: String },
avg_rate: { type: Number },
review: {type : String}
});
// // Create new lecture document
reviewSchema.statics.create = function (payload) {
// this === Model
const lecture = new this(payload);
// return Promise
return lecture.save();
};
// Find lecturename
reviewSchema.statics.findBylecturename = function (lecturename) {
// return promise
// V4부터 exec() 필요없음
return this.find({ lecturename });
};
// Find by professor name
reviewSchema.statics.findByproname = function (proname) {
return this.find({ proname });
};
// Update by lecturename
reviewSchema.statics.updateBylecturename = function (lecturename, payload) {
// { new: true }: return the modified document rather than the original. defaults to false
return this.findOneAndUpdate({ lecturename }, payload, { new: true });
};
// Delete by lecturename
reviewSchema.statics.deleteBylecturename = function (lecturename) {
return this.remove({ lecturename });
};
// Create Model & Export
module.exports = mongoose.model('Review', reviewSchema);
This diff is collapsed. Click to expand it.
......@@ -11,10 +11,10 @@
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"dotenv": "^8.0.0",
"emoji-strip": "^1.0.1",
"express": "^4.17.0",
"mongodb": "^3.2.6",
"mongoose": "^5.5.11",
"mongojs": "^2.6.0",
"mysql": "^2.17.1",
"puppeteer": "^1.17.0",
"puppeteer-core": "^1.17.0",
"request": "^2.88.0"
......
const router = require('express').Router();
const Lecture = require('../models/lecture');
// Find All
router.get('/', (req, res) => {
Lecture.findAll()
.then((Lectures) => {
if (!Lectures.length) return res.status(404).send({ err: 'Lecture not found' });
res.send(`find successfully: ${Lectures}`);
})
.catch(err => res.status(500).send(err));
});
// Find One by lecturename
router.get('/lecturename/:lecturename', (req, res) => {
Lecture.findOneBylecturename(req.params.lecturename)
.then((Lecture) => {
if (!Lecture) return res.status(404).send({ err: 'Lecture not found' });
res.send(`findOne successfully: ${Lecture}`);
})
.catch(err => res.status(500).send(err));
});
// Create new Lecture document
router.post('/', (req, res) => {
console.log(req.body)
Lecture.create(req.body)
.then(Lecture => res.send(Lecture))
.catch(err => res.status(500).send(err));
});
// Update by lecturename
router.put('/lecturename/:lecturename', (req, res) => {
Lecture.updateBylecturename(req.params.lecturename, req.body)
.then(Lecture => res.send(Lecture))
.catch(err => res.status(500).send(err));
});
// Delete by lecturename
router.delete('/lecturename/:lecturename', (req, res) => {
Lecture.deleteBylecturename(req.params.lecturename)
.then(() => res.sendStatus(200))
.catch(err => res.status(500).send(err));
});
module.exports = router;
\ No newline at end of file
const router = require('express').Router();
const Review = require('../models/review');
// Find All
router.get('/', (req, res) => {
Review.findAll()
.then((Reviews) => {
if (!Reviews.length) return res.status(404).send({ err: 'Review not found' });
res.send(`find successfully: ${Reviews}`);
})
.catch(err => res.status(500).send(err));
});
// Find One by Reviewid
router.get('/lecturename/:lecturename', (req, res) => {
Review.findBylecturename(req.params.lecturename)
.then((Review) => {
if (!Review) return res.status(404).send({ err: 'Review not found' });
res.send(`findOne successfully: ${Review}`);
})
.catch(err => res.status(500).send(err));
});
router.get('/proname/:proname', (req, res) => {
Review.findByproname(req.params.proname)
.then((Review) => {
if (!Review) return res.status(404).send({ err: 'Review not found' });
res.send(`findOne successfully: ${Review}`);
})
.catch(err => res.status(500).send(err));
});
// Create new Review document
router.post('/', (req, res) => {
console.log(req.body)
Review.create(req.body)
.then(Review => res.send(Review))
.catch(err => res.status(500).send(err));
});
// Update by lecturename
router.put('/lecturename/:lecturename', (req, res) => {
Review.updateBylecturename(req.params.lecturename, req.body)
.then(Review => res.send(Review))
.catch(err => res.status(500).send(err));
});
// Delete by lecturename
router.delete('/lecturename/:lecturename', (req, res) => {
Review.deleteBylecturename(req.params.lecturename)
.then(() => res.sendStatus(200))
.catch(err => res.status(500).send(err));
});
module.exports = router;
\ No newline at end of file
// ENV
require('dotenv').config();
// DEPENDENCIES
const express = require('express');
const mongoose = require('mongoose');
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 4500;
// Static File Service
app.use(express.static('public'));
// Body-parser
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Node의 native Promise 사용
mongoose.Promise = global.Promise;
// Connect to MongoDB
mongoose.connect(process.env.MONGO_URI)
.then(() => console.log('Successfully connected to mongodb'))
.catch(e => console.error(e));
// ROUTERS
app.use('/lectures', require('./routes/lectures'));
app.use('/reviews', require('./routes/reviews'));
app.listen(port, () => console.log(`Server listening on port ${port}`));
\ No newline at end of file