-
Notifications
You must be signed in to change notification settings - Fork 0
/
indetifyGoogle.js
176 lines (154 loc) · 4.62 KB
/
indetifyGoogle.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
174
175
176
const { scrapeEmailFromDomain } = require("./scrapeContactInfo");
// const { emailPermutator } = require("./permutate");
const { getLocationYelp, getYelpData } = require("./yelpLocation");
const { searchPlaces, placeInfo } = require("./googlePlaceUtils");
const {
regexSnippet,
getCityCountry,
extractDomainFromUrl
} = require("./utils");
const {
postDataToAppsScript,
removeElem,
textDataToArray
} = require("./utils");
const { getEmailsFromToofr } = require("./getEmailsFromToofr");
const getMapsPlacesLocationGoogle = async (
googleData,
vertical,
scriptUrl,
userStartTime
) => {
let placesArr = [];
let emailLeads = [];
for (let i = 0; i < googleData.length; i++) {
console.log("GOOGLE DATA", googleData);
let link = googleData[i];
// fbLinkedinUsers.push(link)
// let splitted = stripSpecalChar(link.name)
// .split(" ")
// .filter(item => item.length > 2);
// = (splitted[0] + " " + splitted[1]).replace(
// /[^\w\s]/gi,
// ""
// );
//return;
let filteredName = link.firstName + " " + link.lastName;
let location = link.location;
let yelpAddress = await getLocationYelp(filteredName, location);
console.log("Yelp Address", yelpAddress);
let placeData;
if (!yelpAddress) {
placeData = await searchPlaces(
"" + filteredName + ", " + vertical + ", " + location + ""
);
// console.log("Search Place ", placeData)
placeData = placeData[0];
// await getGooglePlaceInfo(
// "" + filteredName + ", " + vertical + ", " + location + "",
// "query",
// getGooglePlacesApiKeys()
// );
}
if (!placeData) {
if (!yelpAddress) continue;
placeData = await searchPlaces(
"" + filteredName + ", " + vertical + ", " + yelpAddress + ""
);
placeData = placeData[0];
// placeData = await getGooglePlaceInfo(
// "" + filteredName + ", " + vertical + ", " + yelpAddress + "",
// "query",
// getGooglePlacesApiKeys()
// );
if (!placeData) continue;
continue;
}
let placeIdInfo = await placeInfo(placeData.place_id);
// console.log("place ID", placeIdInfo);
// await getGooglePlaceInfo(
// placeData.placeId,
// "placeid",
// getGooglePlacesApiKeys()
// );
let { vicinity, name, website = "", rating = "" } = placeIdInfo;
placesArr.push([
name,
link.firstName,
link.lastName,
link.url,
vicinity,
website,
rating
]);
let domain = website.match(".*://?([^/]+)")
? website.match(".*://?([^/]+)")[1]
: `${filteredName.replace(" ", "")}.com`;
let crawlEmail = await scrapeEmailFromDomain(website || domain);
// console.log(
// "Firstname",
// splitted[0],
// "LastName",
// splitted[1],
// "Website",
// website,
// "Domain",
// domain
// );
// let emailFromToof = await getEmailsFromToofr(
// link.firstName,
// link.lastName,
// website || domain
// );
// console.log("EMAILS FROM TOOFR", emailFromToof);
if (emailFromToof != []) {
let emailsToofr = [];
emailFromToof.forEach(el => {
emailsToofr.push(el.email + " , " + " | " + el.confidence);
});
}
//let firstEmail = crawlEmail.split(",")[0];
console.log("EMAILS FROM TOOFR", emailsToofr);
let emails = [
...[
name,
link.firstName,
link.lastName,
link.url,
website,
filteredName,
emailsToofr.join(" ")
//crawlEmail
]
//...permutateEmails
];
emailLeads.push(emails);
}
await postDataToAppsScript(scriptUrl, placesArr, "places");
await postDataToAppsScript(scriptUrl, emailLeads, "emails");
//startTime;
// await getBusinessData(vertical, inputLocation, scriptUrl);
let queueRequests = removeElem(userStartTime);
let isItLastReq = queueRequests.length === 0;
console.log("Is it last request? ", isItLastReq, queueRequests);
if (isItLastReq) {
let rawEmails = textDataToArray();
//console.log(rawEmails);
console.log("PROCESS FINISHED");
// Remove File data before Validation
//emptyTextDataFile();
//validateRawEmails(scriptUrl, rawEmails);
await postDataToAppsScript(
"https://script.google.com/macros/s/AKfycbwvj6UAhPMaEPb3p-SshlFeJ_Z2jftVeSwh-K2-I9VG9aaCs0Qd/exec",
textDataToArray().map(item => [item]),
"verifiedEmails"
);
}
};
function stripSpecalChar(str) {
return str.replace(/[`~!@#$%^&*()_|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, " ");
}
module.exports = {
//postDataToAppsScript,
getMapsPlacesLocationGoogle
};