-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0cf2d5
commit 25bb51b
Showing
7 changed files
with
320 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const { isJobExpired, isSameDay } = require('../utils/isSameDay'); | ||
const settings = require('../model/settings'); | ||
const axios = require('axios'); | ||
const Xjob = require('../model/xjobs'); | ||
|
||
const empllo = async () => { | ||
try { | ||
const API_URL = 'https://empllo.com/api/v1'; | ||
|
||
let LAST_EMPLLO_API_UPDATE = null; | ||
let sameDay = false; | ||
|
||
const settingDoc = await settings.findOne({ name: 'Settings' }); | ||
if (settingDoc) { | ||
LAST_EMPLLO_API_UPDATE = settingDoc.empllo_api_update; | ||
} | ||
|
||
const pingAPI = await axios.get(`${API_URL}?limit=1`); | ||
const get_last_update_at = new Date(pingAPI.data.updated_at * 1000); | ||
|
||
if (LAST_EMPLLO_API_UPDATE != null) { | ||
sameDay = isSameDay(LAST_EMPLLO_API_UPDATE, get_last_update_at); | ||
|
||
const newSetting = await settings.create({ | ||
name: 'Settings', | ||
empllo_api_update: get_last_update_at | ||
}); | ||
await newSetting.save(); | ||
} | ||
|
||
if (sameDay === false) { | ||
console.log('RUNNING......'); | ||
// Fetch jobs | ||
const query = await axios.get(`${API_URL}`).data; | ||
const total_count = query.total_count; | ||
const jobs = query.jobs; | ||
|
||
jobs.forEach(async (job) => { | ||
// check if job has expired | ||
const expireDate = new Date(job.expiryDate * 1000); | ||
const jobExpired = isJobExpired(expireDate); | ||
|
||
if (jobExpired === false) { | ||
const [ | ||
title, | ||
// description, | ||
companyName, | ||
companyLogo, | ||
minSalary, | ||
maxSalary, | ||
seniority, | ||
categories, | ||
publishedDate, | ||
expiryDate, | ||
applicationLink, | ||
jobType, | ||
workModel | ||
] = [ | ||
job.title, | ||
// jobs.excerpt, | ||
job.companyName, | ||
job.companyLogo, | ||
job.minSalary, | ||
job.maxSalary, | ||
job.seniorityLevel, | ||
job.tags, | ||
job.pubDate, | ||
job.expiryDate, | ||
job.applicationLink, | ||
job.jobType, | ||
job.workModel | ||
]; | ||
// create job | ||
const newJob = await Xjob.create( | ||
[ | ||
{ | ||
title, | ||
description, | ||
companyName, | ||
companyLogo, | ||
minSalary, | ||
maxSalary, | ||
seniority, | ||
categories, | ||
publishedDate, | ||
expiryDate, | ||
applicationLink, | ||
jobType, | ||
workModel, | ||
source: 'empllo' | ||
} | ||
], | ||
{ new: true } | ||
); | ||
|
||
await newJob[0].save(); | ||
} | ||
}); | ||
} | ||
|
||
return true; | ||
} catch (error) { | ||
console.log(error); | ||
return false; | ||
} | ||
}; | ||
|
||
module.exports = empllo; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const { isJobExpired, isSameDay } = require('../utils/isSameDay'); | ||
const settings = require('../model/settings'); | ||
const axios = require('axios'); | ||
const Xjob = require('../model/xjobs'); | ||
|
||
const himalayas = async () => { | ||
try { | ||
const API_URL = 'https://himalayas.app/jobs/api'; | ||
|
||
let LAST_HIMALAYAS_API_UPDATE = null; | ||
let sameDay = false; | ||
|
||
const settingDoc = await settings.findOne({ name: 'Settings' }); | ||
if (settingDoc) { | ||
LAST_HIMALAYAS_API_UPDATE = settingDoc.himalayas_api_update; | ||
} | ||
|
||
const pingAPI = await axios.get(`${API_URL}?limit=1`); | ||
const get_last_update_at = new Date(pingAPI.data.updated_at * 1000); | ||
|
||
if (LAST_HIMALAYAS_API_UPDATE != null) { | ||
sameDay = isSameDay(LAST_HIMALAYAS_API_UPDATE, get_last_update_at); | ||
|
||
const newSetting = await settings.create({ | ||
name: 'Settings', | ||
himalayas_api_update: get_last_update_at | ||
}); | ||
await newSetting.save(); | ||
} | ||
|
||
if (sameDay === false) { | ||
console.log('RUNNING......'); | ||
// Fetch jobs | ||
const query = await axios.get(`${API_URL}`).data; | ||
const total_count = query.total_count; | ||
const jobs = query.jobs; | ||
|
||
jobs.forEach(async (job) => { | ||
// check if job has expired | ||
const expireDate = new Date(job.expiryDate * 1000); | ||
const jobExpired = isJobExpired(expireDate); | ||
|
||
if (jobExpired === false) { | ||
const [ | ||
title, | ||
description, | ||
companyName, | ||
companyLogo, | ||
minSalary, | ||
maxSalary, | ||
seniority, | ||
categories, | ||
publishedDate, | ||
expiryDate, | ||
applicationLink | ||
] = [ | ||
job.title, | ||
job.excerpt, | ||
job.companyName, | ||
job.companyLogo, | ||
job.minSalary, | ||
job.maxSalary, | ||
job.seniority, | ||
job.categories, | ||
job.pubDate, | ||
job.expiryDate, | ||
job.applicationLink | ||
]; | ||
// create job | ||
const newJob = await Xjob.create( | ||
[ | ||
{ | ||
title, | ||
description, | ||
companyName, | ||
companyLogo, | ||
minSalary, | ||
maxSalary, | ||
seniority, | ||
categories, | ||
publishedDate, | ||
expiryDate, | ||
applicationLink, | ||
source: 'himalayas' | ||
} | ||
], | ||
{ new: true } | ||
); | ||
|
||
await newJob[0].save(); | ||
} | ||
}); | ||
} | ||
|
||
return true; | ||
} catch (error) { | ||
console.log(error); | ||
return false; | ||
} | ||
}; | ||
|
||
module.exports = himalayas; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const settingSchema = new mongoose.Schema({ | ||
name: { | ||
type: String, | ||
default: 'Settings', | ||
required: false | ||
}, | ||
himalayas_api_update: { | ||
type: String, | ||
required: false | ||
} | ||
}); | ||
|
||
const Settings = mongoose.model('Settings', settingSchema); | ||
|
||
module.exports = Settings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const xjobSchema = new mongoose.Schema({ | ||
title: { | ||
type: String, | ||
required: false | ||
}, | ||
description: { | ||
type: String, | ||
required: false | ||
}, | ||
companyName: { | ||
type: String, | ||
required: false | ||
}, | ||
companyLogo: { | ||
type: String, | ||
required: false | ||
}, | ||
minSalary: { | ||
type: Number, | ||
required: false | ||
}, | ||
maxSalary: { | ||
type: Number, | ||
required: false | ||
}, | ||
seniority: { | ||
type: Array, | ||
required: false | ||
}, | ||
categories: { | ||
type: Array, | ||
required: false | ||
}, | ||
publishedDate: { | ||
type: String, | ||
required: false | ||
}, | ||
expiryDate: { | ||
type: String, | ||
required: false | ||
}, | ||
applicationLink: { | ||
type: String, | ||
required: false | ||
}, | ||
jobType: { | ||
type: String, | ||
required: false | ||
}, | ||
workModel: { | ||
type: String, | ||
required: false | ||
} | ||
}); | ||
|
||
const Xjob = mongoose.model('Xjob', xjobSchema); | ||
|
||
module.exports = Xjob; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const isSameDay = (date1, date2) => { | ||
const givenDate = new Date(date1); | ||
const currentDate = new Date(date2); | ||
|
||
return ( | ||
givenDate.getUTCFullYear() === currentDate.getUTCFullYear() && | ||
givenDate.getUTCMonth() === currentDate.getUTCMonth() && | ||
givenDate.getUTCDate() === currentDate.getUTCDate() | ||
); | ||
}; | ||
|
||
const isJobExpired = (expiryDate) => { | ||
const givenDate = new Date(expiryDate); | ||
const currentDate = new Date(); | ||
|
||
// Normalize both dates to midnight to compare only the date parts | ||
givenDate.setUTCHours(0, 0, 0, 0); | ||
currentDate.setUTCHours(0, 0, 0, 0); | ||
|
||
return givenDate < currentDate; | ||
}; | ||
|
||
module.exports = { | ||
isSameDay, | ||
isJobExpired | ||
}; |