-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathParseJobs.py
executable file
·78 lines (67 loc) · 2.07 KB
/
ParseJobs.py
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
#!/usr/bin/env python3
import sys
import yaml
from pprint import pprint
from datetime import timedelta, date
def loadYamlFile(file):
with open(file, 'r') as fileStream:
return yaml.safe_load(fileStream)
def saveYamlFile(file, content):
with open(file, 'w') as fileStream:
yaml.dump(content, fileStream, default_flow_style=False)
def flattenJobs(jobsData):
jobs = []
for company_jobs in jobsData:
for date_jobs in company_jobs['jobs']:
for job in date_jobs['jobs']:
jobs.append({
"company": company_jobs['company'],
"post_date": date_jobs['post_date'],
"remote": "remote" in job and job["remote"],
"link": job["link"],
"title": job["title"],
})
return jobs
def convertJobs(jobsData):
# use 6 days instead of 7, because sometimes the post is updated 6.9 days ago
one_week_ago = date.today() - timedelta(days = 6)
companies = {}
newPostings = False
for job in jobsData:
if not job['company'] in companies:
companies[job['company']] = {
"company": job['company'],
"jobs": {
"current": [],
"previous": [],
}
}
new_job = {
"title": job['title'],
"link": job['link'],
"remote": job['remote'],
}
if job['post_date'] >= one_week_ago:
newPostings = True
companies[job['company']]['jobs']['current'].append(new_job)
else:
companies[job['company']]['jobs']['previous'].append(new_job)
return ([*companies.values()], newPostings)
if __name__ == '__main__':
if len(sys.argv) < 2:
path = './'
elif sys.argv[1][-1] == '/':
path = sys.argv[1]
else:
path = sys.argv[1] + '/'
jobsFile = f'{path}_data/jobs.yml'
newJobsFile = f'{path}_data/jobs-sorted.yml'
jobsData = loadYamlFile(jobsFile)
flattenedJobs = flattenJobs(jobsData)
flattenedJobs.sort(key=lambda x: x['post_date'], reverse = True)
(convertedJobs, newPostings) = convertJobs(flattenedJobs)
saveYamlFile(newJobsFile, {
"newPostings": newPostings,
"updateDate": date.today(),
"jobs": convertedJobs
})