Skip to content

Commit

Permalink
Merge pull request #18 from rajatmw1999/master
Browse files Browse the repository at this point in the history
Pull
  • Loading branch information
StrangerZiokan authored Sep 16, 2020
2 parents d32d72e + 8970184 commit 7e90ecd
Show file tree
Hide file tree
Showing 65 changed files with 4,144 additions and 1,597 deletions.
133 changes: 124 additions & 9 deletions api/admin_routes/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ const express = require("express");
const router = express.Router();
const mongoose = require("mongoose");
const FeaturedCourses = require("../models/roadmap/FeaturedCourses");

var bodyParser = require('body-parser');
router.use(bodyParser.json());
router.use(bodyParser.urlencoded({ extended: false }));
//Route 1
//ADD A NEW FEATURED COURSE
router.post("/addfeaturedcourses", (req, res, next) => {
const featuredcourse = new FeaturedCourses({
_id: new mongoose.Types.ObjectId(),
name: req.body.name,
price: req.body.price,
link: req.body.link,
company: req.body.company,
imageURL: req.body.imageUrl,
noOfHours: req.body.noOfHours,
desc: req.body.desc,
priceDiscount: req.body.priceDiscount,
duration: req.body.duration,
nameOfSkill: req.body.nameOfSkill.toLowerCase(),
category: req.body.category.toLowerCase()
});
featuredcourse
.save()
Expand All @@ -28,8 +39,9 @@ router.post("/addfeaturedcourses", (req, res, next) => {
});

//Route 2
router.post("/featuredCoursesById", (req, res) => {
const id = req.body.id;
//SEARCH A FEATURED COURSE BY ID
router.get("/featuredCoursesById/:id", (req, res) => {
const id = req.params.id;
FeaturedCourses.find({ _id: id })
.exec()
.then((doc) => {
Expand All @@ -49,10 +61,11 @@ router.post("/featuredCoursesById", (req, res) => {
});

//Route 3
//GET A FEATURED COURSE BY CATEGORY NAME AND SKILL NAME
router.post("/featuredCoursesByCategorySkill", (req, res) => {
const category = req.body.category;
const skillname = req.body.skillName;
FeaturedCourses.find({ NameOfSkill: skillname, Category: category })
const category = req.body.category.toLowerCase();
const skillname = req.body.skillName.toLowerCase();
FeaturedCourses.find({ nameOfSkill: skillname, category: category })
.exec()
.then((doc) => {
console.log("From database", doc);
Expand All @@ -71,8 +84,9 @@ router.post("/featuredCoursesByCategorySkill", (req, res) => {
});

//Route 4
router.delete("/deleteFeaturedCoursesById", (req, res) => {
const id = req.body.productId;
//DELETE A FEATURED COURSE BY ID
router.get("/deleteFeaturedCoursesById/:id", (req, res) => {
const id = req.params.id;
FeaturedCourses.remove({ _id: id })
.exec()
.then((result) => {
Expand All @@ -86,4 +100,105 @@ router.delete("/deleteFeaturedCoursesById", (req, res) => {
});
});

//Route 5
//GET ALL COURSES OF A CATEGORY
router.get("/featuredCoursesByCategory/:category", (req, res) => {
const category = req.params.category.toLowerCase().split('-')[0];
FeaturedCourses.find({ category: category })
.exec()
.then((doc) => {
console.log("From database", doc);
if (doc) {
res.status(200).json(doc);
} else {
res.status(404).json({
message: "No valid entry found for provided Category",
});
}
})
.catch((err) => {
console.log(err);
res.status(500).json({ error: err });
});
});

//ROUTE 6
//GET ALL COURSES OF A PARTICULAR SKILL
router.get("/featuredCoursesBySkill/:skillName", (req, res) => {
const skillname = req.params.skillName.toLowerCase().split('-')[0];
FeaturedCourses.find({ nameOfSkill: skillname })
.exec()
.then((doc) => {
console.log("From database", doc);
if (doc) {
res.status(200).json(doc);
} else {
res.status(404).json({
message: "No valid entry found for provided Skill",
});
}
})
.catch((err) => {
console.log(err);
res.status(500).json({ error: err });
});
});

//Route 7
//EDIT AN EXISTING COURSE
router.patch('/edit/:courseId',(req, res, next) =>{

const id = req.params.courseId;
const updateOps = {
name: req.body.name,
price: req.body.price,
link: req.body.link,
company: req.body.company,
imageUrl: req.body.imageUrl,
noOfHours: req.body.noOfHours,
desc: req.body.desc,
priceDiscount: req.body.priceDiscount,
duration: req.body.duration,
nameOfSkill: req.body.nameOfSkill.toLowerCase(),
category: req.body.category.toLowerCase()
};
console.log(updateOps);
FeaturedCourses.updateOne({ _id: id}, {$set: updateOps})
.exec()
.then(result => {
console.log(result);
res.status(200).json({
message: 'Featured Course updated yes',
});
})
.catch(err => {
console.log(err);
res.status(500).json({
error: err
})
});

});

//route 8
//RETUTN ALL FEATURED COURSES
router.get("/courses/all", (req, res) => {
FeaturedCourses.find({ })
.exec()
.then((doc) => {
console.log("From database", doc);
if (doc) {
res.status(200).json(doc);
} else {
res.status(404).json({
message: "No valid entry found.",
});
}
})
.catch((err) => {
console.log(err);
res.status(500).json({ error: err });
});
});

module.exports = router;
15 changes: 10 additions & 5 deletions api/data_routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ router.get("/searchsome/:skillName", async (req, res, next) => {
var arr = [];
var finalarr = [];
arr = req.params.skillName.toLowerCase().split("-");
for (var j = 0; j < arr.length; j++) {
var j;
for (j = 0; j < arr.length; j++) {
for (let elm of result) {
let skillStr = elm.nameSkill.toLowerCase();
let skillStr = await elm.nameSkill.toLowerCase();
console.log(elm);
if (skillStr.search(arr[j]) != -1) {
finalarr.push(elm);
}
}
}

if(j == arr.length)
{
res.status(200).json({
data: finalarr.length > 0 ? finalarr : "Not Found !",
});
}
} catch (err) {
res.status(500).json({
error: next(err),
Expand All @@ -45,11 +49,12 @@ router.get("/searchall/:skillName", async (req, res, next) => {
var arr = [];
var finalarr = [];
arr = req.params.skillName.toLowerCase().split("-");
console.log(arr);
for (let elm of result) {
var flag = 0;
let skillStr = elm.nameSkill.toLowerCase();
let skillStr = await elm.nameSkill.toLowerCase();
for (var j = 0; j < arr.length; j++) {
if (skillStr.search(arr[j]) === -1) {
if (skillStr.search(arr[j]) == -1) {
flag = 1;
}
}
Expand Down
7 changes: 3 additions & 4 deletions api/middleware/bitdegree.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,13 @@ let data = await page.evaluate(() =>{
json.courseName.push(JSON.stringify(courseName[i].innerText));//.href.substring(30)
json.price.push(JSON.stringify(price[i].innerText));
json.instructorName.push("BitDegree");
//json.link.push(JSON.stringify(courseName[i].href).substring(34));
json.link.push(JSON.stringify(link[i].href));
//json.courseName.push(json.link[i].substring(34));
//json.instructorName.push(JSON.stringify(instructorName[i].innerText));
json.courseDescription.push(null);
json.UrlOfImageThumbnail.push(JSON.stringify(UrlOfImageThumbnail[i].getAttribute('src')));
json.StudentsEnrolled.push(null);
json.NumberofHours.push(null);
j+=3;
// j+=3;
}

return json;
Expand Down Expand Up @@ -102,14 +100,15 @@ let data = await page.evaluate(() =>{
});

// console.log(data);
browser.close();
//res.status(200).json({
// message:'Search Results from BitDegree !',
// query: query.q,
// Data: data
//});
});

browser.close();

}

//var query = 'blockchain';
Expand Down
3 changes: 2 additions & 1 deletion api/middleware/codeacademy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ module.exports = (req, res, next,data1,category) => {

(async () =>{
const extractNames= async (weburl) =>{
let page = await browser.newPage();
let page = await browser.newPage();
console.log('Running middleware inside Codecademy');
await page.goto(weburl);

const data = await page.evaluate(() =>{
Expand Down
11 changes: 2 additions & 9 deletions api/middleware/khanAcademy.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,14 @@ let data = await page.evaluate(() =>{
//var price = document.querySelectorAll('div[class="field field-name-price"] >span');
var courseDescription = document.querySelectorAll('div[class="gs-bidi-start-align gs-snippet"]');
var link = document.querySelectorAll('div[class="gs-title"] >a');
// var UrlOfImageThumbnail = document.querySelectorAll('div[class="gsc-table-cell-thumbnail gsc-thumbnail"]>div[class="gs-image-box gs-web-image-box gs-web-image-box-landscape"]>a[class="gs-image"]>img[src]');
//
//var instructorName = document.querySelectorAll('');
//StanfordOnline
//var json = JSON.stringify(price);
//return courseName;
//,instructorName:[""] courseName ,price:[""]
// var UrlOfImageThumbnail = document.querySelectorAll('div[class="gs-image-box gs-web-image-box gs-web-image-box-landscape"]>a[class="gs-image"]>img[src]');

var json = {courseName:[],link:[],courseDescription:[]};
for(let i = 0; i < courseName.length; i++){
json.courseName.push(JSON.stringify(courseName[i].innerText));
//json.price.push(JSON.stringify(price[i].innerText));
json.link.push(JSON.stringify(link[i].href));
json.courseDescription.push(JSON.stringify(courseDescription[i].innerText));
// json.UrlOfImageThumbnail.push(JSON.stringify(UrlOfImageThumbnail[i].getAttribute('src')));
//json.instructorName.push(JSON.stringify(instructorName[i].innerText));
}

return json;
Expand Down
13 changes: 8 additions & 5 deletions api/middleware/openYale.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ let data = await page.evaluate(() =>{
var courseName = document.querySelectorAll('h3[class="title"] >a');
//var price = document.querySelectorAll('div[class="field field-name-price"] >span');
var link = document.querySelectorAll('h3[class="title"] >a');
var CourseDescription = document.querySelectorAll('div[class="search-snippet-info"]>p[class="search-snippet"]');

var json = {courseName:[],link:[]};
var json = {courseName:[],link:[],CourseDescription:[]};
for(let i = 0; i < courseName.length; i++){
json.courseName.push(JSON.stringify(courseName[i].innerText));
//json.price.push(JSON.stringify(price[i].innerText));
json.link.push(JSON.stringify(link[i].href));
json.CourseDescription.push(JSON.stringify(CourseDescription[i].innerText));
//json.instructorName.push(JSON.stringify(instructorName[i].innerText));
}

Expand All @@ -48,10 +50,11 @@ let data = await page.evaluate(() =>{
category:category,
platform:'openYale',
nameSkill: data1,
Courses: [ {NameofCourse: data.courseName[1],LinkToCourse: data.link[1]},
{NameofCourse: data.courseName[2],LinkToCourse: data.link[2]},
{NameofCourse: data.courseName[3],LinkToCourse: data.link[3]},
{NameofCourse: data.courseName[4],LinkToCourse: data.link[4]},]
Courses: [ {NameofCourse: data.courseName[0],LinkToCourse: data.link[0],CourseDescription:data.CourseDescription[0]},
{NameofCourse: data.courseName[1],LinkToCourse: data.link[1],CourseDescription:data.CourseDescription[1]},
{NameofCourse: data.courseName[2],LinkToCourse: data.link[2],CourseDescription:data.CourseDescription[2]},
{NameofCourse: data.courseName[3],LinkToCourse: data.link[3],CourseDescription:data.CourseDescription[3]},
{NameofCourse: data.courseName[4],LinkToCourse: data.link[4],CourseDescription:data.CourseDescription[4]}]
});
skill
.save()
Expand Down
38 changes: 18 additions & 20 deletions api/middleware/skillshare.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,21 @@ let skillShareSearchQuery = data1;
await page.waitFor(10000);

let data = await page.evaluate(() => {
let instructorName = (document.querySelectorAll('p[class="title ellipsis"]'));
let UrlOfImageThumbnail = (document.querySelectorAll('div[class="ss-card__thumbnail-img-holder"]>img[src]'));
let courseName = (document.querySelectorAll('p[class="ss-card__title"] >a'));
let courseDuration = (document.querySelectorAll('div[class="ss-class__stats__duration"]'));
let studentsEnrolled = (document.querySelectorAll('span[class="ss-class__stats__stud-count"]'));
// let price = (document.querySelectorAll('span[class="currency-converter "]'));
// let rating = (document.querySelectorAll('div[class="text-bold text-large"]'));
// let lessons = (document.querySelectorAll('div[class="flex flex-direction-column ProfileBase--truncate flex-direction-column"] >div >span'));
// let instructorName = (document.querySelectorAll('p[class="title ellipsis"]'));
let NameofCourse = (document.querySelectorAll('p[class="title"]'));;
let instructorName = (document.querySelectorAll('div[class="user-information small"]>a'));
let StudentsEnrolled = (document.querySelectorAll('div[class="stats"]>span[class="student-count"]'));
let NumberofHours = (document.querySelectorAll('div[class="stats"]>div[class="duration"]>span'));

var json = {instructorName:[],courseName:[],courseDuration:[],studentsEnrolled:[],UrlOfImageThumbnail:[]};

var json = {NameofCourse:[],instructorName:[],StudentsEnrolled:[],NumberofHours:[]};


for(let i=0;i<instructorName.length;i++){
json.instructorName.push(JSON.stringify(instructorName[i].innerText));
json.courseName.push(JSON.stringify(courseName[i].innerText));
json.courseDuration.push(JSON.stringify(courseDuration[i].innerText));
json.studentsEnrolled.push(JSON.stringify(studentsEnrolled[i].innerText));
json.UrlOfImageThumbnail.push(JSON.stringify(UrlOfImageThumbnail[i].getAttribute('src')));
json.NameofCourse.push(JSON.stringify(NameofCourse[i].innerText));
json.StudentsEnrolled.push(JSON.stringify(StudentsEnrolled[i].innerText));
json.NumberofHours.push(JSON.stringify(NumberofHours[i].innerText));
}

return json;
Expand All @@ -55,11 +52,11 @@ let skillShareSearchQuery = data1;
category:category,
nameSkill: data1,
platform:'skillShare',
Courses: [ {NameofCourse: data.courseName[0],Instructor: data.instructorName[0],UrlOfImageThumbnail:data.UrlOfImageThumbnail[0],StudentsEnrolled:data.studentsEnrolled[0]},
{NameofCourse: data.courseName[1],Instructor: data.instructorName[1],UrlOfImageThumbnail:data.UrlOfImageThumbnail[1],StudentsEnrolled:data.studentsEnrolled[1]},
{NameofCourse: data.courseName[2],Instructor: data.instructorName[2],UrlOfImageThumbnail:data.UrlOfImageThumbnail[2],StudentsEnrolled:data.studentsEnrolled[2]},
{NameofCourse: data.courseName[3],Instructor: data.instructorName[3],UrlOfImageThumbnail:data.UrlOfImageThumbnail[3],StudentsEnrolled:data.studentsEnrolled[3]},
{NameofCourse: data.courseName[4],Instructor: data.instructorName[4],UrlOfImageThumbnail:data.UrlOfImageThumbnail[4],StudentsEnrolled:data.studentsEnrolled[4]}]
Courses: [ {NameofCourse: data.NameofCourse[0],Instructor: data.instructorName[0],StudentsEnrolled:data.StudentsEnrolled[0],NumberofHours:data.NumberofHours[0]},
{NameofCourse: data.NameofCourse[1],Instructor: data.instructorName[1],StudentsEnrolled:data.StudentsEnrolled[1],NumberofHours:data.NumberofHours[1]},
{NameofCourse: data.NameofCourse[2],Instructor: data.instructorName[2],StudentsEnrolled:data.StudentsEnrolled[2],NumberofHours:data.NumberofHours[2]},
{NameofCourse: data.NameofCourse[3],Instructor: data.instructorName[3],StudentsEnrolled:data.StudentsEnrolled[3],NumberofHours:data.NumberofHours[3]},
{NameofCourse: data.NameofCourse[4],Instructor: data.instructorName[4],StudentsEnrolled:data.StudentsEnrolled[4],NumberofHours:data.NumberofHours[4]}]
});
skill
.save()
Expand All @@ -74,12 +71,13 @@ let skillShareSearchQuery = data1;
});


// console.log("skillShareResult",data);
// console.log("skillShareResult",data);
browser.close();


})

browser.close();

})();
next();
}
Expand Down
Loading

0 comments on commit 7e90ecd

Please sign in to comment.