Пример #1
0
    def post(self):

        # Move to logging default namespace
        previous_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('dedupe_log')
        current_namespace = namespace_manager.get_namespace()

        # Get parameters from request body
        params = json.loads(self.request.body)

        # Add "client" parameter
        params['client'] = CLIENT

        # Parse event coordinates
        latlon = params.pop('latlon')
        if latlon and latlon != "None":
            params['lat'], params['lon'] = map(float, latlon.split(","))
        else:
            params['lat'] = None
            params['lon'] = None

        # Build and store LogEntry entity in default namespace
        log_entry = LogEntry(**params)
        log_entry_key = log_entry.put()

        # Restore previous namespace
        namespace_manager.set_namespace(previous_namespace)

        # Send response and finish call
        resp = {
            "result": "success",
            "message": "new log entry successfully added",
            "namespace": current_namespace,
            "logger_version": LOGGER_VERSION,
            "log_entry_key": log_entry_key.id(),
            "log_entry": params
        }
        logging.info(resp)
        return
Пример #2
0
    def post(self):

        # Move to default namespace
        previous_namespace = namespace_manager.get_namespace()
        namespace_manager.set_namespace('query_log')
        current_namespace = namespace_manager.get_namespace()

        # Get parameters from request body

        params = json.loads(self.request.body)

        # Add "client" parameter

        params['client'] = CLIENT

        # Parse event coordinates

        latlon = params.pop('latlon')
        if latlon:
            params['lat'], params['lon'] = map(float, latlon.split(","))
        else:
            params['lat'] = None
            params['lon'] = None

        # Remove "results_by_resource" from parameters for independent process

        res_counts = params.pop('res_counts')

        # Transform "matching_records" to <str> (for ">10000" entries)

        params['matching_records'] = str(params['matching_records'])

        # Build and store LogEntry entity in default namespace

        log_entry = LogEntry(**params)
        log_entry_key = log_entry.put()

        # Process results_by_resource

        if res_counts:
            res_counts = json.loads(res_counts)
            params['results_by_resource'] = []
            for i in res_counts:
                r = ResourceLogEntry(id=i,
                                     parent=log_entry_key,
                                     count=res_counts[i])
                params['results_by_resource'].append(r)

        # Update LogEntry entity (only if existing results_by_resource)

            log_entry = log_entry_key.get()
            log_entry.results_by_resource = params['results_by_resource']
            log_entry_key = log_entry.put()

        # Restore previous namespace

        namespace_manager.set_namespace(previous_namespace)

        # Send response and finish call

        resp = {
            "result": "success",
            "message": "new log entry successfully added",
            "namespace": current_namespace,
            "logger_version": LOGGER_VERSION,
            "log_entry_key": log_entry.key.id(),
            "log_entry": params
        }
        logging.info(resp)
        return
Пример #3
0
def writeCrawlLog(links, isFinished, jobID):
    logEntry = LogEntry(record=links, crawlFinished=isFinished, jobID=jobID)
    logEntry.put()