diff --git a/server/cp/commands/__init__.py b/server/cp/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/cp/commands/fix_language.py b/server/cp/commands/fix_language.py new file mode 100644 index 0000000..25c01be --- /dev/null +++ b/server/cp/commands/fix_language.py @@ -0,0 +1,23 @@ + +import time + +from superdesk import get_resource_service +from newsroom.commands.manager import manager + + +@manager.command +def fix_language(resource="items", limit=50, sleep_secs=2): + service = get_resource_service(resource) + + source = {"query": {"terms": {"language": ["en-CA", "en-US", "fr-CA"]}}, "size": 100} + + for i in range(int(limit)): + items = service.search(source) + if not items.count(): + break + for item in items: + updates = {"language": item["language"].split("-")[0]} + service.system_update(item["_id"], updates, item) + print(".", end="", flush=True) + time.sleep(int(sleep_secs)) + print(".") diff --git a/server/manage.py b/server/manage.py index a6ccc73..ad34d7b 100644 --- a/server/manage.py +++ b/server/manage.py @@ -1,6 +1,8 @@ from newsroom.commands import * # noqa from newsroom.commands.manager import manager +from cp.commands.fix_language import fix_language # noqa + if __name__ == "__main__": manager.run()