Depuis le 18 août 2010, vous devez être identifié pour éditer des pages dans Rodovid (excepté Rodovid Engine).

RoGer - version complète (code source)

Un article de Rodovid FR.

Jump to: navigation, search

Sommaire

[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/Special:Tree/"
urlnum = urltyp + num + "?showfulltree=yes"

# 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 ":" in elem:
        ind_el = elem.index(":")
        if elem[0:ind_el] == a_per or elem[0:ind_el] == a_fam:
            list.append(elem)

# Suppression des doublons :
listem = []
listen = []
listem_fm = []
listem_rp = []
listem_fd = []
listem_sr = []
for el in list:
    if el not in listem:
        listem.append(el)
        listem_fm.append([])
        listem_rp.append([])
        listem_fd.append("")
        listem_sr.append("")
    else:
        listen.append(el)
print listem
print len(listem), "fiches"


# Récupération des fiches et création des listes :
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
ny = 0
nz = 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)
    ind_es = s0.index(":")
    if s0[:ind_es] == a_per:
        nx = nx + 1
        nz = nz + 1
        print nz, ":", nx, "personne(s)"
    if s0[:ind_es] == a_fam:
        ny = ny + 1
        nz = nz + 1
        print nz, ":", ny, "famille(s)"

        #Listage des parents (avec leurs enfants) de chaque famille :
        while "\n1 HUSB @" in textpn:
            ind_ta = textpn.index("\n1 HUSB @") + 1
            ind_ty = textpn[ind_ta + 8:].index("@")
            ind_tz = textpn[ind_ta:].index("\n") + 1
            s_tn = a_per + ":" + textpn[ind_ta + 8:ind_ta + 8 + ind_ty]
            ind_tn = listem.index(s_tn)
            n_fm = listem_fm[ind_tn]
            n_fm.append(s0[ind_es + 1:])
            listem_fm[ind_tn] = n_fm
            textpn = textpn[:ind_ta] + textpn[ind_ta + ind_tz:]
            textps = textpn
            while "\n1 CHIL @" in textps:
                ind_ra = textps.index("\n1 CHIL @") + 1
                ind_ry = textps[ind_ra + 8:].index("@")
                ind_rz = textps[ind_ra:].index("\n") + 1
                n_rp = listem_rp[ind_tn]
                n_rp.append(textps[ind_ra + 8:ind_ra + 8 + ind_ry])
                listem_rp[ind_tn] = n_rp
                textps = textps[:ind_ra] + textps[ind_ra + ind_rz:]
        while "\n1 WIFE @" in textpn:
            ind_ma = textpn.index("\n1 WIFE @") + 1
            ind_my = textpn[ind_ma + 8:].index("@")
            ind_mz = textpn[ind_ma:].index("\n") + 1
            s_mn = a_per + ":" + textpn[ind_ma + 8:ind_ma + 8 + ind_my]
            ind_mn = listem.index(s_mn)
            m_fm = listem_fm[ind_mn]
            m_fm.append(s0[ind_es + 1:])
            listem_fm[ind_mn] = m_fm
            textpn = textpn[:ind_ma] + textpn[ind_ma + ind_mz:]
            textps = textpn
            while "\n1 CHIL @" in textps:
                ind_ra = textps.index("\n1 CHIL @") + 1
                ind_ry = textps[ind_ra + 8:].index("@")
                ind_rz = textps[ind_ra:].index("\n") + 1
                m_rp = listem_rp[ind_mn]
                m_rp.append(textps[ind_ra + 8:ind_ra + 8 + ind_ry])
                listem_rp[ind_mn] = m_rp
                textps = textps[:ind_ra] + textps[ind_ra + ind_rz:]


