In [1]:
import csv

Fabriquer un fichier listant les parcours d'un réseau, en conservant l'info de la ligne parente :

xsv join route_id osm-transit-extractor_routes.csv route_id osm-transit-extractor_line_routes.csv |xsv select line_id,route_id,origin,destination,code,network,colour|xsv search -s network Apolo > apolo7.csv

L'en-tête du tableau sera :

{| class="wikitable" width="100%" ! Réf. !class="unsortable"| Ligne / Trajet !class="unsortable"| État !class="unsortable"| Commentaires

Ne pas oublier de fermer le tableau avec

|}


In [2]:
with open("osm2wiki_routes_list.csv",'r') as f:
    reader = csv.DictReader(f)
    routes = list(reader)

lines_id = list(set([route['line_id'] for route in routes]))

for a_line_id in lines_id:
    current_routes = [route for route in routes if route['line_id'] == a_line_id]
    
    wiki_template_for_route = """
    || {{Relation|%%route_id%%|%%origin%%%%destination%%|tools=no}} || {{State Route|r=NA|h=NA}}
    """
    wiki_content_for_routes = []
    for route in current_routes:
        wiki_content_for_current_route = wiki_template_for_route.replace('%%route_id%%', route['route_id'].split(':')[-1])
        wiki_content_for_current_route = wiki_content_for_current_route.replace('%%origin%%', route['origin'])
        wiki_content_for_current_route = wiki_content_for_current_route.replace('%%destination%%', route['destination'])
        wiki_content_for_routes.append(wiki_content_for_current_route)
   
    wiki_content = """
    |-
    |style="background-color:%%colour%%; text-align: center; color: white" rowspan="%%nb_route%%" | %%ref%%
    | colspan="2" | {{browseLine|%%line_id%%|network=%%network%%|ref=%%ref%%}} '''  Ligne %%ref%%  ''' || 
    |-"""
    
    wiki_content = wiki_content = wiki_content.replace('%%nb_route%%', str(len(current_routes)+1))
    wiki_content = wiki_content.replace('%%line_id%%', a_line_id.split(':')[-1])
    wiki_content = wiki_content.replace('%%network%%', current_routes[0]['network'].replace(' ', '%20'))
    wiki_content = wiki_content.replace('%%ref%%', current_routes[0]['code'])
    wiki_content = wiki_content.replace('%%colour%%', current_routes[0]['colour'])

    
    
    wiki_content += """|-""".join(wiki_content_for_routes)
    
    print(wiki_content)


    |-
    |style="background-color:#0033cc; text-align: center; color: white" rowspan="3" | 2
    | colspan="2" | {{browseLine|7318440|network=Apolo%207|ref=2}} '''  Ligne 2  ''' || 
    |-
    || {{Relation|7318438|Paul Algis (Chelles) → Gare de Chelles Gournay|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|7318439|Gare de Chelles Gournay → Paul Algis (Chelles)|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#006600; text-align: center; color: white" rowspan="3" | 9s
    | colspan="2" | {{browseLine|8287385|network=Apolo%207|ref=9s}} '''  Ligne 9s  ''' || 
    |-
    || {{Relation|8287376|Bois Madame (Chelles) → Cité Scolaire (Chelles)|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|8287377|Cité Scolaire (Chelles) → Bois Madame (Chelles)|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#9bbb59; text-align: center; color: white" rowspan="3" | 7s
    | colspan="2" | {{browseLine|8287382|network=Apolo%207|ref=7s}} '''  Ligne 7s  ''' || 
    |-
    || {{Relation|8287378|Debussy (Courtry) → Cité Scolaire (Chelles)|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|8287379|Cité Scolaire (Chelles) → Debussy (Courtry)|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#ff9a00; text-align: center; color: white" rowspan="3" | 4s
    | colspan="2" | {{browseLine|8287384|network=Apolo%207|ref=4s}} '''  Ligne 4s  ''' || 
    |-
    || {{Relation|8287380|Mairie (Claye-Souilly) → Cité Scolaire (Chelles)|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|8287381|Cité Scolaire (Chelles) → Mairie (Claye-Souilly)|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#ff9a00; text-align: center; color: white" rowspan="3" | 4
    | colspan="2" | {{browseLine|7728377|network=Apolo%207|ref=4}} '''  Ligne 4  ''' || 
    |-
    || {{Relation|3531645|Chelles Gare RER-SNCF → Mairie de Claye-Souilly|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|8061217|Mairie de Claye-Souilly → Chelles Gare RER-SNCF|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#0099ff; text-align: center; color: white" rowspan="3" | 5
    | colspan="2" | {{browseLine|7331862|network=Apolo%207|ref=5}} '''  Ligne 5  ''' || 
    |-
    || {{Relation|3352494|Rond-Point des Sciences (Chelles) → Gare de Lagny Thorigny|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|7331860|Gare de Lagny Thorigny → Rond-Point des Sciences (Chelles)|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#680068; text-align: center; color: white" rowspan="3" | 3
    | colspan="2" | {{browseLine|3081886|network=Apolo%207|ref=3}} '''  Ligne 3  ''' || 
    |-
    || {{Relation|3080733|Gare SNCF/RER → Gare de Villeparisis Mitry-le-Neuf|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|3081885|Gare de Villeparisis Mitry-le-Neuf → Gare SNCF/RER Chelles|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#895913; text-align: center; color: white" rowspan="3" | 8
    | colspan="2" | {{browseLine|7466920|network=Apolo%207|ref=8}} '''  Ligne 8  ''' || 
    |-
    || {{Relation|3475445|Vaires Gare SNCF → Chelles Gare SNCF/RER|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|7699493|Chelles Gare SNCF/RER → Vaires Gare SNCF|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#9bbb59; text-align: center; color: white" rowspan="2" | 7
    | colspan="2" | {{browseLine|8285312|network=Apolo%207|ref=7}} '''  Ligne 7  ''' || 
    |-
    || {{Relation|7699449|Rond-Point des Sciences (Chelles) → Gare de Chelles Gournay|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#680068; text-align: center; color: white" rowspan="3" | 3s
    | colspan="2" | {{browseLine|7699451|network=Apolo%207|ref=3s}} '''  Ligne 3s  ''' || 
    |-
    || {{Relation|7916479|Gare de Mitry Claye → Cité Scolaire|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|7916480|Cité Scolaire → Gare de Mitry Claye|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#ffb814; text-align: center; color: white" rowspan="3" | 1
    | colspan="2" | {{browseLine|7142158|network=Apolo%207|ref=1}} '''  Ligne 1  ''' || 
    |-
    || {{Relation|3162035|Gare de Chelles → Rond-Point des Sciences (Chelles)|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|7142157|Rond-Point des Sciences (Chelles) → Gare de Chelles|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#663300; text-align: center; color: white" rowspan="3" | 8s
    | colspan="2" | {{browseLine|8287383|network=Apolo%207|ref=8s}} '''  Ligne 8s  ''' || 
    |-
    || {{Relation|8287374|Gare de Chelles → Mairie (Chelles)|tools=no}} || {{State Route|r=NA|h=NA}}
    |-
    || {{Relation|8287375|Mairie (Chelles) → Vieux Moulin (Chelles)|tools=no}} || {{State Route|r=NA|h=NA}}
    

    |-
    |style="background-color:#d30000; text-align: center; color: white" rowspan="2" | 6
    | colspan="2" | {{browseLine|8285313|network=Apolo%207|ref=6}} '''  Ligne 6  ''' || 
    |-
    || {{Relation|7699450|Gare de Chelles Gournay → Gare de Vaires Torcy|tools=no}} || {{State Route|r=NA|h=NA}}