-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraper.js
163 lines (118 loc) · 3.38 KB
/
scraper.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
var mongoose = require('mongoose');
var config = require('./config');
var Job = require('./models/job');
var Company = require('./models/company');
var test = false;
if (!test) mongoose.connect(config.mongodb);
/*
^--- seem good to go
https://chc.tbe.taleo.net/chc01/ats/careers/searchResults.jsp?org=SHIMANO&cws=1
^--- maybe multiple pages? also has fish
http://wheelsmfg.com/employment-opportunities
https://www.eastoncycling.com/about-us/careers/
^--- all on one page
^--- json but easy looking to scrape
https://www.giant-bicycles.com/us/job-openings
http://www.finishlineusa.com/resources/careers.php
https://www.brompton.com/About-Us/Careers
^--- weird pdfs
https://www.pinkbike.com/about/jobs/
https://recruiting.ultipro.com/QUA1003QBP/JobBoard/4b01c3ed-7e54-43da-954f-c74c4b3945a6/OpportunityDetail?opportunityId=19b344bd-5891-40ec-9fa0-46d4393c3b98
https://www.fitzii.com/careers/cervelo/
https://www.trekbikes.com/us/en_US/current_openings?p=jobs&nl=1
https://www.specialized.com/us/en/careers
https://www.santacruzbicycles.com/en-US/current-job-openings
^--- donezo
*/
var companyComplete = [];
var started = (company) => {
companyComplete[company] = false;
}
var completed = (company) => {
companyComplete[company] = true;
}
var companyCompleted = () => Object.keys(companyComplete).every(e=>companyComplete[e]==true);
var tags = [
{name: "mechanic", label: "Mechanic"},
{name: "engineering", label: "Engineering"},
{name: "accounting", label: "Accounting"},
{name: "executive", label: "Executive"},
{name: "customer service", label: "Customer Service"},
]
var getTag = () => tags[Math.floor(Math.random() * tags.length)]
class jobsaver {
constructor(completedCallback) {
this.jobQueue = [];
this.done = true;
this.completedCallback = completedCallback;
}
next() {
return this.jobQueue.shift();
}
add(...job) {
if (job == undefined) {
console.log("undefined job");
return;
}
this.jobQueue.push(...job);
this.start();
}
start() {
if (this.done) {
this.done = false;
this.saveJob();
}
}
stop() {
this.done = true;
// have all companies been scraped?
if (companyCompleted()) {
console.log('all done');
this.completedCallback();
}
}
saveJob() {
var job = this.next();
if (job == undefined) { this.stop(); return; }
//insert made up tag
//job.tags = [getTag()]
Job.findOneAndUpdate(
{'url':job.url},
{$set:job,$setOnInsert: {first_seen: new Date()}},
{upsert:true},
(err,doc) => {
if (err) {
console.log(err);
}
else {
if (doc == null) {
console.log("new job added: "+job.title);
} else {
console.log("job updated: "+job.title);
}
}
this.saveJob();
}
);
}
}
/* pull companies from db with hasScraper */
var params = {'hasScraper': true}
if (process.argv[2]) {
params['company'] = process.argv[2];
}
Company.find(params,(err,res)=>{
if (res) {
var js = new jobsaver(()=>process.exit());
res.forEach((company) => {
var scraper = require(`./scrapers/${company.company}`);
console.log('scraping '+company.company);
started(company.company);
var s = new scraper(company);
s.process(
js.add.bind(js),
()=>{completed(company.company)}
)
})
}
})