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)