Exemple #1
0
def create_country_nodes(df):
    n_nodes = 0
    for _, row in df.drop_duplicates(subset=["country"]).iterrows():
        country = Country(name=row["country"])
        country.save()
        n_nodes += 1
    print("created {} nodes".format(n_nodes))
Exemple #2
0
def load_countries():
    property_list = ('name', 'tld', 'abbr' 'phone', 'curr_code', 'curr_name')
    countries = dict()
    with open('./data/countries/country-by-abbreviation.json') as json_file:
        for line in yaml.safe_load(json_file):
            country = dict([('name', line['country']),
                            ('abbr', line['abbreviation'])])
            countries[line['country']] = country

    with open('./data/countries/country-by-domain-tld.json') as json_file:
        for line in yaml.safe_load(json_file):
            if line['country'] in countries:
                country = countries[line['country']]
                if not line['tld'] is None:
                    country['tld'] = line['tld'][1:]

    with open('./data/countries/country-by-currency-code.json') as json_file:
        for line in yaml.safe_load(json_file):
            if line['country'] in countries:
                country = countries[line['country']]
                if not line['currency_code'] is None:
                    country['curr_code'] = line['currency_code']

    with open('./data/countries/country-by-currency-name.json') as json_file:
        for line in yaml.safe_load(json_file):
            if line['country'] in countries:
                country = countries[line['country']]
                if not line['currency_name'] is None:
                    country['curr_name'] = line['currency_name']

    with open('./data/countries/country-by-calling-code.json') as json_file:
        for line in yaml.safe_load(json_file):
            if line['country'] in countries:
                country = countries[line['country']]
                if not line['calling_code'] is None:
                    country['phone'] = line['calling_code']

    start_db()

    for k, v in countries.items():
        country = Country(name=v['name'])
        if 'tld' in v:
            country.tld = v['tld']
        if 'abbr' in v:
            country.abbr = v['abbr']
        if 'phone' in v:
            country.phone = v['phone']
        country.save()

    stop_db()

    print(json.dumps(countries, indent=4, sort_keys=True))
 def POST(self, name):
     """Inserts new country."""
     data = json.loads(web.data())
     country_code = data.get('country_code')
     country_name = data.get('country_name')
     try:
         assert country_code and country_name
     except AssertionError as error:
         logger.debug(error)
         raise Error(BADPARAMS)
     country = Country(country_code, country_name)
     country.save()
     return [country.__dict__]
Exemple #4
0
def load_countries(request, indexfile=""):
    if indexfile == "":
        indexfile = "iso3166codes.csv"

    fin = open(indexfile, 'rb')
    csvin = csv.reader(fin)
    headers = csvin.next()
    for row in csvin:
        print(row[0] + ":" + row[1])
        print(type(row[1]))
        newcountry = Country(ISOalpha3=row[0].decode('latin-1'),
                             ISOname=row[1].decode('latin-1'))
        newcountry.save()
    return HttpResponse("Country details loaded from file " + indexfile)
Exemple #5
0
def load_countries(request, indexfile=""):
    if indexfile == "":
        indexfile = "iso3166codes.csv"

    fin = open(indexfile, 'rb')
    csvin = csv.reader(fin)
    headers = csvin.next()
    for row in csvin:
        print(row[0] + ":" + row[1])
        print(type(row[1]))
        newcountry = Country(ISOalpha3=row[0].decode('latin-1'),
                             ISOname=row[1].decode('latin-1'))
        newcountry.save()
    return HttpResponse("Country details loaded from file "+ indexfile)
    def create(country_name):
        """ Create a new country """
        country = Country(country_name)

        return country.save()