Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
add schema and Python for countries
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Apr 30, 2016
1 parent 4a1097b commit fd1ca95
Show file tree
Hide file tree
Showing 5 changed files with 282 additions and 2 deletions.
18 changes: 18 additions & 0 deletions gratipay/models/country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import absolute_import, division, print_function, unicode_literals

from postgres.orm import Model


class Country(Model):
"""Represent country records from our database (read-only).
:var int id: the record's primary key in our ``countries`` table
:var unicode name: the name of the country
:var unicode code2: the country's `ISO 3166-1 alpha-2`_ code
:var unicode code3: the country's `ISO 3166-1 alpha-3`_ code
.. _ISO 3166-1 alpha-2 : https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
.. _ISO 3166-1 alpha-3 : https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
"""
typname = 'countries'
2 changes: 1 addition & 1 deletion gratipay/testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Harness(unittest.TestCase):
db = client.website.db
platforms = client.website.platforms
tablenames = db.all("SELECT tablename FROM pg_tables "
"WHERE schemaname='public'")
"WHERE schemaname='public' AND tablename != 'countries'")
seq = itertools.count(0)


Expand Down
3 changes: 2 additions & 1 deletion gratipay/wireup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from gratipay.elsewhere.venmo import Venmo
from gratipay.models.account_elsewhere import AccountElsewhere
from gratipay.models.community import Community
from gratipay.models.country import Country
from gratipay.models.exchange_route import ExchangeRoute
from gratipay.models.participant import Participant
from gratipay.models.team import Team
Expand All @@ -54,7 +55,7 @@ def db(env):
maxconn = env.database_maxconn
db = GratipayDB(dburl, maxconn=maxconn)

for model in (AccountElsewhere, Community, ExchangeRoute, Participant, Team):
for model in (AccountElsewhere, Community, Country, ExchangeRoute, Participant, Team):
db.register_model(model)
gratipay.billing.payday.Payday.db = db

Expand Down
8 changes: 8 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE countries -- http://www.iso.org/iso/country_codes
( id bigserial primary key
, code2 text NOT NULL UNIQUE
, code3 text NOT NULL UNIQUE
, name text NOT NULL UNIQUE
);

