本文整理汇总了Python中Path.Path.get_by_gtfs_id方法的典型用法代码示例。如果您正苦于以下问题:Python Path.get_by_gtfs_id方法的具体用法?Python Path.get_by_gtfs_id怎么用?Python Path.get_by_gtfs_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path.Path
的用法示例。
在下文中一共展示了Path.get_by_gtfs_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_trips
# 需要导入模块: from Path import Path [as 别名]
# 或者: from Path.Path import get_by_gtfs_id [as 别名]
def import_trips(cls, directory):
from Route import Route
from Calendar import Calendar
from TripRoute import TripRoute
from Path import Path
from Stop import Stop
try:
f = open(os.path.join(directory, 'trips.txt'), 'rb')
reader = csv.reader(f)
mappings = {'route_id': ('route', lambda x: Route.get_by_gtfs_id(x)),
'service_id': ('calendar', lambda x: Calendar.get_by_gtfs_id(x)),
'trip_id': ('name', lambda x: x),
'trip_headsign': ('headsign', lambda x: x),
'direction_id': ('direction', lambda x: int(x) if x else 0),
'shape_id': ('path', lambda x: Path.get_by_gtfs_id(x)),
}
# create a headers with an index
headers = reader.next()
r_headers = dict([(x, i) for i, x in enumerate(headers)])
for l2 in reader:
if len(l2) != len(headers):
print >> sys.stderr, 'Invalid line', l2, headers
continue
kw = {}
for i, a in enumerate(l2):
key = headers[i]
if key in mappings:
kw[mappings[key][0]] = mappings[key][1](BaseObject.unquote(a))
# create the trip route
trip_route = TripRoute(**kw)
# set the id
trip_route.gtfs_id = BaseObject.unquote(l2[r_headers['trip_id']])
# create a trip
trip = trip_route.add_trip()
trip.gtfs_id = BaseObject.unquote(l2[r_headers['trip_id']])
# go through the list again and set block ids
#!mwd - I'm not sure how to do this. We link
# blocks by trip ids, but block ids are
# random in gtfs, so we have no way to link
# them back
except IOError, e:
print >> sys.stderr, 'Unable to open trips.txt:', e