Commit 89b705f9 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the script fix-country-0815.py.

parent 1f89f74f
# -*- coding: utf-8 -*-
""" NAME
fix-country -- fix invalid country names
fix-country-0808 -- fix invalid country names
SYNOPSIS
fix-country [options]
DESCRIPTION
Before the track_publications 0.8.8, the name of the country
for a conference is defined by the user or by harvesters.
As the result, the database contains a mixture of French and
English name for country. In addition, some value are wrong.
Starting with version 0.8.8, the database is populated with
a list of countries, in English, coming from a geographical
database. A standard user or an harvesters can no longer add
a country in the database.
The aim of this script, is to replace invalid name by the
correct one and to remove bad ones.
At the end of this process, the database should only contains
official country names.
OPTIONS
EXAMPLE
> cd ... /track_publications/scripts
> ./track_publications fix-country.py
> ./run script fix-country-0808.py
> ./run script -S track_publications_cppm fix-country-0808.py
AUTHOR
R. Le Gac -- Nov 2014
"""
if __name__ == "__main__":
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 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
# 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]: ")
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(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-country-0815 -- Add synonyms for countries
SYNOPSIS
fix-country-0815
DESCRIPTION
Starting with version 0.8.8, the database is populated with
a list of countries, in English, coming from a geographical
database. A standard user or an harvesters can no longer add
a country in the database.
In version 0.8.15, the field synonyms is added to the country
table. It contains the ISO(3)(numeric) country code(s) as well as the
and FIPS (Federal Information Processing Standard) value.
The aim of this script, is to add the synonyms.
OPTIONS
EXAMPLE
> cd ... /track_publications/scripts
> ./run script fix-country-0815.py
> ./run script -S track_publications_cppm fix-country-0815.py
AUTHOR
R. Le Gac -- Oct 2015
"""
if __name__ == "__main__":
from countries import COUNTRIES
from plugin_dbui import get_id, UNDEF_ID
print "\nScanning countries in ", db._uri
for country, synonym in COUNTRIES:
idc = get_id(db.countries, country=country)
if idc is None:
print country, " is not in the database ?"
continue
db(db.countries.id==idc).update(synonyms=synonym)
rep = raw_input("Commit database change [y/N]: ")
if rep == "y":
db.commit()
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