Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
231 lines (196 loc) · 6.22 KB
/
Copy pathserver.js
File metadata and controls
231 lines (196 loc) · 6.22 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
const cluster = require("cluster");
const http = require("http");
const numCPUs = require("os").cpus().length;
const express = require("express");
const app = express();
const bodyParser = require("body-parser");
const { scraper } = require("./scraper");
const { getBusinessByZipCode } = require("./searchByZipCodes");
const { getBusinessData } = require("./yelpBusinessLocation");
const { validateRawEmails } = require("./bulkEmailChecker");
const { linkedinLeads } = require("./linkedinLeads");
const { getMapsPlacesLocation } = require("./identifyLinkedin");
const { getMapsPlacesLocationGoogle } = require("./indetifyGoogle");
const { getBingData } = require("./identifyBingResults");
const { bingSearchApi } = require("./bingSearchApi");
const { getEmailsFromToofr } = require("./getEmailsFromToofr");
// let RateLimit = require("express-rate-limit");
const { queueRequests, getCityCountry } = require("./utils");
// const { scraPeYellowPages } = require("./scrapeYellowPages");
const { pickProxiesIp } = require("./proxies");
const mongoose = require("mongoose");
const { scrapeLinkedinUrl } = require("./scrapeLinkedinUrlBingApi");
mongoose.Promise = global.Promise;
mongoose.connect(
"mongodb://root:root@mongo-companies.server.pkristijan.xyz:27017/",
err => {
if (err) {
console.log("err", err);
return;
}
}
);
const PORT = 4000;
/**
* Get port from environment and store in Express.
*/
let port = normalizePort(process.env.PORT || PORT);
// let limiter = new RateLimit({
// windowMs: 1 * 60 * 1000, // 1 minute
// max: 1, // limit each IP to 1 requests per windowMs
// delayMs: 0 // disable delaying - full speed until the max limit is reached
// });
app.use(
bodyParser.urlencoded({
extended: true,
limit: "5mb",
parameterLimit: 100000
})
);
app.use(
bodyParser.json({
limit: "5mb"
})
);
// app.use(bodyParser.json());
// apply to all requests
//app.use("/scrape", limiter);
let proxyIp = require("./myDataBase.json");
// app.post("/yellowPages", async (req, res) => {
// const { vertical, location, count } = req.body;
// let results = await scraPeYellowPages(vertical, location, count);
// res.send({ msg: "success" });
// });
app.post("/linkedinScrape", async (req, res) => {
const { query, vertical, location, scriptUrl, count } = req.body;
let link = `http://www.bing.com/search?q=${query}&qs=n&first=0`;
console.log("query", query, "whole link query", link);
let proxyIp = "95.216.86.195:443"; //await pickProxiesIp();
let results = await linkedinLeads(
link,
[],
location,
vertical,
count,
scriptUrl,
proxyIp
// proxyIp.ip
);
res.send({ msg: "success", link });
});
app.post("/identifyLinkedin", async (req, res) => {
console.log(req.body);
const { linkedinData, scriptUrl, vertical, inputLocation } = req.body;
getMapsPlacesLocation(linkedinData, inputLocation, vertical, scriptUrl);
res.send({ msg: "success" });
});
app.post("/identifyBing", async (req, res) => {
//console.log(req.body);
const { linkedinData, scriptUrl, vertical, inputLocation } = req.body;
getBingData(linkedinData, inputLocation, vertical, scriptUrl);
res.send({ msg: "success" });
});
app.post("/identifyGoogle", async (req, res) => {
const { googleData, scriptUrl, vertical } = req.body;
getMapsPlacesLocationGoogle(googleData, vertical, scriptUrl);
res.send({ msg: "success" });
});
app.post("/getEmailsToofr", async (req, res) => {
const { googleData, scriptUrl } = req.body;
getEmailsFromToofr(googleData, scriptUrl);
res.send({ msg: "success" });
});
app.post("/scrapeLinkedinUrl", async (req, res) => {
const { urls, scriptUrl } = req.body;
let arr = urls.map(el => el.profileUrl);
// console.log(urls);
let proxyIp = "95.216.86.195:443";
let link = [];
let formattedUrls = arr.map(
item => `http://www.bing.com/search?q=${item}&qs=n&first=0`
);
let results = await scrapeLinkedinUrl(formattedUrls, [], scriptUrl, proxyIp);
res.send({ msg: "success" });
});
app.post("/scrape", async (req, res) => {
const { query, vertical, location, scriptUrl, count } = req.body;
if (!query || !vertical || !location || !scriptUrl) {
return res.status(401).send({ msg: "Not enough parametars." });
}
let link = `http://www.bing.com/search?q=${query}&qs=n&first=0`;
let startTime = new Date().getTime();
req.startTime = startTime;
queueRequests.push(startTime);
console.log("Request Queue", startTime);
let results = await scraper(
link,
[],
location,
vertical,
count,
scriptUrl,
proxyIp.ip,
startTime
);
// yelp business
// let locationResults = getBusinessData(
// vertical,
// location,
// scriptUrl,
// startTime
// );
res.send({ msg: "success", link });
});
app.post("/bussines", async (req, res) => {
const { location, scriptUrl, term } = req.body;
if (!location || !scriptUrl || !term) {
return res.status(401).send({ msg: "Not enough parametars." });
}
let locationResults = await getBusinessData(term, location, scriptUrl);
res.send({ msg: "success", location, term });
});
app.post("/zipCodeSearch", async (req, res) => {
const { city, country, vertical, scriptUrl } = req.body; // zipcode
if (!city || !country || !vertical || !scriptUrl) {
return res.status(401).send({ msg: "Not enough parametars." });
}
let zipCodesBussines = await getBusinessByZipCode(
city,
country,
vertical,
scriptUrl
);
res.send({ msg: "success", country, vertical });
});
app.post("/validatemails", async (req, res) => {
let { rawEmails, scriptUrl } = req.body;
console.log(rawEmails);
validateRawEmails(scriptUrl, rawEmails);
res.send({ msg: "success" });
});
if (cluster.isMaster) {
console.log(`Master ${process.pid} is running`);
for (let i = 0; i < numCPUs.length; i++) {
cluster.fork();
}
cluster.on("exit", (worker, code, signal) => {
console.log(`worker ${worker.process.pid} died`);
});
} else {
}
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
let port = parseInt(val, 10);
if (isNaN(port)) {
// named pipe
return val;
}
if (port >= 0) {
// port number
return port;
}
return false;
}