import logging import json import base64 from dbprocessor import DBProcessor parser = DBProcessor() logging.basicConfig(level=logging.INFO) # First json to postgis, then postgis to database def json_to_database(request): # Extract data from request envelope = json.loads(request.data.decode('utf-8')) payload = base64.b64decode(envelope['message']['data']) # Extract subscription from subscription string try: subscription = envelope['subscription'].split('/')[-1] logging.info(f'Message received from {subscription} [{payload}]') parser.process(json.loads(payload)) except Exception as e: logging.info('Extract of subscription failed') logging.debug(e) raise e # Returning any 2xx status indicates successful receipt of the message. # 204: no content, delivery successfull, no further actions needed return 'OK', 204
import logging import json import base64 from dbprocessor import DBProcessor parser = DBProcessor() def topic_to_datastore(request): # Extract data from request envelope = json.loads(request.data.decode('utf-8')) payload = base64.b64decode(envelope['message']['data']) # Extract subscription from subscription string try: subscription = envelope['subscription'].split('/')[-1] logging.info(f'Message received from {subscription} [{payload}]') parser.process(json.loads(payload)) except Exception as e: logging.info('Extract of subscription failed') logging.debug(e) raise e # Returning any 2xx status indicates successful receipt of the message. # 204: no content, delivery successfull, no further actions needed return 'OK', 204
import logging import json import base64 from dbprocessor import DBProcessor parser = DBProcessor() logging.basicConfig(level=logging.INFO) def topic_to_xml(request): # Extract data from request envelope = json.loads(request.data.decode('utf-8')) payload = base64.b64decode(envelope['message']['data']) # Extract subscription from subscription string try: subscription = envelope['subscription'].split('/')[-1] logging.info(f'Message received from {subscription} [{payload}]') parser.process(json.loads(payload), request) except Exception as e: logging.info('Extract of subscription failed') logging.debug(e) raise e # Returning any 2xx status indicates successful receipt of the message. # 204: no content, delivery successful, no further actions needed return 'OK', 204
import base64 import json import logging import config import googlemaps from google.cloud import datastore from dbprocessor import DBProcessor client = datastore.Client() parser = DBProcessor(client) def topic_to_datastore(request): gmaps = None if hasattr(config, 'GEO_API_KEY'): gmaps = googlemaps.Client(key=config.GEO_API_KEY) # Extract data from request envelope = json.loads(request.data.decode('utf-8')) payload = base64.b64decode(envelope['message']['data']) # Extract subscription from subscription string try: subscription = envelope['subscription'].split('/')[-1] logging.info(f'Message received from {subscription}') parser.process(json.loads(payload), gmaps) except Exception: logging.exception('Extract of subscription failed') # Returning any 2xx status indicates successful receipt of the message.