This commit is contained in:
Gabriel Augendre 2021-08-18 16:32:08 +02:00
parent 78859c7c08
commit c6f2327d2a
5 changed files with 37240 additions and 0 deletions

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module insee_number_translator
go 1.16

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,275 @@
package main
var CONTINENTS = map[string]string{
"1": "Europe",
"2": "Asie",
"3": "Afrique",
"4": "Amérique",
"5": "Océanie",
}
var COUNTRIES = map[string][]string{
"99125": {"ALBANIE"},
"99109": {"ALLEMAGNE"},
"99130": {"ANDORRE"},
"99110": {"AUTRICHE"},
"99131": {"BELGIQUE"},
"99148": {"BIELORUSSIE"},
"99118": {"BOSNIE-HERZEGOVINE"},
"99111": {"BULGARIE"},
"99119": {"CROATIE"},
"99101": {"DANEMARK", "FEROE (ILES)"},
"99134": {"ESPAGNE"},
"99106": {"ESTONIE"},
"99156": {"EX-REPUBLIQUE YOUGOSLAVE DE MACEDOINE"},
"99105": {"FINLANDE"},
"99133": {"GIBRALTAR"},
"99126": {"GRECE"},
"99132": {"ROYAUME-UNI", "GUERNESEY", "JERSEY", "MAN (ILE)"},
"99112": {"HONGRIE"},
"99136": {"IRLANDE, ou EIRE"},
"99102": {"ISLANDE"},
"99127": {"ITALIE"},
"99157": {"KOSOVO"},
"99107": {"LETTONIE"},
"99113": {"LIECHTENSTEIN"},
"99108": {"LITUANIE"},
"99137": {"LUXEMBOURG"},
"99144": {"MALTE"},
"99151": {"MOLDAVIE"},
"99138": {"MONACO"},
"99120": {"MONTENEGRO"},
"99103": {"NORVEGE", "BOUVET (ILE)", "SVALBARD et ILE JAN MAYEN"},
"99135": {"PAYS-BAS", "ARUBA"},
"99122": {"POLOGNE"},
"99139": {"PORTUGAL"},
"99141": {"REPUBLIQUE DEMOCRATIQUE ALLEMANDE"},
"99142": {"REPUBLIQUE FEDERALE D'ALLEMAGNE"},
"99114": {"ROUMANIE"},
"99123": {"RUSSIE"},
"99128": {"SAINT-MARIN"},
"99121": {"SERBIE"},
"99117": {"SLOVAQUIE"},
"99145": {"SLOVENIE"},
"99104": {"SUEDE"},
"99140": {"SUISSE"},
"99115": {"TCHECOSLOVAQUIE"},
"99116": {"TCHEQUE (REPUBLIQUE)"},
"99124": {"TURQUIE D'EUROPE"},
"99155": {"UKRAINE"},
"99129": {"VATICAN, ou SAINT-SIEGE"},
"99212": {"AFGHANISTAN"},
"99201": {"ARABIE SAOUDITE"},
"99252": {"ARMENIE"},
"99253": {"AZERBAIDJAN"},
"99249": {"BAHREIN"},
"99246": {"BANGLADESH"},
"99214": {"BHOUTAN"},
"99224": {"BIRMANIE"},
"99225": {"BRUNEI"},
"99234": {"CAMBODGE"},
"99216": {"CHINE"},
"99254": {"CHYPRE"},
"99237": {"COREE"},
"99239": {"COREE (REPUBLIQUE DE)"},
"99238": {"COREE (REPUBLIQUE POPULAIRE DEMOCRATIQUE DE)"},
"99247": {"EMIRATS ARABES UNIS"},
"99228": {"ETATS MALAIS NON FEDERES"},
"99255": {"GEORGIE"},
"99230": {"HONG-KONG"},
"99223": {"INDE", "GOA"},
"99231": {"INDONESIE"},
"99204": {"IRAN"},
"99203": {"IRAQ"},
"99207": {"ISRAEL"},
"99217": {"JAPON"},
"99222": {"JORDANIE"},
"99211": {"KAMTCHATKA"},
"99256": {"KAZAKHSTAN"},
"99257": {"KIRGHIZISTAN"},
"99240": {"KOWEIT"},
"99241": {"LAOS"},
"99205": {"LIBAN"},
"99232": {"MACAO"},
"99227": {"MALAISIE"},
"99229": {"MALDIVES"},
"99218": {"MANDCHOURIE"},
"99242": {"MONGOLIE"},
"99215": {"NEPAL"},
"99250": {"OMAN"},
"99258": {"OUZBEKISTAN"},
"99213": {"PAKISTAN"},
"99261": {"PALESTINE (Etat de)"},
"99220": {"PHILIPPINES"},
"99221": {"POSSESSIONS BRITANNIQUES AU PROCHE-ORIENT"},
"99248": {"QATAR"},
"99209": {"SIBERIE"},
"99226": {"SINGAPOUR"},
"99235": {"SRI LANKA"},
"99206": {"SYRIE"},
"99259": {"TADJIKISTAN"},
"99236": {"TAIWAN"},
"99219": {"THAILANDE"},
"99262": {"TIMOR ORIENTAL"},
"99210": {"TURKESTAN RUSSE"},
"99260": {"TURKMENISTAN"},
"99208": {"TURQUIE"},
"99243": {"VIET NAM"},
"99244": {"VIET NAM DU NORD"},
"99245": {"VIET NAM DU SUD"},
"99251": {"YEMEN"},
"99233": {"YEMEN DEMOCRATIQUE"},
"99202": {"YEMEN (REPUBLIQUE ARABE DU)"},
"99319": {"ACORES, MADERE"},
"99303": {"AFRIQUE DU SUD"},
"99352": {"ALGERIE"},
"99395": {"ANGOLA"},
"99327": {"BENIN"},
"99347": {"BOTSWANA"},
"99331": {"BURKINA"},
"99321": {"BURUNDI"},
"99322": {"CAMEROUN"},
"99305": {"CAMEROUN ET TOGO"},
"99396": {"CAP-VERT"},
"99323": {"CENTRAFRICAINE (REPUBLIQUE)"},
"99397": {"COMORES"},
"99324": {"CONGO"},
"99312": {"CONGO (REPUBLIQUE DEMOCRATIQUE)"},
"99326": {"COTE D'IVOIRE"},
"99399": {"DJIBOUTI"},
"99301": {"EGYPTE"},
"99317": {"ERYTHREE"},
"99391": {"ESWATINI"},
"99315": {"ETHIOPIE"},
"99328": {"GABON"},
"99304": {"GAMBIE"},
"99329": {"GHANA"},
"99330": {"GUINEE"},
"99314": {"GUINEE EQUATORIALE"},
"99392": {"GUINEE-BISSAU"},
"99320": {"ILES PORTUGAISES DE L'OCEAN INDIEN"},
"99332": {"KENYA"},
"99348": {"LESOTHO"},
"99302": {"LIBERIA"},
"99316": {"LIBYE"},
"99333": {"MADAGASCAR"},
"99334": {"MALAWI"},
"99335": {"MALI"},
"99350": {"MAROC"},
"99390": {"MAURICE"},
"99336": {"MAURITANIE"},
"99393": {"MOZAMBIQUE"},
"99311": {"NAMIBIE"},
"99337": {"NIGER"},
"99338": {"NIGERIA"},
"99339": {"OUGANDA"},
"99313": {"PROVINCES ESPAGNOLES D'AFRIQUE", "PRESIDES", "CANARIES (ILES)"},
"99340": {"RWANDA"},
"99389": {"SAHARA OCCIDENTAL"},
"99306": {"SAINTE HELENE, ASCENSION ET TRISTAN DA CUNHA"},
"99394": {"SAO TOME-ET-PRINCIPE"},
"99341": {"SENEGAL"},
"99398": {"SEYCHELLES"},
"99342": {"SIERRA LEONE"},
"99318": {"SOMALIE"},
"99343": {"SOUDAN"},
"99307": {"SOUDAN ANGLO-EGYPTIEN, KENYA, OUGANDA"},
"99349": {"SOUDAN DU SUD"},
"99325": {"TANGER"},
"99309": {"TANZANIE"},
"99344": {"TCHAD"},
"99345": {"TOGO"},
"99351": {"TUNISIE"},
"99346": {"ZAMBIE"},
"99308": {"ZANZIBAR", "OCEAN INDIEN (TERRITOIRE BRITANNIQUE DE L')"},
"99310": {"ZIMBABWE"},
"99441": {"ANTIGUA-ET-BARBUDA"},
"99431": {"ANTILLES NEERLANDAISES"},
"99415": {"ARGENTINE"},
"99436": {"BAHAMAS"},
"99434": {"BARBADE"},
"99429": {"BELIZE"},
"99425": {
"BERMUDES",
"ANGUILLA",
"CAIMANES (ILES)",
"MONTSERRAT",
"TURKS ET CAIQUES (ILES)",
"VIERGES BRITANNIQUES (ILES)",
"TERRITOIRES DU ROYAUME-UNI AUX ANTILLES",
},
"99418": {"BOLIVIE"},
"99443": {"BONAIRE, SAINT EUSTACHE ET SABA"},
"99416": {"BRESIL"},
"99401": {"CANADA"},
"99417": {"CHILI"},
"99419": {"COLOMBIE"},
"99406": {"COSTA RICA"},
"99407": {"CUBA"},
"99444": {"CURAÇAO"},
"99408": {"DOMINICAINE (REPUBLIQUE)"},
"99438": {"DOMINIQUE"},
"99414": {"EL SALVADOR"},
"99420": {"EQUATEUR"},
"99404": {"ETATS-UNIS", "ALASKA"},
"99435": {"GRENADE"},
"99430": {"GROENLAND"},
"99409": {"GUATEMALA"},
"99428": {"GUYANA"},
"99410": {"HAITI"},
"99411": {"HONDURAS"},
"99426": {"JAMAIQUE"},
"99403": {"LABRADOR"},
"99427": {
"MALOUINES, OU FALKLAND (ILES)",
"GEORGIE DU SUD ET LES ILES SANDWICH DU SUD",
"TERR. DU ROYAUME-UNI DANS L'ATLANTIQUE SUD",
},
"99405": {"MEXIQUE"},
"99412": {"NICARAGUA"},
"99413": {"PANAMA"},
"99421": {"PARAGUAY"},
"99422": {"PEROU"},
"99432": {
"PORTO RICO",
"VIERGES DES ETATS-UNIS (ILES)",
"TERR. DES ETATS-UNIS D'AMERIQUE EN AMERIQUE",
},
"99442": {"SAINT-CHRISTOPHE-ET-NIEVES"},
"99439": {"SAINTE-LUCIE"},
"99445": {"SAINT-MARTIN (PARTIE NEERLANDAISE)"},
"99440": {"SAINT-VINCENT-ET-LES GRENADINES"},
"99437": {"SURINAME"},
"99402": {"TERRE-NEUVE"},
"99433": {"TRINITE-ET-TOBAGO"},
"99423": {"URUGUAY"},
"99424": {"VENEZUELA"},
"99501": {
"AUSTRALIE",
"CHRISTMAS (ILE)",
"COCOS ou KEELING (ILES)",
"HEARD ET MACDONALD (ILES)",
"NORFOLK (ILE)",
},
"99508": {"FIDJI"},
"99504": {"HAWAII (ILES)"},
"99513": {"KIRIBATI"},
"99515": {"MARSHALL (ILES)"},
"99516": {"MICRONESIE (ETATS FEDERES DE)"},
"99507": {"NAURU"},
"99502": {"NOUVELLE-ZELANDE", "COOK (ILES)", "NIUE", "TOKELAU"},
"99517": {"PALAOS (ILES)"},
"99510": {"PAPOUASIE-NOUVELLE-GUINEE"},
"99503": {"PITCAIRN (ILE)"},
"99512": {"SALOMON (ILES)"},
"99506": {"SAMOA OCCIDENTALES"},
"99505": {
"GUAM",
"SAMOA AMERICAINES",
"MARIANNES DU NORD (ILES)",
"TERR. DES ETATS-UNIS D'AMERIQUE EN OCEANIE",
},
"99509": {"TONGA"},
"99511": {"TUVALU"},
"99514": {"VANUATU"},
}

