Un article de Rodovid FR.
[modifier] Version pour Rodovid.FR
# -*- coding: utf-8 -*-
import pywikibot
a_per = "Personne"
a_fam = "Famille"
# Récupération du numéro de la personne
num = raw_input ("Matricule : ")
# Création de l'adresse
urltyp = "http://fr.rodovid.org/wk/Personne:"
urlnum = urltyp + num
# Récupération de la page ("arbre complet"):
import urllib
text = urllib.urlopen(urlnum)
htmlSource = text.read()
text.close()
# Découpage de la page :
listSource = htmlSource.split("'")
# Sélection des adresses :
list = []
n = 0
for elem in listSource:
if elem[0:3] == "Per" or elem[0:3] == "Fam":
list.append(elem)
# Suppression des doublons :
listem = []
listen = []
for el in list:
if el not in listem:
listem.append(el)
else:
listen.append(el)
print listem
# Récupération des fiches :
header_0 = "0 HEAD\n"
header_s1 = "1 SOUR RODOVID\n"
header_c1 = "1 CHAR UTF-8\n"
header_g1 = "1 GEDC\n"
header_g2 = "2 VERS 5.5\n"
header_g3 = "2 FORM LINEAGE-LINKED\n"
header_g = header_g1 + header_g2 + header_g3
header = header_0 + header_s1 + header_c1 + header_g
textpf = ""
nx = 0
listep = []
for s0 in listem:
site = pywikibot.getSite()
page = pywikibot.Page(site, s0)
textpn = page.get(get_redirect = True)
textpn = textpn.encode('utf-8') + "\n"
listep.append(textpn)
nx = nx + 1
print nx, "fiche(s)"
# Incorporation des fiches-familles
listed = []
for s1 in listem:
listec = []
listef = []
ind_lim = listem.index(s1)
textpr = listep[ind_lim]
ind_db = s1.index(":")
if s1[0:ind_db] == a_per:
textpx = ""
nm = s1[ind_db + 1:]
if "1 SEX M\n" in textpr:
sp = "m"
if "1 SEX F\n" in textpr:
sp = "f"
if "1 SEX \n" in textpr:
sp = "n"
for elef in listem:
ind_dp = elef.index(":")
if elef[0:ind_dp] == a_fam:
elev = elef[ind_dp + 1:]
ind_nef = listem.index(elef)
textpv = listep[ind_nef]
text_p = "1 HUSB @" + s1[ind_db + 1:] + "@"
text_m = "1 WIFE @" + s1[ind_db + 1:] + "@"
if text_p in textpv or text_m in textpv:
textpb = "1 FAMS " + "@" + elev + "@\n"
listep[ind_lim] = listep[ind_lim] + textpb
listef.append(elev)
while "\n1 CHIL" in textpr:
ind_tec = textpr.index("\n1 CHIL") + 9
textpr = textpr[ind_tec:]
ind_tex = textpr.index("@")
n_enf = textpr[:ind_tex]
listec.append(n_enf)
elee = a_per + ":" + n_enf
if elee in listem:
ind_nec = listem.index(elee)
textpc = listep[ind_nec]
else:
site = pywikibot.getSite()
page = pywikibot.Page(site, elee)
textpc = page.get(get_redirect = True)
textpc = textpc.encode('utf-8') + "\n"
ind_tef = textpc.index("\n1 FAMC ") + 1
textpc = textpc[ind_tef:]
ind_tev = textpc.index("\n")
textpp = "1 FAMS " + textpc[7:ind_tev + 1]
n_foy = textpc[8:ind_tev - 1]
if n_foy not in listef:
listef.append(n_foy)
listep[ind_lim] = listep[ind_lim] + textpp
if ":" in n_foy:
if n_foy not in listed:
textpx = "0 @" + n_foy + "@ FAM\n"
listed.append(n_foy)
if "+" not in n_foy:
if sp == "m" or sp == "n":
textpx = textpx + "1 HUSB @" + nm + "@\n"
if sp == "f":
textpx = textpx + "1 WIFE @" + nm + "@\n"
else:
ind_sp = n_foy.index("+")
if n_foy.index(nm) == 1:
elep = n_foy[ind_sp + 1:]
else:
elep = n_foy[1:ind_sp]
if sp == "m" or sp == "n":
textpx = textpx + "1 HUSB @" + nm + "@\n"
textpx = textpx + "1 WIFE @" + elep + "@\n"
if sp == "f":
textpx = textpx + "1 HUSB @" + elep + "@\n"
textpx = textpx + "1 WIFE @" + nm + "@\n"
for elei in listem:
ind_nei = listem.index(elei)
textpy = listep[ind_nei]
eley = elei[len(a_per) + 1:]
if ("1 FAMC @" + n_foy + "@\n") in textpy:
textpx = textpx + "1 CHIL @" + eley + "@\n"
print textpx
listep[ind_lim] = listep[ind_lim] + textpx
textpr = listep[ind_lim]
# Compilation des fiches
textpf = textpf + textpr
textfi = header + textpf
trlr = "0 TRLR"
text0 = textfi + trlr
out_file = open("rgtest0.txt", "w")
out_file.write(text0)
out_file.close()
[modifier] Python et Pywikibot :
[modifier] GeRod, du Gedcom vers Rodovid :
[modifier] RoGer, de Rodovid vers un Gedcom :