Skip to content

Commit

Permalink
add manage command to fix language (#118)
Browse files Browse the repository at this point in the history
it will remove `-CA` or `-US` from language.

CPNHUB-227
  • Loading branch information
petrjasek authored Aug 1, 2023
1 parent 0a88e85 commit ddab87b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
Empty file added server/cp/commands/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions server/cp/commands/fix_language.py
Original file line number Diff line number Diff line change
@@ -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(".")
2 changes: 2 additions & 0 deletions server/manage.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit ddab87b

Please sign in to comment.