diff options
author | Ruben Rodriguez <ruben@trisquel.info> | 2022-09-08 20:40:21 -0400 |
---|---|---|
committer | Ruben Rodriguez <ruben@trisquel.info> | 2022-09-08 20:40:21 -0400 |
commit | c33290316ff738f5d92f8c3755ce1a220e623900 (patch) | |
tree | 2b8449d20d034f348351ac0eb32cafc876fb9438 /tools | |
parent | 34d10f8767c087221798c33410abc75d4da96c9b (diff) |
Fixed json processing to match upstream changes
Diffstat (limited to 'tools')
-rw-r--r-- | tools/process-json-files.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/tools/process-json-files.py b/tools/process-json-files.py index a20de40..3a3bde1 100644 --- a/tools/process-json-files.py +++ b/tools/process-json-files.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python3 -# +#! /usr/bin/python3 + # Copyright (C) 2020, 2021 grizzlyuser <grizzlyuser@protonmail.com> -# Copyright (C) 2020, 2021 Ruben Rodriguez <ruben@trisquel.info> +# Copyright (C) 2020, 2021 Ruben Rodriguez <ruben@gnu.org> # Copyright (C) 2021 Amin Bandali <bandali@gnu.org> # # This program is free software; you can redistribute it and/or modify @@ -18,7 +18,6 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - import json import sys import time @@ -53,10 +52,18 @@ class RemoteSettings: DUMPS_PATH_ABSOLUTE = arguments.MAIN_PATH / DUMPS_PATH_RELATIVE _WRAPPER_NAME = 'data' + _LAST_MODIFIED_KEY_NAME = 'last_modified' + + @classmethod + def get_collection_timestamp(cls, collection): + return max((record[cls._LAST_MODIFIED_KEY_NAME] + for record in collection.content), default=0) @classmethod def wrap(cls, processed): - return File(processed.path, {cls._WRAPPER_NAME: processed.content}) + return File(processed.path, + {cls._WRAPPER_NAME: processed.content, + 'timestamp': cls.get_collection_timestamp(processed)}) @classmethod def unwrap(cls, parsed_jsons): @@ -90,13 +97,15 @@ class RemoteSettings: while timestamp in timestamps: timestamp += 1 timestamps.append(timestamp) - record['last_modified'] = timestamp + record[cls._LAST_MODIFIED_KEY_NAME] = timestamp if parsed_schema is not None: validate(record, schema=parsed_schema) result.append(record) + result.sort( + key=lambda record: record[cls._LAST_MODIFIED_KEY_NAME], reverse=True) cls.OUTPUT_PATH.parent.mkdir(parents=True, exist_ok=True) return File(cls.OUTPUT_PATH, result) @@ -111,7 +120,7 @@ class RemoteSettings: class Changes(RemoteSettings): JSON_PATHS = tuple(RemoteSettings.DUMPS_PATH_ABSOLUTE.glob('*/*.json')) - OUTPUT_PATH = RemoteSettings.DUMPS_PATH_ABSOLUTE / 'monitor/changes.json' + OUTPUT_PATH = RemoteSettings.DUMPS_PATH_ABSOLUTE / 'monitor/changes' @classmethod def wrap(cls, processed): @@ -126,8 +135,8 @@ class Changes(RemoteSettings): for collection in unwrapped_jsons: if collection.path != RemoteSettings.DUMPS_PATH_ABSOLUTE / 'main/example.json': latest_change = {} - latest_change['last_modified'] = max( - (record['last_modified'] for record in collection.content), default=0) + latest_change[cls._LAST_MODIFIED_KEY_NAME] = cls.get_collection_timestamp( + collection) latest_change['bucket'] = collection.path.parent.name latest_change['collection'] = collection.path.stem changes.append(latest_change) |