\i sql/countries.sql
253 changes: 253 additions & 0 deletions sql/countries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
-- scraped from https://www.iso.org/obp/ui/#search
INSERT INTO countries
(code2, code3, name)
VALUES ('AD', 'AND', 'Andorra')
, ('AE', 'ARE', 'United Arab Emirates (the)')
, ('AF', 'AFG', 'Afghanistan')
, ('AG', 'ATG', 'Antigua and Barbuda')
, ('AI', 'AIA', 'Anguilla')
, ('AL', 'ALB', 'Albania')
, ('AM', 'ARM', 'Armenia')
, ('AO', 'AGO', 'Angola')
, ('AQ', 'ATA', 'Antarctica')
, ('AR', 'ARG', 'Argentina')
, ('AS', 'ASM', 'American Samoa')
, ('AT', 'AUT', 'Austria')
, ('AU', 'AUS', 'Australia')
, ('AW', 'ABW', 'Aruba')
, ('AX', 'ALA', 'Åland Islands')
, ('AZ', 'AZE', 'Azerbaijan')
, ('BA', 'BIH', 'Bosnia and Herzegovina')
, ('BB', 'BRB', 'Barbados')
, ('BD', 'BGD', 'Bangladesh')
, ('BE', 'BEL', 'Belgium')
, ('BF', 'BFA', 'Burkina Faso')
, ('BG', 'BGR', 'Bulgaria')
, ('BH', 'BHR', 'Bahrain')
, ('BI', 'BDI', 'Burundi')
, ('BJ', 'BEN', 'Benin')
, ('BL', 'BLM', 'Saint Barthélemy')
, ('BM', 'BMU', 'Bermuda')
, ('BN', 'BRN', 'Brunei Darussalam')
, ('BO', 'BOL', 'Bolivia (Plurinational State of)')
, ('BQ', 'BES', 'Bonaire, Sint Eustatius and Saba')
, ('BR', 'BRA', 'Brazil')
, ('BS', 'BHS', 'Bahamas (the)')
, ('BT', 'BTN', 'Bhutan')
, ('BV', 'BVT', 'Bouvet Island')
, ('BW', 'BWA', 'Botswana')
, ('BY', 'BLR', 'Belarus')
, ('BZ', 'BLZ', 'Belize')
, ('CA', 'CAN', 'Canada')
, ('CC', 'CCK', 'Cocos (Keeling) Islands (the)')
, ('CD', 'COD', 'Congo (the Democratic Republic of the)')
, ('CF', 'CAF', 'Central African Republic (the)')
, ('CG', 'COG', 'Congo (the)')
, ('CH', 'CHE', 'Switzerland')
, ('CI', 'CIV', 'Côte dIvoire')
, ('CK', 'COK', 'Cook Islands (the)')
, ('CL', 'CHL', 'Chile')
, ('CM', 'CMR', 'Cameroon')
, ('CN', 'CHN', 'China')
, ('CO', 'COL', 'Colombia')
, ('CR', 'CRI', 'Costa Rica')
, ('CU', 'CUB', 'Cuba')
, ('CV', 'CPV', 'Cabo Verde')
, ('CW', 'CUW', 'Curaçao')
, ('CX', 'CXR', 'Christmas Island')
, ('CY', 'CYP', 'Cyprus')
, ('CZ', 'CZE', 'Czech Republic (the)')
, ('DE', 'DEU', 'Germany')
, ('DJ', 'DJI', 'Djibouti')
, ('DK', 'DNK', 'Denmark')
, ('DM', 'DMA', 'Dominica')
, ('DO', 'DOM', 'Dominican Republic (the)')
, ('DZ', 'DZA', 'Algeria')
, ('EC', 'ECU', 'Ecuador')
, ('EE', 'EST', 'Estonia')
, ('EG', 'EGY', 'Egypt')
, ('EH', 'ESH', 'Western Sahara*')
, ('ER', 'ERI', 'Eritrea')
, ('ES', 'ESP', 'Spain')
, ('ET', 'ETH', 'Ethiopia')
, ('FI', 'FIN', 'Finland')
, ('FJ', 'FJI', 'Fiji')
, ('FK', 'FLK', 'Falkland Islands (the) [Malvinas]')
, ('FM', 'FSM', 'Micronesia (Federated States of)')
, ('FO', 'FRO', 'Faroe Islands (the)')
, ('FR', 'FRA', 'France')
, ('GA', 'GAB', 'Gabon')
, ('GB', 'GBR', 'United Kingdom of Great Britain and Northern Ireland (the)')
, ('GD', 'GRD', 'Grenada')
, ('GE', 'GEO', 'Georgia')
, ('GF', 'GUF', 'French Guiana')
, ('GG', 'GGY', 'Guernsey')
, ('GH', 'GHA', 'Ghana')
, ('GI', 'GIB', 'Gibraltar')
, ('GL', 'GRL', 'Greenland')
, ('GM', 'GMB', 'Gambia (the)')
, ('GN', 'GIN', 'Guinea')
, ('GP', 'GLP', 'Guadeloupe')
, ('GQ', 'GNQ', 'Equatorial Guinea')
, ('GR', 'GRC', 'Greece')
, ('GS', 'SGS', 'South Georgia and the South Sandwich Islands')
, ('GT', 'GTM', 'Guatemala')
, ('GU', 'GUM', 'Guam')
, ('GW', 'GNB', 'Guinea-Bissau')
, ('GY', 'GUY', 'Guyana')
, ('HK', 'HKG', 'Hong Kong')
, ('HM', 'HMD', 'Heard Island and McDonald Islands')
, ('HN', 'HND', 'Honduras')
, ('HR', 'HRV', 'Croatia')
, ('HT', 'HTI', 'Haiti')
, ('HU', 'HUN', 'Hungary')
, ('ID', 'IDN', 'Indonesia')
, ('IE', 'IRL', 'Ireland')
, ('IL', 'ISR', 'Israel')
, ('IM', 'IMN', 'Isle of Man')
, ('IN', 'IND', 'India')
, ('IO', 'IOT', 'British Indian Ocean Territory (the)')
, ('IQ', 'IRQ', 'Iraq')
, ('IR', 'IRN', 'Iran (Islamic Republic of)')
, ('IS', 'ISL', 'Iceland')
, ('IT', 'ITA', 'Italy')
, ('JE', 'JEY', 'Jersey')
, ('JM', 'JAM', 'Jamaica')
, ('JO', 'JOR', 'Jordan')
, ('JP', 'JPN', 'Japan')
, ('KE', 'KEN', 'Kenya')
, ('KG', 'KGZ', 'Kyrgyzstan')
, ('KH', 'KHM', 'Cambodia')
, ('KI', 'KIR', 'Kiribati')
, ('KM', 'COM', 'Comoros (the)')
, ('KN', 'KNA', 'Saint Kitts and Nevis')
, ('KP', 'PRK', 'Korea (the Democratic Peoples Republic of)')
, ('KR', 'KOR', 'Korea (the Republic of)')
, ('KW', 'KWT', 'Kuwait')
, ('KY', 'CYM', 'Cayman Islands (the)')
, ('KZ', 'KAZ', 'Kazakhstan')
, ('LA', 'LAO', 'Lao Peoples Democratic Republic (the)')
, ('LB', 'LBN', 'Lebanon')
, ('LC', 'LCA', 'Saint Lucia')
, ('LI', 'LIE', 'Liechtenstein')
, ('LK', 'LKA', 'Sri Lanka')
, ('LR', 'LBR', 'Liberia')
, ('LS', 'LSO', 'Lesotho')
, ('LT', 'LTU', 'Lithuania')
, ('LU', 'LUX', 'Luxembourg')
, ('LV', 'LVA', 'Latvia')
, ('LY', 'LBY', 'Libya')
, ('MA', 'MAR', 'Morocco')
, ('MC', 'MCO', 'Monaco')
, ('MD', 'MDA', 'Moldova (the Republic of)')
, ('ME', 'MNE', 'Montenegro')
, ('MF', 'MAF', 'Saint Martin (French part)')
, ('MG', 'MDG', 'Madagascar')
, ('MH', 'MHL', 'Marshall Islands (the)')
, ('MK', 'MKD', 'Macedonia (the former Yugoslav Republic of)')
, ('ML', 'MLI', 'Mali')
, ('MM', 'MMR', 'Myanmar')
, ('MN', 'MNG', 'Mongolia')
, ('MO', 'MAC', 'Macao')
, ('MP', 'MNP', 'Northern Mariana Islands (the)')
, ('MQ', 'MTQ', 'Martinique')
, ('MR', 'MRT', 'Mauritania')
, ('MS', 'MSR', 'Montserrat')
, ('MT', 'MLT', 'Malta')
, ('MU', 'MUS', 'Mauritius')
, ('MV', 'MDV', 'Maldives')
, ('MW', 'MWI', 'Malawi')
, ('MX', 'MEX', 'Mexico')
, ('MY', 'MYS', 'Malaysia')
, ('MZ', 'MOZ', 'Mozambique')
, ('NA', 'NAM', 'Namibia')
, ('NC', 'NCL', 'New Caledonia')
, ('NE', 'NER', 'Niger (the)')
, ('NF', 'NFK', 'Norfolk Island')
, ('NG', 'NGA', 'Nigeria')
, ('NI', 'NIC', 'Nicaragua')
, ('NL', 'NLD', 'Netherlands (the)')
, ('NO', 'NOR', 'Norway')
, ('NP', 'NPL', 'Nepal')
, ('NR', 'NRU', 'Nauru')
, ('NU', 'NIU', 'Niue')
, ('NZ', 'NZL', 'New Zealand')
, ('OM', 'OMN', 'Oman')
, ('PA', 'PAN', 'Panama')
, ('PE', 'PER', 'Peru')
, ('PF', 'PYF', 'French Polynesia')
, ('PG', 'PNG', 'Papua New Guinea')
, ('PH', 'PHL', 'Philippines (the)')
, ('PK', 'PAK', 'Pakistan')
, ('PL', 'POL', 'Poland')
, ('PM', 'SPM', 'Saint Pierre and Miquelon')
, ('PN', 'PCN', 'Pitcairn')
, ('PR', 'PRI', 'Puerto Rico')
, ('PS', 'PSE', 'Palestine, State of')
, ('PT', 'PRT', 'Portugal')
, ('PW', 'PLW', 'Palau')
, ('PY', 'PRY', 'Paraguay')
, ('QA', 'QAT', 'Qatar')
, ('RE', 'REU', 'Réunion')
, ('RO', 'ROU', 'Romania')
, ('RS', 'SRB', 'Serbia')
, ('RU', 'RUS', 'Russian Federation (the)')
, ('RW', 'RWA', 'Rwanda')
, ('SA', 'SAU', 'Saudi Arabia')
, ('SB', 'SLB', 'Solomon Islands')
, ('SC', 'SYC', 'Seychelles')
, ('SD', 'SDN', 'Sudan (the)')
, ('SE', 'SWE', 'Sweden')
, ('SG', 'SGP', 'Singapore')
, ('SH', 'SHN', 'Saint Helena, Ascension and Tristan da Cunha')
, ('SI', 'SVN', 'Slovenia')
, ('SJ', 'SJM', 'Svalbard and Jan Mayen')
, ('SK', 'SVK', 'Slovakia')
, ('SL', 'SLE', 'Sierra Leone')
, ('SM', 'SMR', 'San Marino')
, ('SN', 'SEN', 'Senegal')
, ('SO', 'SOM', 'Somalia')
, ('SR', 'SUR', 'Suriname')
, ('SS', 'SSD', 'South Sudan')
, ('ST', 'STP', 'Sao Tome and Principe')
, ('SV', 'SLV', 'El Salvador')
, ('SX', 'SXM', 'Sint Maarten (Dutch part)')
, ('SY', 'SYR', 'Syrian Arab Republic')
, ('SZ', 'SWZ', 'Swaziland')
, ('TC', 'TCA', 'Turks and Caicos Islands (the)')
, ('TD', 'TCD', 'Chad')
, ('TF', 'ATF', 'French Southern Territories (the)')
, ('TG', 'TGO', 'Togo')
, ('TH', 'THA', 'Thailand')
, ('TJ', 'TJK', 'Tajikistan')
, ('TK', 'TKL', 'Tokelau')
, ('TL', 'TLS', 'Timor-Leste')
, ('TM', 'TKM', 'Turkmenistan')
, ('TN', 'TUN', 'Tunisia')
, ('TO', 'TON', 'Tonga')
, ('TR', 'TUR', 'Turkey')
, ('TT', 'TTO', 'Trinidad and Tobago')
, ('TV', 'TUV', 'Tuvalu')
, ('TW', 'TWN', 'Taiwan (Province of China)')
, ('TZ', 'TZA', 'Tanzania, United Republic of')
, ('UA', 'UKR', 'Ukraine')
, ('UG', 'UGA', 'Uganda')
, ('UM', 'UMI', 'United States Minor Outlying Islands (the)')
, ('US', 'USA', 'United States of America (the)')
, ('UY', 'URY', 'Uruguay')
, ('UZ', 'UZB', 'Uzbekistan')
, ('VA', 'VAT', 'Holy See (the)')
, ('VC', 'VCT', 'Saint Vincent and the Grenadines')
, ('VE', 'VEN', 'Venezuela (Bolivarian Republic of)')
, ('VG', 'VGB', 'Virgin Islands (British)')
, ('VI', 'VIR', 'Virgin Islands (U.S.)')
, ('VN', 'VNM', 'Viet Nam')
, ('VU', 'VUT', 'Vanuatu')
, ('WF', 'WLF', 'Wallis and Futuna')
, ('WS', 'WSM', 'Samoa')
, ('YE', 'YEM', 'Yemen')
, ('YT', 'MYT', 'Mayotte')
, ('ZA', 'ZAF', 'South Africa')
, ('ZM', 'ZMB', 'Zambia')
, ('ZW', 'ZWE', 'Zimbabwe')
;

0 comments on commit fd1ca95

Please sign in to comment.