Skip to content

Commit d8d8664

Browse files
authored
Add script to move Fermilab URLs (#25)
* Add script to move Fermilab URLs * Auto-format python code Co-authored-by: michamos <[email protected]>
1 parent 0015e74 commit d8d8664

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import requests
2+
3+
from inspirehep.curation.search_check_do import SearchCheckDo
4+
5+
FIXED_URLS = requests.get(
6+
"https://cernbox.cern.ch/remote.php/dav/public-files/"
7+
"FVgeaG5VAVx8B09/fermilab_fixed_urls.json"
8+
).json()
9+
10+
11+
class FixFermilabURLs(SearchCheckDo):
12+
"""Rewrite URLs to Fermilab PDFs that have moved."""
13+
14+
query = "urls.value:'ccd.fnal.gov'"
15+
16+
@staticmethod
17+
def check(record, logger, state):
18+
for url in record.get_value("urls.value", []):
19+
if "ccd.fnal.gov" not in url:
20+
continue
21+
if url in FIXED_URLS:
22+
return True
23+
logger.warning("URL not found in translation map", url=url)
24+
return False
25+
26+
@staticmethod
27+
def do(record, logger, state):
28+
for url in record["urls"]:
29+
value = url["value"]
30+
if "ccd.fnal.gov" in value:
31+
url["value"] = FIXED_URLS.get(value, value)
32+
33+
34+
FixFermilabURLs()

0 commit comments

Comments
 (0)