fix_country_0900.py 1.49 KB
Newer Older
1 2
# -*- coding: utf-8 -*-
""" NAME
3
        fix_country_0815 -- Add synonyms for countries
4 5

    SYNOPSIS
6
        fix_country_0815
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

    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

24
        > cd ...limbra/scripts
25
        > ./run script fix_country_0815.py
26
        > ./run script -S limbra_cppm fix_country_0815.py
27 28 29 30 31 32 33 34 35 36 37

    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
38
    for country, values in COUNTRIES:
39 40 41 42 43 44

        idc = get_id(db.countries, country=country)
        if idc is None:
            print country, " is not in the database ?"
            continue

45 46 47 48 49
        # transform values in the list of synonyms
        # remove duplicate entries
        li = values.replace(' ', '').split(',')
        synonyms = list(set(li))
        db(db.countries.id==idc).update(synonyms=synonyms)
50 51 52 53

    rep = raw_input("Commit database change [y/N]: ")
    if rep == "y":
        db.commit()