当前位置: 首页>>代码示例>>Python>>正文


Python BaseObject.unquote方法代码示例

本文整理汇总了Python中BaseObject.BaseObject.unquote方法的典型用法代码示例。如果您正苦于以下问题:Python BaseObject.unquote方法的具体用法?Python BaseObject.unquote怎么用?Python BaseObject.unquote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BaseObject.BaseObject的用法示例。


在下文中一共展示了BaseObject.unquote方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: import_agencies

# 需要导入模块: from BaseObject import BaseObject [as 别名]
# 或者: from BaseObject.BaseObject import unquote [as 别名]
    def import_agencies(cls, directory):
        try:
            f = open(os.path.join(directory, 'agency.txt'), 'rb')
            reader = csv.reader(f)

            mappings = {'agency_name': 'name',
                        'agency_url': 'url',
                        'agency_timezone': 'timezone',
                        'agency_lang': 'language',
                        'agency_phone': 'phone',
                        'agency_fare_url': 'fare_url'}

            # 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]] = BaseObject.unquote(a)
                # create the agency
                agency = Agency(**kw)
                # set the id
                agency.gtfs_id = BaseObject.unquote(l2[r_headers['agency_id']])

        except IOError, e:
            print >> sys.stderr, 'Unable to open agency.txt:', e
开发者ID:line72,项目名称:subte,代码行数:35,代码来源:Agency.py

示例2: import_trips

# 需要导入模块: from BaseObject import BaseObject [as 别名]
# 或者: from BaseObject.BaseObject import unquote [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
开发者ID:line72,项目名称:subte,代码行数:51,代码来源:Trip.py

示例3: import_calendars

# 需要导入模块: from BaseObject import BaseObject [as 别名]
# 或者: from BaseObject.BaseObject import unquote [as 别名]
    def import_calendars(cls, directory):
        try:
            f = open(os.path.join(directory, 'calendar.txt'), 'rb')
            reader = csv.reader(f)

            mappings = {'service_id': 'service_name',
                        'monday': 'monday',
                        'tuesday': 'tuesday',
                        'wednesday': 'wednesday',
                        'thursday': 'thursday',
                        'friday': 'friday',
                        'saturday': 'saturday',
                        'sunday': 'sunday',
                        'start_date': 'start_date',
                        'end_date': 'end_date',
                    }
            transforms = {'service_id': lambda x: x,
                          'monday': lambda x: int(x),
                          'tuesday': lambda x: int(x),
                          'wednesday': lambda x: int(x),
                          'thursday': lambda x: int(x),
                          'friday': lambda x: int(x),
                          'saturday': lambda x: int(x),
                          'sunday': lambda x: int(x),
                          'start_date': lambda x: x,
                          'end_date': lambda x: 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]] = transforms[key](BaseObject.unquote(a))
                # create the calendar
                calendar = Calendar(**kw)
                # set the id
                calendar.gtfs_id = BaseObject.unquote(l2[r_headers['service_id']])

        except IOError, e:
            print >> sys.stderr, 'Unable to open calendar.txt:', e
开发者ID:CodeforBirmingham,项目名称:subte,代码行数:51,代码来源:Calendar.py

示例4: import_frequencies

# 需要导入模块: from BaseObject import BaseObject [as 别名]
# 或者: from BaseObject.BaseObject import unquote [as 别名]
    def import_frequencies(cls, directory):
        from Trip import Trip

        try:
            f = open(os.path.join(directory, 'frequencies.txt'), 'rb')
            reader = csv.reader(f)

            mappings = {'trip_id': ('trip_route', lambda x: Trip.get_by_gtfs_id(x).trip_route),
                        'start_time': ('start', lambda x: x),
                        'end_time': ('end', lambda x: x),
                        'headway_secs': ('headway', lambda x: 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 frequency
                frequency = Frequency(**kw)
                trip_route = frequency.trip_route.frequencies.append(frequency)

        except IOError, e:
            print >> sys.stderr, 'Unable to open frequencies.txt:', e
开发者ID:CodeforBirmingham,项目名称:subte,代码行数:35,代码来源:Frequency.py

示例5: import_stops

# 需要导入模块: from BaseObject import BaseObject [as 别名]
# 或者: from BaseObject.BaseObject import unquote [as 别名]
    def import_stops(cls, directory):
        try:
            f = open(os.path.join(directory, 'stops.txt'), 'rb')
            reader = csv.reader(f)

            mappings = {'stop_code': ('code', lambda x: x),
                        'stop_name': ('name', lambda x: x),
                        'stop_desc': ('description', lambda x: x),
                        'stop_lat': ('latitude', lambda x: float(x)),
                        'stop_lon': ('longitude', lambda x: float(x)),
                        'zone_id': ('zone_id', lambda x: x),
                        'stop_url': ('url', lambda x: x),
                        'location_type': ('location_type', lambda x: int(x) if x else 0),
                        'parent_station': ('parent_station', lambda x: 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 stop
                stop = Stop(**kw)
                # set the id
                stop.gtfs_id = BaseObject.unquote(l2[r_headers['stop_id']])

        except IOError, e:
            print >> sys.stderr, 'Unable to open stops.txt:', e
开发者ID:CodeforBirmingham,项目名称:subte,代码行数:39,代码来源:Stop.py

示例6: import_routes

# 需要导入模块: from BaseObject import BaseObject [as 别名]
# 或者: from BaseObject.BaseObject import unquote [as 别名]
    def import_routes(cls, directory):
        try:
            f = open(os.path.join(directory, 'routes.txt'), 'rb')
            reader = csv.reader(f)

            mappings = {'agency_id': ('agency', lambda x: Agency.get_by_gtfs_id(x)),
                        'route_short_name': ('short_name', lambda x: x),
                        'route_long_name': ('long_name', lambda x: x),
                        'route_desc': ('description', lambda x: x),
                        'route_type': ('route_type', lambda x: int(x)),
                        'route_url': ('url', lambda x: x),
                        'route_color': ('color', lambda x: x),
                        'route_text_color': ('text_color', lambda x: 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 route
                route = Route(**kw)
                # set the id
                route.gtfs_id = BaseObject.unquote(l2[r_headers['route_id']])

        except IOError, e:
            print >> sys.stderr, 'Unable to open routes.txt:', e
开发者ID:CodeforBirmingham,项目名称:subte,代码行数:38,代码来源:Route.py

示例7: dict

# 需要导入模块: from BaseObject import BaseObject [as 别名]
# 或者: from BaseObject.BaseObject import unquote [as 别名]
            }

            # 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))

                # find the corresponding trip
                trip_id = BaseObject.unquote(l2[r_headers['trip_id']])
                trip = Trip.get_by_gtfs_id(trip_id)
                if trip is None:
                    print >> sys.stderr, 'no trip for id', trip_id

                # add the trip stop
                stop_id = BaseObject.unquote(l2[r_headers['stop_id']])
                stop = Stop.get_by_gtfs_id(stop_id)
                trip.trip_route.add_stop(stop)

                trip_stop = trip.stops[-1]
                trip_stop.arrival = BaseObject.unquote(l2[r_headers['arrival_time']])
                trip_stop.departure = BaseObject.unquote(l2[r_headers['departure_time']])
开发者ID:line72,项目名称:subte,代码行数:33,代码来源:Trip.py


注:本文中的BaseObject.BaseObject.unquote方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。