66from jobspy import scrape_jobs
77
88import json , csv , os
9+ import base64
10+
11+ parser = reqparse .RequestParser ()
12+ parser .add_argument ('job_url' , required = False , type = str , location = 'args' )
13+ parser .add_argument ('title' , required = True , type = str , location = 'args' )
14+ parser .add_argument ('company' , required = True , type = str , location = 'args' )
15+ parser .add_argument ('location' , required = True , type = str , location = 'args' )
16+ parser .add_argument ('date_posted' , required = True , type = str , location = 'args' )
17+ parser .add_argument ('description' , required = True , type = str , location = 'args' )
918
1019jobs = [ ]
1120
@@ -39,9 +48,32 @@ def get(self, jobtype=None):
3948 except :
4049 return [ ]
4150
42- # def post(self):
43- # args = parser.parse_args()
51+ def post (self ):
52+ args = parser .parse_args ()
53+
54+ job = {
55+ 'id' : f"cm-{ str (hash (args ['title' ] + args ['company' ]))} " ,
56+ 'job_url' : args .get ('job_url' ) or '' ,
57+ 'title' : args ['title' ],
58+ 'company' : args ['company' ],
59+ 'location' : args ['location' ],
60+ 'date_posted' : args ['date_posted' ],
61+ 'description' : args ['description' ]
62+ }
63+
64+ tmp = []
65+ if os .path .exists ('data.json' ):
66+ with open ('data.json' , 'r' , encoding = 'utf-8' ) as file :
67+ tmp = json .load (file )
68+ # append the new jobs to the existing ones
69+ tmp .append (job )
70+ else :
71+ tmp = job
72+
73+ with open ('data.json' , 'w' , encoding = 'utf-8' ) as file :
74+ json .dump (tmp , file , indent = 4 )
4475
76+ return job
4577
4678
4779class RefreshJobs (Resource ):
@@ -52,6 +84,7 @@ def get(self):
5284 if os .path .exists ('data.json' ):
5385 with open ('data.json' , 'r' , encoding = 'utf-8' ) as file :
5486 tmp = json .load (file )
87+ # append the new jobs to the existing ones
5588 tmp += jobs
5689 else :
5790 tmp = jobs
0 commit comments