def import_from_adzuna(self, job_area, count): """ Method to import jobs from the Adzuna API """ locations = job_area.locations args = list(locations) + [count] az = Adzuna() all_jobs = az.jobs_at_location(*args) for job in all_jobs: obj, created = JobAdvert.get_or_create_from_adzuna(job_area, job) if not created: break
def get_or_create_from_postcode(cls, postcode): az = Adzuna() try: locations = az.locations_for_postcode(postcode) except AssertionError: raise PostcodeNotFoundError() job_centre_label = None for location_label, location_list in settings.LOCATION_LABELS.items(): if list(location_list['locations']) == locations: job_centre_label = location_label break obj, created = cls.objects.get_or_create( locations=locations, job_centre_label=job_centre_label) obj.save() return obj, created
def get_or_create_from_postcode(cls, postcode): az = Adzuna() try: locations = az.locations_for_postcode(postcode) except AssertionError: raise PostcodeNotFoundError() job_centre_label = None for location_label, location_list in settings.LOCATION_LABELS.items(): if list(location_list['locations']) == locations: job_centre_label = location_label break obj, created = cls.objects.get_or_create( locations=locations, job_centre_label=job_centre_label ) obj.save() return obj, created
def test_jobs_at_location(self): az = Adzuna() x = az.jobs_at_location('UK', 'London', 'South East London', 15) self.assertEqual(len(list(x)), 15)
def test_locations_for_valid_postcode(self): az = Adzuna() x = az.locations_for_postcode('SW1H0ET') self.assertEqual(len(list(x)), 3)
def test_locations_for_invalid_postcode(self): az = Adzuna() self.assertRaises(AssertionError, az.locations_for_postcode, 'not a postcode')
def test_top_companies(self): az = Adzuna() x = az.top_companies('UK', 'London', 'South East London', 2) self.assertEqual(len(list(x)), 2)