forked from Liguria-Digitale/GTFS2NeTEx-converter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResourceFrameComponent.py
84 lines (71 loc) · 2.89 KB
/
ResourceFrameComponent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import sqlite3
import os
import SupportUtilitiesSubComponent
acroMOT=""
class ResourceFrameProcessing():
def processResourceFrame(self, iGTFSExplodedFeedFolder, iNUTS, iDb, iAz, iStartDayCut, iEndDayCut, iVersion, iVAT):
print('===> Processing ResourceFrame...')
conn=sqlite3.connect(iGTFSExplodedFeedFolder + '/' +iDb + '.db')
c=conn.cursor()
# import agency.txt
c.execute('''SELECT agency_id, agency_name, agency_url, agency_timezone, agency_lang, agency_phone, agency_fare_url, agency_email FROM tb_agency''')
records=c.fetchall()
print("Agency.txt => total rows are: ", len(records))
#print("Printing each row")
leftText="""<ResourceFrame id="epd:it:ResourceFrame_EU_PI_COMMON:ita" version="1"><organisations>"""
innerText=""
for row in records:
nameAgencyClean=""
if(row[1]):
nameAgency=SupportUtilitiesSubComponent.StringUtilities
nameAgencyClean=nameAgency.filterOutNotMultilingualChars(self, row[1])
innerText= innerText + """
<Operator id="%s:Operator:%s:%s:%s" version="%s">
<Name>%s</Name>
<ShortName></ShortName>
<ContactDetails>
<Email>%s</Email>
<Phone>%s</Phone>
<Url>%s</Url>
</ContactDetails>
<OrganisationType>operator</OrganisationType>
<Address id="%s:Address:%s%s:1">
<CountryName>Italia</CountryName>
<Street></Street>
<Town></Town>
<PostCode></PostCode>
</Address>
</Operator>""" % (
######## <Authority id> <=== ???
######## <Name> <=== agency_name=row[1]
######## <ShortName> <=== ???
######## <Email> <=== ???
######## <Phone> <=== agency_phone=row[5]
######## <Url> <=== agency_url=row[2]
######## <Address id> <=== ???
######## <CountryName> <=== ???
######## <Street> <=== ???
######## <Town> <=== ???
######## <Postcode> <=== ???
######## <???> <=== agency_timezone=row[3]
######## <???> <=== agency_lang=row[4]
######## <???> <=== agency_fare_url=row[6]
# row.agency_name, row.agency_phone, row.agency_url)
# iNUTS, acroMOT, iAz, iAz, iVersion,
# nameAgencyClean,
# row[7],
# row[5],
# row[2],
# iNUTS, acroMOT, iAz,
# iNUTS, acroMOT, iAz, row[0], iVersion,
iNUTS, iVAT, iAz, iAz, iVersion,
nameAgencyClean,
row[7],
row[5],
row[2],
iNUTS, acroMOT, iAz)
rightText="""</organisations></ResourceFrame>"""
with open(iGTFSExplodedFeedFolder + os.sep + iAz + '-ResourceFrame-temp.xml', 'w', encoding='utf-8') as f: f.write((leftText))
with open(iGTFSExplodedFeedFolder + os.sep + iAz + '-ResourceFrame-temp.xml', 'a', encoding='utf-8') as f: f.write((innerText))
with open(iGTFSExplodedFeedFolder + os.sep + iAz + '-ResourceFrame-temp.xml', 'a', encoding='utf-8') as f: f.write((rightText))
c.close()