This repository was archived by the owner on Mar 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathak_company_in.js
executable file
·164 lines (135 loc) · 5.09 KB
/
ak_company_in.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
// JavaScript Document
// 2. Runs when the JavaScript framework is loaded
function onLinkedInLoad() {
IN.Event.on(IN, "auth", displayStatus);
}
function displayStatus() {
var statusDiv = document.getElementById("status");
statusDiv.innerHTML +=
"<p>Successfully logged in to Linkedin</p>"
}
$(document).ready(function() {
if(isAPIAvailable()) {
$('#files').bind('change', handleFileSelect);
}
});
function isAPIAvailable() {
// Check for the various File API support.
if (window.File && window.FileReader && window.FileList && window.Blob) {
// Great success! All the File APIs are supported.
return true;
} else {
// source: File API availability - http://caniuse.com/#feat=fileapi
// source: <output> availability - http://html5doctor.com/the-output-element/
document.writeln('The HTML5 APIs used in this form are only available in the following browsers:<br />');
// 6.0 File API & 13.0 <output>
document.writeln(' - Google Chrome: 13.0 or later<br />');
// 3.6 File API & 6.0 <output>
document.writeln(' - Mozilla Firefox: 6.0 or later<br />');
// 10.0 File API & 10.0 <output>
document.writeln(' - Internet Explorer: Not supported (partial support expected in 10.0)<br />');
// ? File API & 5.1 <output>
document.writeln(' - Safari: Not supported<br />');
// ? File API & 9.2 <output>
document.writeln(' - Opera: Not supported');
return false;
}
}
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
var file = files[0];
runCompanyUpdate(file)
}
// 1. Reads the CSV to an array and then iterates through each item, checking against Linkedin
function runCompanyUpdate(file) {
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function(event){
var csv = event.target.result;
var lookupSelect = document.getElementById("csvType");
var lookupType = lookupSelect.options[lookupSelect.selectedIndex].value;
var companyLookups = $.csv.toArrays(csv);
var urlStart = "/companies"
var urlMiddle = ""
var urlEnd = ":(id,name,industry,website-url,employee-count-range,founded-year,status,end-year,company-type,email-domains)"
if (lookupType=="linkedinID"){
var urlMiddle = "/"
}
else if (lookupType=="uniName"){
var urlMiddle = "/universal-name="
}
else {
var urlMiddle = "?email-domain="
var urlEnd = ""
}
for (var i=0;i<companyLookups.length;i++)
{
var currentLookup = companyLookups[[i],[i]];
var url = urlStart + urlMiddle + currentLookup + urlEnd
IN.API.Raw()
.url(url)
.result(function (result) {
if (lookupType == "emailDomain"){
displayCompanies(result);
}
else {
displayCompany(result);
}
})
.error(function (error) {
displayError(error);
});
}
};
reader.onerror = function(){ alert('Unable to read ' + file.fileName); };
}
// 3. Runs when the Profile() API call returns successfully
function displayCompany(result) {
var companyProfileDiv = document.getElementById("companyProfile");
var emDoms = result.emailDomains.values
var testes = emDoms.length
console.log(result)
companyProfileDiv.innerHTML +=
"\"" + result.id + "\"§\"" + result.name + "\"§\"" + result.industry + "\"§\"" + result.websiteUrl + "\"§\"" + result.employeeCountRange.name + "\"§\"" + result.foundedYear + "\"§\"" + result.status.name + "\"§\"" + result.endYear + "\"§\"" + result.companyType.name +"\"";
for (var i=0;i<emDoms.length;i++)
{
var emDom = emDoms[i]
companyProfileDiv.innerHTML += "§\"" + emDom + "\"";
}
companyProfileDiv.innerHTML += "<br />";
}
// 4. Runs when the Profile() API call returns successfully - only for email domains - has to have a loop as the results are returned in an array
function displayCompanies(result) {
var companyProfileDiv = document.getElementById("companyProfile");
var companies = result.values;
for (var company in companies) {
companyProfileDiv.innerHTML +=
"\"" + companies[company].id + "\"§\"" + companies[company].name + "\"<br />";
}
}
// 5. Runs when the Profile() API call returns an error
function displayError(error) {
var companyProfileDiv = document.getElementById("companyProfile");
companyProfileDiv.innerHTML +=
"\"" + error.message +"\"<br />"
}
/*
function printTable(file) {
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function(event){
var csv = event.target.result;
var data = $.csv.toArrays(csv);
var html = '';
for(var row in data) {
html += '<tr>\r\n';
for(var item in data[row]) {
html += '<td>' + data[row][item] + '</td>\r\n';
}
html += '</tr>\r\n';
}
$('#contents').html(html);
};
reader.onerror = function(){ alert('Unable to read ' + file.fileName); };
}
*/