How to do it

We will make a few small changes to our API code.  The code from the previous recipe has been copied into 09/04/api.py, with the few modifications made. 

  1. First, we add an import for elasticsearch-py:
from elasticsearch import Elasticsearch
  1. Now we make a quick modification to the get method of the JobListing class (I've done the same in JobListingSkills, but it's omitted here for brevity):
class JobListing(Resource):    def get(self, job_listing_id):        print("Request for job listing with id: " + job_listing_id)        listing = get_job_listing_info(job_listing_id)        es = Elasticsearch()        es.index(index='joblistings', doc_type='job-listing', id=job_listing_id, body=listing)        print("Got the following listing as a response: " + listing)        return ...

Get Python Web Scraping Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.