This repository has been archived by the owner on Oct 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.js
108 lines (101 loc) · 2.04 KB
/
loader.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const mongoClient = require("mongodb").MongoClient;
const axios = require("axios");
const async = require("async");
const youtubeSearch = require("youtube-search");
const config = require("./config");
// ENVIRONMENT
const TAG = "dev";
var mongodbDatabase = "sailing-channels";
var mongodbHost = TAG === "dev" ? "localhost" : "mongo";
// Use connect method to connect to the server
mongoClient.connect(
"mongodb://" + mongodbHost + ":27017/" + mongodbDatabase,
(err, db) => {
// find all channel description
db
.collection("channels")
.find({})
.project({
description: 1
})
.toArray((err, channels) => {
// loop channels
async.each(
channels,
(channel, callback) => {
// push to learn classifier
axios
.post("http://127.0.0.1:8080/learn", {
classifier: "sailing",
category: "sailing",
text: channel.description
})
.then(function(response) {
console.log(channel._id);
return callback();
})
.catch(function(err) {
return callback(err);
});
},
err => {
console.log(err);
db.close();
}
);
});
}
);
const nonSailingSearchTerms = [
"cars",
"games",
"racing",
"garden",
"lifestyle",
"school",
"politics",
"vegan",
"food",
"baking",
"planes",
"vacation",
"holiday",
"usa",
"gaming",
"nature",
"beer",
"books",
"literature"
];
nonSailingSearchTerms.forEach(term => {
var opts = {
maxResults: 50,
key: config.ytAPIKey
};
youtubeSearch(term, opts, function(err, results) {
if (err) return console.log(err);
async.each(
results,
(channel, callback) => {
// push to learn classifier
axios
.post("http://127.0.0.1:8080/learn", {
classifier: "sailing",
category: "non-sailing",
text: channel.description
})
.then(function(response) {
console.log(channel.channelId);
return callback();
})
.catch(function(err) {
return callback(err);
});
},
err => {
console.log(err);
db.close();
}
);
});
});