# Conversion vers le Gedcom classique et compilation des fiches :
listed = []
lister = []
listeb = []
for s1 in listem:
    listec = []
    listef = []
    ind_lim = listem.index(s1)
    textpr = listep[ind_lim]
    ind_db = s1.index(":")
    nm = s1[ind_db + 1:]
    #Adjonction des fiches-familles :
    if s1[0:ind_db] == a_per:
        textpx = ""
        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"

        #Inscription des numéros des fiches-familles existantes :
        for elef in listem_fm[ind_lim]:            
            textpb = "1 FAMS " + "@" + elef + "@\n"
            listep[ind_lim] = listep[ind_lim] + textpb
            listef.append(elef)
        #Inscription des numéros des fiches-familles absentes :
        while "\n1 CHIL" in textpr:
            ind_tec = textpr.index("\n1 CHIL") + 9
            textpr = textpr[ind_tec:]
            ind_tex = textpr.index("@")
            nm_enf = textpr[:ind_tex]
            elee = a_per + ":" + nm_enf
            if nm_enf not in listem_rp[ind_lim]:
                listec.append(nm_enf)
                if elee not in listem:
                    if elee not in lister:
                        site = pywikibot.getSite()
                        page = pywikibot.Page(site, elee)
                        textpc = page.get(get_redirect = True)
                        textpc = textpc.encode('utf-8') + "\n"
                        lister.append(elee)
                        listeb.append(textpc)
        for n_enf in listec:
            if (a_per + ":" + n_enf) in listem:
                ind_nem = listem.index(a_per + ":" + n_enf)
                textpc = listep[ind_nem]
            else:
                ind_ner = lister.index(a_per + ":" + n_enf)
                textpc = listeb[ind_ner]
            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

                #Incorporation de fiches-couples absentes de Rodovid :
                if n_foy not in listed:
                    textpx = 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"
                    for elej in lister:
                        ind_nej = lister.index(elej)
                        textpj = listeb[ind_nej]
                        eler = elej[len(a_per) + 1:]
                        if ("1 FAMC @" + n_foy + "@\n") in textpj:
                            textpx = textpx + "1 CHIL @" + eler + "@\n"
                    print textpx
        listem_fd[ind_lim] = listem_fd[ind_lim] + textpx
        textpr = listep[ind_lim] + listem_fd[ind_lim]

    #Transformation des sources en fiches indépendantes Gedcom :
    ind_sr = 0
    textpz = listep[ind_lim]
    textpw = ""
    textsr = ""
    if s1[0:ind_db] == a_per:
        texttp = "I"
    if s1[0:ind_db] == a_fam:
        texttp = "F"
    nm_sr = 0
    while "\n1 SOUR" in textpz[ind_sr:]:
        nm_sr = nm_sr + 1
        textpq = "1 SOUR @S" + texttp + nm + "." + repr(nm_sr) + "@\n"
        ind_sy = ind_sr + textpz[ind_sr:].index("\n1 SOUR") + 1
        if "\n1 " in textpz[ind_sy:]:
            ind_sz = ind_sy + textpz[ind_sy:].index("\n1 ") + 1
            textsc = textpz[ind_sy:ind_sz]
            textpz = textpz[:ind_sy] + textpq + textpz[ind_sz:]
        else:
            textsc = textpz[ind_sy:]
            textpz = textpz[:ind_sy] + textpq
        textsa = "0 @S" + texttp + nm + "." + repr(nm_sr) + "@ SOUR\n"
        textsc = textsa + "1 TITL"+ textsc[6:]
        if "\n2 TEXT" in textsc:
            ind_st = textsc.index("\n2 TEXT") + 1
            textsc = textsc[:ind_st] + "1 TEXT" + textsc[ind_st + 6:]
        while "\n3 CONC" in textsc:
            ind_sc = textsc.index("\n3 CONC") + 1
            textsc = textsc[:ind_sc] + "2 CONC" + textsc[ind_sc + 6:]
        textsr = textsr + textsc
        ind_sr = ind_sy
    listep[ind_lim] = textpz
    listem_sr[ind_lim] = textsr

# Compilation des fiches
    textpr = listep[ind_lim] + listem_sr[ind_lim] + listem_fd[ind_lim]
    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] Voir aussi :

[modifier] Python et Pywikibot :

[modifier] GeRod, du Gedcom vers Rodovid :

[modifier] RoGer, de Rodovid vers un Gedcom :

Джерельна довідка за населеним пунктом