View file

@ -0,0 +1,113 @@
package main
var DEPARTMENTS = map[string]string{
"01": "Ain",
"02": "Aisne",
"03": "Allier",
"04": "Alpes-de-Haute-Provence",
"05": "Hautes-Alpes",
"06": "Alpes-Maritimes",
"07": "Ardèche",
"08": "Ardennes",
"09": "Ariège",
"10": "Aube",
"11": "Aude",
"12": "Aveyron",
"13": "Bouches-du-Rhône",
"14": "Calvados",
"15": "Cantal",
"16": "Charente",
"17": "Charente-Maritime",
"18": "Cher",
"19": "Corrèze",
"2A": "Corse-du-Sud",
"2B": "Haute-Corse",
"21": "Côte-d'Or",
"22": "Côtes-d'Armor",
"23": "Creuse",
"24": "Dordogne",
"25": "Doubs",
"26": "Drôme",
"27": "Eure",
"28": "Eure-et-Loir",
"29": "Finistère",
"30": "Gard",
"31": "Haute-Garonne",
"32": "Gers",
"33": "Gironde",
"34": "Hérault",
"35": "Ille-et-Vilaine",
"36": "Indre",
"37": "Indre-et-Loire",
"38": "Isère",
"39": "Jura",
"40": "Landes",
"41": "Loir-et-Cher",
"42": "Loire",
"43": "Haute-Loire",
"44": "Loire-Atlantique",
"45": "Loiret",
"46": "Lot",
"47": "Lot-et-Garonne",
"48": "Lozère",
"49": "Maine-et-Loire",
"50": "Manche",
"51": "Marne",
"52": "Haute-Marne",
"53": "Mayenne",
"54": "Meurthe-et-Moselle",
"55": "Meuse",
"56": "Morbihan",
"57": "Moselle",
"58": "Nièvre",
"59": "Nord",
"60": "Oise",
"61": "Orne",
"62": "Pas-de-Calais",
"63": "Puy-de-Dôme",
"64": "Pyrénées-Atlantiques",
"65": "Hautes-Pyrénées",
"66": "Pyrénées-Orientales",
"67": "Bas-Rhin",
"68": "Haut-Rhin",
"69": "Rhône",
"70": "Haute-Saône",
"71": "Saône-et-Loire",
"72": "Sarthe",
"73": "Savoie",
"74": "Haute-Savoie",
"75": "Paris",
"76": "Seine-Maritime",
"77": "Seine-et-Marne",
"78": "Yvelines",
"79": "Deux-Sèvres",
"80": "Somme",
"81": "Tarn",
"82": "Tarn-et-Garonne",
"83": "Var",
"84": "Vaucluse",
"85": "Vendée",
"86": "Vienne",
"87": "Haute-Vienne",
"88": "Vosges",
"89": "Yonne",
"90": "Territoire de Belfort",
"91": "Essonne",
"92": "Hauts-de-Seine",
"93": "Seine-Saint-Denis",
"94": "Val-de-Marne",
"95": "Val-d'Oise",
"971": "Guadeloupe",
"972": "Martinique",
"973": "Guyane",
"974": "La Réunion",
"975": "Saint-Pierre-et-Miquelon",
"976": "Mayotte",
"977": "Saint-Barthélemy",
"978": "Saint-Martin",
"984": "Terres australes et antarctiques françaises",
"986": "Wallis et Futuna",
"987": "Polynésie française",
"988": "Nouvelle-Calédonie",
"989": "Île de Clipperton",
}

