-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.js
More file actions
94 lines (69 loc) · 2.53 KB
/
Copy pathapp.js
File metadata and controls
94 lines (69 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
const express = require("express");
const bodyParser = require("body-parser");
const ejs = require('ejs');
const app = express();
app.set("view engine", "ejs");
const SerpWow = require('google-search-results-serpwow')
const serpwow = new SerpWow('API KEY') // API key
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(express.static("public"));
app.get("/", (req, res) => {
res.sendFile(__dirname + "/index.html");
})
app.post("/", (req, res) => {
var query = req.body.query; // User input sent from form
var params = {
q: query,
location: 'Canada'
}
serpwow.json(params)
.then((result) => {
var data = result
var video1 = data.inline_videos[0].link
var prob1 = data.related_questions[0].question
var ans1 = data.related_questions[0].answer
var prob2 = data.related_questions[1].question
var ans2 = data.related_questions[1].answer
var prob3 = data.related_questions[2].question
var ans3 = data.related_questions[2].answer
var web1t = data.organic_results[0].title
var web2t = data.organic_results[1].title
var web3t = data.organic_results[2].title
var web1desc = data.organic_results[0].snippet
var web2desc = data.organic_results[1].snippet
var web3desc = data.organic_results[2].snippet
var web1url = data.organic_results[0].cached_page_link
var web2url = data.organic_results[1].cached_page_link
var web3url = data.organic_results[2].cached_page_link
groups = video1.match(/.*\/(watch\?v=)?(.+)/)
let video_id = groups[groups.length - 1]
let embed_link = `https://www.youtube.com/embed/${video_id}`
res.render("learn", {
query: query,
video1: embed_link,
prob1: prob1,
prob2: prob2,
prob3: prob3,
ans1: ans1,
ans2: ans2,
ans3: ans3,
web1t: web1t,
web2t: web2t,
web3t: web3t,
web1url: web1url,
web2url: web2url,
web3url: web3url,
web1desc: web1desc,
web2desc: web2desc,
web3desc: web3desc
})
})
.catch(error => {
console.log(error);
});
});
app.listen(process.env.PORT || 3000, () => {
console.log("Server on port 3000");
});