How to do it

In our job listings implementation, we used the following code to determine the host for Elasticsearch:

host = 'localhost'if os.environ.get('ES_HOST'):    host = os.environ.get('ES_HOST')print("ElasticSearch host: " + host)es = Elasticsearch(hosts=[host])

It's a straightforward and simple thing to do, but it's very important for making our app incredibly portable to different environments.  This defaults to using localhost, but lets us define a different host with the ES_HOST environment variable.

The implementation of the skills search also makes a similar change to allow us to change a default of localhost for our scraping microservice:

CONFIG = {'AMQP_URI': "amqp://guest:guest@localhost"}if os.environ.get('JOBS_AMQP_URL'): CONFIG[ ...

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.