Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /spraakbanken_karp-backend /repl_scripts /replace.py
| # Does a search and replace on all text fields in a resource. | |
| import sys | |
| from karp.foundation import json | |
| entry_commands.start_transaction() | |
| resource_name = sys.argv[1] | |
| for line in sys.stdin.readlines(): | |
| id, search, replace = line.split() | |
| entry = entry_queries.by_id(resource_name, id) | |
| print(entry.id) | |
| for path in json.all_paths(entry.entry): | |
| value = json.get_path(path, entry.entry) | |
| if isinstance(value, str): | |
| new_value = value.replace(search, replace) | |
| if value != new_value: | |
| print(value, "=>", new_value) | |
| json.set_path(path, new_value, entry.entry) | |
| entry_commands.update_entry(resource_name, entry.id, entry.version, "", "", entry.entry) | |
| entry_commands.commit() | |
Xet Storage Details
- Size:
- 767 Bytes
- Xet hash:
- bf45738d3014a08c6eb158bf4c42da54019398726c4e4bf6713830303adf0418
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.