Commit 82d11e87 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the scripts fix-conference-url and fix-report-number.

parent 9f1c8a0d
# -*- coding: utf-8 -*-
""" NAME
fix-conference-url
SYNOPSIS
fix the publications field conference_url
DESCRIPTION
Check the field conference_url in the invenio store and update it.
From time to time, it has been forgotten.
OPTIONS
-h, --help
Display the help and exit.
EXAMPLE
> cd ...track_publications/scripts
> ./track_publications fix-conference-url
AUTHOR
R. Le Gac -- Dec 2014
"""
if __name__ == "__main__":
import re
import sys
from argparse import ArgumentParser, FileType
from invenio_tools import CheckAndFix, CheckException, InvenioStore, Marc12
REG_ORIGIN = re.compile("http://([a-z\.]+)/record/(\d+)")
# command line options
parser = ArgumentParser()
args = parser.parse_args()
# unlock the publications update when the status is OK
db.publications._before_update.remove(INHIBIT_PUBLICATION_UPDATE_ON_OK)
# service
check = CheckAndFix()
decode = Marc12()
# scan the publications table
query = db.publications.origin.len() > 0
query &= db.publications.conference_url.len() == 0
query &= (db.publications.id_categories == 7) | (db.publications.id_categories == 9)
for row in db(query).select():
m = REG_ORIGIN.match(row.origin)
if not m:
continue
host, store_id = m.groups()
# retrieve the full record from the store
store = InvenioStore(host)
xml = store.get_record(store_id)
record = decode(xml)[0]
try:
check.conference(record)
except CheckException, e:
pass
val = record.conference_url()
if val:
print " - %s, conference url: %s" % (row.id, val)
db(db.publications.id==row.id).update(conference_url=val)
db.commit()
# close
sys.exit(0)
......@@ -33,47 +33,49 @@
R. Le Gac -- Nov 2014
"""
from callbacks import INHIBIT_PUBLICATION_UPDATE_ON_OK
from countries import COUNTRIES
from plugin_dbui import get_id, UNDEF_ID
# unlock the publications update when the status is OK
db.publications._before_update.remove(INHIBIT_PUBLICATION_UPDATE_ON_OK)
# scan the database to find invalid countries
for row in db(db.countries).select():
if __name__ == "__main__":
if row.country in COUNTRIES or row.id == UNDEF_ID:
continue
from callbacks import INHIBIT_PUBLICATION_UPDATE_ON_OK
# replacement value for the country
old_country = row.country
new_country = raw_input("\nReplacement for '%s' [to skip CR]: " % old_country)
from countries import COUNTRIES
from plugin_dbui import get_id, UNDEF_ID
if not new_country:
continue
# is the new value valid ?
id_old = get_id(db.countries, country=old_country)
id_new = get_id(db.countries, country=new_country)
# unlock the publications update when the status is OK
db.publications._before_update.remove(INHIBIT_PUBLICATION_UPDATE_ON_OK)
if not id_new:
continue
print "%s will be replaced by %s" % (old_country, new_country)
rep = raw_input("Ok to continue [y/N]: ")
if rep != "y":
continue
# scan the database to find invalid countries
for row in db(db.countries).select():
if row.country in COUNTRIES or row.id == UNDEF_ID:
continue
# replacement value for the country
old_country = row.country
new_country = raw_input("\nReplacement for '%s' [to skip CR]: " % old_country)
if not new_country:
continue
# modify publications
for row in db(db.publications.id_countries==id_old).select():
print " - ", row.id, row.title
db(db.publications.id==row.id).update(id_countries=id_new)
db.commit()
# is the new value valid ?
id_old = get_id(db.countries, country=old_country)
id_new = get_id(db.countries, country=new_country)
if not id_new:
continue
print "%s will be replaced by %s" % (old_country, new_country)
rep = raw_input("Ok to continue [y/N]: ")
# delete the old value
db(db.countries.id==id_old).delete()
db.commit()
if rep != "y":
continue
# modify publications
for row in db(db.publications.id_countries==id_old).select():
print " - ", row.id, row.title
db(db.publications.id==row.id).update(id_countries=id_new)
db.commit()
# delete the old value
db(db.countries.id==id_old).delete()
db.commit()
\ No newline at end of file
# -*- coding: utf-8 -*-
""" NAME
fix-report-number
SYNOPSIS
fix the publications field report-numbers
DESCRIPTION
Check the field report-numbers in the invenio store and update it.
From time to time, it has been forgotten.
OPTIONS
-h, --help
Display the help and exit.
EXAMPLE
> cd ...track_publications/scripts
> ./track_publications fix-report-number
AUTHOR
R. Le Gac -- Dec 2014
"""
if __name__ == "__main__":
import re
import sys
from argparse import ArgumentParser, FileType
from invenio_tools import InvenioStore, Marc12
REG_ORIGIN = re.compile("http://([a-z\.]+)/record/(\d+)")
# command line options
parser = ArgumentParser()
args = parser.parse_args()
# unlock the publications update when the status is OK
db.publications._before_update.remove(INHIBIT_PUBLICATION_UPDATE_ON_OK)
# service
decode = Marc12()
# scan the publications table
query = db.publications.origin.len() > 0
query &= db.publications.report_numbers.len() == 0
for row in db(query).select():
m = REG_ORIGIN.match(row.origin)
if not m:
continue
host, store_id = m.groups()
# retrieve the full record from the store
store = InvenioStore(host)
xml = store.get_record(store_id)
record = decode(xml)[0]
val = record.report_number()
if val:
print " - %s, report number(s): %s" % (row.id, val)
db(db.publications.id==row.id).update(report_numbers=val)
db.commit()
# close
sys.exit(0)
......@@ -19,7 +19,7 @@ HEAD
- Redesing the lists and metrics interfaces as well as metric view.
- Remove obsolete controller toolbox. It is now replaced by standalone
scripts: export-to-csv, import-from-csv, fix-conference-dates, fix-country,
fix-defense, fix-submitted
fix-defense, ifix-report-number, fix-submitted.
- The list of country is almost frozen by using the default list coming
from a geographical database (www.geonames.org).
Harvester can not add country anymore.
......
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