From bbfdbc36ff952b3727045655662c0386da64c2c2 Mon Sep 17 00:00:00 2001 From: Micha Moskovic Date: Fri, 29 Nov 2024 16:56:14 +0100 Subject: [PATCH] Add script to move JACoW URLs (#60) * Add script to move JACoW URLs * Auto-format python code --------- Co-authored-by: michamos --- scripts/move-jacow-urls/script.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/move-jacow-urls/script.py diff --git a/scripts/move-jacow-urls/script.py b/scripts/move-jacow-urls/script.py new file mode 100644 index 0000000..848f60e --- /dev/null +++ b/scripts/move-jacow-urls/script.py @@ -0,0 +1,27 @@ +from inspirehep.curation.search_check_do import SearchCheckDo + +OLD_PREFIX = "http://accelconf.web.cern.ch/accelconf/" +NEW_PREFIX = "http://accelconf.web.cern.ch/" + + +class MoveJACOWURLs(SearchCheckDo): + """Move URLs pointing to JETP to new domain.""" + + query = "urls.value:http://accelconf.web.cern.ch/*" + + @staticmethod + def check(record, logger, state): + return any( + value.lower().startswith(OLD_PREFIX) + for value in record.get_value("urls.value", []) + ) + + @staticmethod + def do(record, logger, state): + urls = record.get("urls", []) + for url in urls: + if url["value"].lower().startswith(OLD_PREFIX): + url["value"] = NEW_PREFIX + url["value"][len(OLD_PREFIX) :] + + +MoveJACOWURLs()