View file

@ -0,0 +1,90 @@
package main
import (
"strconv"
"strings"
"time"
)
type InseeData struct {
inseeNumber string
gender string
year int
month int
department string
city string
foreign bool
country string
orderOfBirth int
controlKey int
}
func newInseeData(inseeNumber string) (*InseeData, error) {
num := inseeNumber
department := num[5:7]
city := num[7:10]
if department == "97" || department == "98" {
department = num[5:8]
city = num[8:10]
}
dep, err := strconv.Atoi(department)
if err != nil {
return nil, err
}
foreign := false
country := ""
if (dep >= 91 && dep <= 96) || dep == 99 {
foreign = true
country = city
city = ""
}
order, err := strconv.Atoi(num[10:13])
if err != nil {
return nil, err
}
controlKey, err := strconv.Atoi(num[13:])
if err != nil {
return nil, err
}
month, err := strconv.Atoi(num[3:5])
if err != nil {
return nil, err
}
year, err := strconv.Atoi(num[1:3])
if err != nil {
return nil, err
}
year += 2000
now := time.Now()
birthday := time.Date(year, time.Month(month), 1, 0, 0, 0, 0, nil)
if birthday.After(now) {
year -= 100
}
return &InseeData{
inseeNumber: num,
gender: num[0:1],
year: year,
month: month,
department: department,
city: city,
foreign: foreign,
country: country,
orderOfBirth: order,
controlKey: controlKey,
}, nil
}
func (insee InseeData) isValid() (bool, error) {
num := strings.Replace(insee.inseeNumber, "2A", "19", 1)
num = strings.Replace(num, "2B", "18", 1)[:len(num)-2]
numInt, err := strconv.Atoi(num)
if err != nil {
return false, err
}
code := 97 - (numInt % 97)
return code == insee.controlKey, nil
}
func main() {
}