-
Notifications
You must be signed in to change notification settings - Fork 2
/
evaluate.js
76 lines (66 loc) · 1.77 KB
/
evaluate.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
import mongoose from "mongoose";
import dotenv from "dotenv";
import { Job } from "./models/job.js";
dotenv.config();
const mongoUrl = process.env.MONGO_URI;
const keywords = [
"Junior",
"Graduate/Junior",
"Graduate",
"React",
"Javascript",
"angular",
"Vue",
".net",
"sql",
"node",
"typescript",
"remote",
"work from home",
];
export const evaluate = async () => {
const jobOutput = [];
try {
await mongoose.connect(mongoUrl, {
useNewUrlParser: true,
});
const jobs = await Job.find({
title: {
$regex: "(Junior|Graduate/Junior|Graduate|React|Javascript|Vue|.NET)",
$options: "i", // case insensitive
},
keywords: {
$in: keywords,
},
});
// now for each job we need to work out if it is still valid
for (const job of jobs) {
const dateCrawled = job.dateCrawled;
const listingDate = job.listingDate.replace("d ago", "");
const currentDate = new Date();
const daysElapsed = Math.floor(
(currentDate - dateCrawled) / (24 * 60 * 60 * 1000)
);
const updatedListingDate = parseInt(listingDate) + daysElapsed;
if (updatedListingDate > 30) {
// Skip the job as it's been more than 30 days since the dateCrawled, and the ad won't exist anymore on Seek
continue;
}
// Tighten up the rules for job titles
const jobTitle = job.title.toLowerCase();
if (
!jobTitle.includes("senior") &&
!jobTitle.includes("lead") &&
!jobTitle.includes("manager")
) {
// Process the job
jobOutput.push(job);
}
}
console.log("Jobs from database", jobs);
return jobOutput;
} catch (error) {
console.log("Could not connect to MongoDB:", error);
process.exit(1);
}
};