-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
173 lines (154 loc) · 4.43 KB
/
utils.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
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
const axioshttps = require("axios-https-proxy-fix");
const axios = require("axios");
const fs = require("fs");
const countryMapper = require("./companyData/countriesMap.json");
const inputStr = inputStr => {
return inputStr
.replace(/[\s_-]+/g, " ")
.trim()
.split(" ")
.map(function(str) {
return str.replace(/\W/g, "");
})
.map(function(str, i) {
return str
.split("")
.map(function(l, j) {
return i !== 0 && j == 0 ? l.toUpperCase() : l.toLowerCase();
})
.join("");
})
.join("");
};
const axiosProxyRequest = url => {
return axioshttps.get(url, {
proxy: {
host: "us-wa.proxymesh.com",
port: 31280,
auth: {
username: "tealeaf",
password: "eTjiELVQeA8HNPXBweWGdpdD"
}
}
});
};
const axiosProxyRequest1 = (proxyIp, url) => {
return axios.get(url, {
proxy: {
host: proxyIp.split(":")[0],
port: proxyIp.split(":")[1]
// auth: {
// username: "lum-customer-hl_030a86e4-zone-static",
// password: "ueyv97j2vmup"
// }
}
});
};
// axiosProxyRequest1(
// "http://www.bing.com/search?q=site%3Alinkedin.com+intitle%3ACOO+AND+inbody%3Achiropractor+Texas&qs=n&form=QBLH&sp=-1&pq=site%3Alinkedin.com+intitle%3Acoo+and+inbody%3Achiropractor+texas&sc=0-59&sk=&cvid=E9A3AD83A3724162B1F38CA156D1A81A"
// ).then(res => console.log(res));
const postDataToAppsScript = async (
scriptUrl = "https://script.google.com/macros/s/AKfycbwvj6UAhPMaEPb3p-SshlFeJ_Z2jftVeSwh-K2-I9VG9aaCs0Qd/exec",
data,
name
) => {
//console.log("POST DATA TO APP SCRIPT", data);
let objData = { [name]: data };
return axios
.post(scriptUrl, objData)
.then(resp => {
//console.log("DATA TO APP SCRIPT", resp);
return resp.data;
})
.catch(err => {});
};
let queueRequests = [];
const removeElem = el => {
let indexT = queueRequests.indexOf(el);
console.log("removing element", queueRequests, queueRequests.indexOf(el), el);
if (indexT > -1) {
queueRequests.splice(indexT, 1);
}
return queueRequests;
};
const writeEmailsToFile = (emails = []) => {
return fs.appendFileSync("rawEmails.txt", emails.join("\n") + "\n");
};
const textDataToArray = () => {
return fs
.readFileSync("rawEmails.txt")
.toString()
.split("\n")
.filter(onlyUnique);
};
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
const emptyTextDataFile = () => {
try {
return fs.unlinkSync("rawEmails.txt");
} catch (err) {}
};
const regexSnippet = async snippet => {
console.log("enter");
if (snippet) {
let matchedSnippet = snippet.match(/(CEO|Owner|COO|Founder)(.*\n?)(\,)/g);
console.log("match", matchedSnippet);
if (matchedSnippet !== null) {
if (
matchedSnippet[0].indexOf("CEO") > -1 ||
matchedSnippet[0].indexOf("Owner") > -1 ||
matchedSnippet[0].indexOf("COO") > -1 ||
matchedSnippet[0].indexOf("Founder") > -1
) {
let newSnippet = matchedSnippet[0]
.split(".")[0]
.replace(/and|et|at|of|CEO|COO|Owner|Founder|founder,/g, "");
console.log("SNIPPET REGEX", newSnippet);
let filteredSnippet = newSnippet.replace(/[^a-zA-Z ]/g, ""); //.replace(/\s/g, ' ');
console.log("Filtered Snippet", filteredSnippet);
return filteredSnippet;
}
}
}
};
//regexSnippet("Mohamed Punjani - Founder and CEO - Bond Animal Health ...");
const getCityCountry = locationString => {
if (locationString) {
let arr = locationString.split(",").map(item => item.trim());
let foundCountry = arr.filter(item => countryMapper[item]);
//console.log(foundCountry);
let indexCountry = arr.indexOf(foundCountry[0]);
let city =
(indexCountry > -1 ? (indexCountry === 1 ? arr[0] : arr[1]) : "") || "";
console.log({
country: foundCountry[0],
city
});
return {
country: foundCountry[0] || "",
city,
shortCode: countryMapper[foundCountry[0]] || ""
};
}
};
const extractDomainFromUrl = url => {
let matches = url.match(/^https?\:\/\/([^\/?#]+)(?:[\/?#]|$)/i);
let domain = matches && matches[1];
return domain;
};
module.exports = {
toLowerCamel: inputStr,
axiosProxyRequest,
postDataToAppsScript,
queueRequests,
writeEmailsToFile,
textDataToArray,
removeElem,
emptyTextDataFile,
regexSnippet,
getCityCountry,
extractDomainFromUrl,
axiosProxyRequest1
};
//console.log(textDataToArray())