-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtfs_fetch.py
77 lines (73 loc) · 2.29 KB
/
gtfs_fetch.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
# Gets the current GTFS files and updates the GTFS directory.
# MAKE SURE YOU MOVE THE GTFS FILES ALREADY IN THE GTFS DIRECTORY SOMEWHERE ELSE
# (ie. rename the folder to something like gtfs_fall_2019)
import requests
import os
gtfs_directory = 'gtfs'
gtfs_config = [
{
'name': 'Barrie Transit',
'source': 'http://www.myridebarrie.ca/gtfs/Google_transit.zip',
},
{
'name': 'Brampton Transit',
'source': 'http://www.brampton.ca/EN/City-Hall/OpenGov/Open-Data-Catalogue/Documents/Google_Transit.zip',
},
{
'name': 'Burlington Transit',
'source': 'http://opendata.burlington.ca/gtfs-rt/GTFS_Data.zip',
},
{
'name': 'DRT',
'source': 'https://maps.durham.ca/OpenDataGTFS/GTFS_Durham_TXT.zip',
},
{
'name': 'GO',
'source': 'https://www.gotransit.com/static_files/gotransit/assets/Files/GO_GTFS.zip',
},
{
'name': 'GRT',
'source': 'http://www.regionofwaterloo.ca/opendatadownloads/GRT_GTFS.zip',
},
{
'name': 'Guelph Transit',
'source': 'http://data.open.guelph.ca/datafiles/guelph-transit/guelph_transit_gtfs.zip',
},
{
'name': 'HSR',
'source': 'http://googlehsrdocs.hamilton.ca/',
},
{
'name': 'Milton Transit',
},
{
'name': 'MiWay',
'source': 'https://www.miapp.ca/GTFS/google_transit.zip?#',
},
{
'name': 'Niagara Falls Transit',
'source': 'https://maps.niagararegion.ca/googletransit/NiagaraRegionTransit.zip',
},
{
'name': 'Oakville Transit',
'source': 'https://www.arcgis.com/sharing/rest/content/items/d78a1c1ad6a940009de8b68839a8f606/data',
},
{
'name': 'TTC',
'source': 'http://opendata.toronto.ca/TTC/routes/OpenData_TTC_Schedules.zip',
},
{
'name': 'YRT',
'source': 'https://www.yrt.ca/google/google_transit.zip',
},
]
if not os.path.exists(gtfs_directory):
os.mkdir(gtfs_directory)
for gtfs in gtfs_config:
if 'source' not in gtfs:
print('Warning:', gtfs['name'], 'does not have a GTFS source - it will be skipped. Open gtfs_fetch.py and add in the GTFS link under the "source" key as is done in the other agencies.')
continue
req = requests.get(gtfs['source'])
with open(gtfs_directory + '/' + gtfs['name'] + '.zip', 'wb') as gtfs_stream:
gtfs_stream.write(req.content)
print('Updated', gtfs['name'], 'in', gtfs_directory)