generated from superdesk/newsroom-app
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add manage command to fix language (#118)
it will remove `-CA` or `-US` from language. CPNHUB-227
- Loading branch information
Showing
3 changed files
with
25 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |