In [1]:
import csv
on a en entrée un fichier csv de cette forme :
cat routes_accra.csv |xsv sample 10 |xsv table
Lines From To network mode Operator Comment
281 Kaneshie Russia Accra Arena - Total Zongo - Russia - Mataheko Branch of G.P.R.T.U
188 Circle Asore Danho Trotro bus Biakoye Taxi Union Branch of G.P.R.T.U
48 Abeka Lapaz Korle Bu Trotro bus Abeka-Lapaz Kaneshie Agbogbloshie Branch of GPRTU
164 Arena Kaneshie Trotro bus Accra Arena - Total Zongo - Russia - Marteheko Branch of G.P.R.T.U
256 Adjiringanor Accra New Tema Station Trotro bus East Legon-La Bawaleshie-M-A-S-A GPRTU Charge not recorded
298 Kokomlemle Dzorwulu Kokomlemle - Pig Farm - Dzorwulu - Abelemkpe Local of Pig Farm Branch. Trotro loads en route
96 Achimota Kotobabi Down Trotro bus Achimota GPRTU Main Branch Not available
389 Accra New Town Madina Accra Newtown - 37 - Burma Camp - Madina Branch B-track GPS has weak connection, A-track GPS is okay
473 Accra Salaga Chemuna Chorkor Trotro Branch of GPRTU
177 Bubiashie-Atico Circle Trotro bus Bubuashie-Atico-Circle Branch of GPRTU
In [2]:
with open("csv2wiki_routes_list.csv",'r') as f:
reader = csv.DictReader(f)
lines = list(reader)
#lines
In [3]:
wiki_template = """
|-
| rowspan="2" |%%ref%%
| rowspan="2" | %%network%%
| rowspan="2" | %%operator%%
| rowspan="2" |{{Relation|0|%%origin%% ↔ %%destination%%|tools=josm}}
{{User:Singing-Poppy/Template:InitPTRelations
|ref = %%ref%%
|from = %%origin%%
|to = %%destination%%
|operator = %%operator%%
|network = %%network%%
|pt_mode = %%mode%%
}}
||{{Relation|0|%%origin%% → %%destination%%}} || {{State Route|r=NA|h=NA}}
||
|
|-
|| {{Relation|0|%%destination%% → %%origin%%}} || {{State Route|r=NA|h=NA}}
||
|
"""
for a_line in lines:
#print(a_line)
content = wiki_template.replace('%%ref%%', a_line['Lines'])
content = content.replace('%%origin%%', a_line['From'])
content = content.replace('%%destination%%', a_line['To'])
content = content.replace('%%mode%%', a_line['mode'])
content = content.replace('%%network%%', a_line['network'])
content = content.replace('%%operator%%', a_line['Operator'])
print(content)