Commit 8920bf7b authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add script fix_origin.py

parent 3786dc78
......@@ -12,16 +12,13 @@
OPTIONS
-h, --help
Display the help and exit.
EXAMPLE
> cd ...limbra/scripts
> ./run script statistics.py
> run script myapp fix_foreignkey_is_null.py
AUTHOR
R. Le Gac -- Mar 2015
R. Le Gac -- Jan 2021
"""
import logging
......
""" NAME
fix_origin
SYNOPSIS
fix_origin
DESCRIPTION
It happens that origin can contains the wrong OAI_URL:
http://old.inspirehep.net/record/xyz
It is replaced by http://inspirehep.net/record/xyz
OPTIONS
EXAMPLE
> cd ...limbra/scripts
> ./run script myapp fix_origin.py
AUTHOR
R. Le Gac -- Jan 2021
"""
import logging
from plugin_dbui import UNDEF_ID
def cli():
# start logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)
formatter = logging.Formatter(
"%(asctime)s %(levelname)s %(message)s",
datefmt="%H:%M:%S")
logger.handlers[0].setFormatter(formatter)
logger.info(f"scan origin field")
rows = db().iterselect(db.publications.id, db.publications.origin)
for row in rows:
origin = row.origin
if isinstance(origin, str) and "old." in origin:
origin = origin.replace("old.", "")
print(f" fix {row.id} {row.origin}")
dct = dict()
dct["origin"] = origin
db(db.publications.id == row.id).update(**dct)
rep = input("\n Commit change (y/N): ")
if rep in ("y", "Y"):
db.commit()
logger.info("database modified")
if __name__ == "__main__":
cli()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment