コード例 #1
0
            unique_platforms_id.add(a['ref'])
    print platforms_id[route_id]

import transitfeed
schedule = transitfeed.Schedule()
schedule.AddAgency("Transjogja", "http://iflyagency.com",
                   "Indonesia/Yogyakarta")

service_period = schedule.GetDefaultServicePeriod()
service_period.SetStartDate("20150101")
service_period.SetEndDate("20160101")
service_period.SetWeekdayService(True)
#service_period.SetDateHasService('20070704', False)

stops_transit = {}
nodes = MyApi.NodesGet(unique_platforms_id)
for node_id, node in nodes.items():
    platform_name = node['tag']['name']
    stops_transit[node_id] = schedule.AddStop(lng=node['lon'],
                                              lat=node['lat'],
                                              name=platform_name)
    print 'Adding Stop', platform_name

#Adding Routes in GTFS
import datetime
for route_id in routes:
    route_name = routes_info[route_id]['name']
    print '\n\nAdding Trip', route_name
    route_ref = routes_info[route_id]['ref']
    route_colour = routes_info[route_id]['colour']
    route = schedule.AddRoute(short_name=route_ref,
コード例 #2
0
class TestOsmApiNode(osmapi_tests.TestOsmApi):
    def test_NodeGet(self):
        self._conn_mock()

        result = self.api.NodeGet(123)

        args, kwargs = self.api._conn.putrequest.call_args
        self.assertEquals(args[0], 'GET')
        self.assertEquals(args[1], '/api/0.6/node/123')

        self.assertEquals(
            result, {
                'id': 123,
                'changeset': 15293,
                'uid': 605,
                'timestamp': datetime.datetime(2012, 4, 18, 11, 14, 26),
                'lat': 51.8753146,
                'lon': -1.4857118,
                'visible': True,
                'version': 8,
                'user': '******',
                'tag': {
                    'amenity': 'school',
                    'foo': 'bar',
                    'name': 'Berolina & Schule'
                },
            })

    def test_NodeGet_with_version(self):
        self._conn_mock()

        result = self.api.NodeGet(123, NodeVersion=2)

        args, kwargs = self.api._conn.putrequest.call_args
        self.assertEquals(args[0], 'GET')
        self.assertEquals(args[1], '/api/0.6/node/123/2')

        self.assertEquals(
            result, {
                'id': 123,
                'changeset': 4152,
                'uid': 605,
                'timestamp': datetime.datetime(2011, 4, 18, 11, 14, 26),
                'lat': 51.8753146,
                'lon': -1.4857118,
                'visible': True,
                'version': 2,
                'user': '******',
                'tag': {
                    'amenity': 'school',
                },
            })

    def test_NodeCreate_changesetauto(self):
        # setup mock
        self.api = OsmApi(api="api06.dev.openstreetmap.org",
                          changesetauto=True)
        self._conn_mock(auth=True,
                        filenames=[
                            'test_NodeCreate_changesetauto.xml',
                            'test_ChangesetUpload_create_node.xml',
                            'test_ChangesetClose.xml',
                        ])

        test_node = {
            'lat': 47.123,
            'lon': 8.555,
            'tag': {
                'amenity': 'place_of_worship',
                'religion': 'pastafarian'
            }
        }

        self.assertIsNone(self.api.NodeCreate(test_node))

    def test_NodeCreate(self):
        self._conn_mock(auth=True)

        # setup mock
        self.api.ChangesetCreate = mock.Mock(return_value=1111)
        self.api._CurrentChangesetId = 1111

        test_node = {
            'lat': 47.287,
            'lon': 8.765,
            'tag': {
                'amenity': 'place_of_worship',
                'religion': 'pastafarian'
            }
        }

        cs = self.api.ChangesetCreate({'comment': 'This is a test dataset'})
        self.assertEquals(cs, 1111)
        result = self.api.NodeCreate(test_node)

        args, kwargs = self.api._conn.putrequest.call_args
        self.assertEquals(args[0], 'PUT')
        self.assertEquals(args[1], '/api/0.6/node/create')

        self.assertEquals(result['id'], 9876)
        self.assertEquals(result['lat'], test_node['lat'])
        self.assertEquals(result['lon'], test_node['lon'])
        self.assertEquals(result['tag'], test_node['tag'])

    def test_NodeCreate_wo_changeset(self):
        test_node = {
            'lat': 47.287,
            'lon': 8.765,
            'tag': {
                'amenity': 'place_of_worship',
                'religion': 'pastafarian'
            }
        }

        with self.assertRaisesRegexp(Exception, 'need to open a changeset'):
            self.api.NodeCreate(test_node)

    def test_NodeCreate_wo_auth(self):
        self._conn_mock()

        # setup mock
        self.api.ChangesetCreate = mock.Mock(return_value=1111)
        self.api._CurrentChangesetId = 1111
        test_node = {
            'lat': 47.287,
            'lon': 8.765,
            'tag': {
                'amenity': 'place_of_worship',
                'religion': 'pastafarian'
            }
        }

        with self.assertRaisesRegexp(UsernamePasswordMissingError,
                                     'Username/Password missing'):
            self.api.NodeCreate(test_node)

    def test_NodeUpdate(self):
        self._conn_mock(auth=True)

        # setup mock
        self.api.ChangesetCreate = mock.Mock(return_value=1111)
        self.api._CurrentChangesetId = 1111

        test_node = {
            'id': 7676,
            'lat': 47.287,
            'lon': 8.765,
            'tag': {
                'amenity': 'place_of_worship',
                'name': 'christian'
            }
        }

        cs = self.api.ChangesetCreate({'comment': 'This is a test dataset'})
        self.assertEquals(cs, 1111)
        result = self.api.NodeUpdate(test_node)

        args, kwargs = self.api._conn.putrequest.call_args
        self.assertEquals(args[0], 'PUT')
        self.assertEquals(args[1], '/api/0.6/node/7676')

        self.assertEquals(result['id'], 7676)
        self.assertEquals(result['version'], 3)
        self.assertEquals(result['lat'], test_node['lat'])
        self.assertEquals(result['lon'], test_node['lon'])
        self.assertEquals(result['tag'], test_node['tag'])

    def test_NodeDelete(self):
        self._conn_mock(auth=True)

        # setup mock
        self.api.ChangesetCreate = mock.Mock(return_value=1111)
        self.api._CurrentChangesetId = 1111

        test_node = {'id': 7676}

        cs = self.api.ChangesetCreate({'comment': 'This is a test dataset'})
        self.assertEquals(cs, 1111)

        result = self.api.NodeDelete(test_node)

        args, kwargs = self.api._conn.putrequest.call_args
        self.assertEquals(args[0], 'DELETE')
        self.assertEquals(args[1], '/api/0.6/node/7676')
        self.assertEquals(result['id'], 7676)
        self.assertEquals(result['version'], 4)

    def test_NodeHistory(self):
        self._conn_mock()

        result = self.api.NodeHistory(123)

        args, kwargs = self.api._conn.putrequest.call_args
        self.assertEquals(args[0], 'GET')
        self.assertEquals(args[1], '/api/0.6/node/123/history')

        self.assertEquals(len(result), 8)
        self.assertEquals(result[4]['id'], 123)
        self.assertEquals(result[4]['version'], 4)
        self.assertEquals(result[4]['lat'], 51.8753146)
        self.assertEquals(result[4]['lon'], -1.4857118)
        self.assertEquals(result[4]['tag'], {
            'empty': '',
            'foo': 'bar',
        })

    def test_NodeWays(self):
        self._conn_mock()

        result = self.api.NodeWays(234)

        args, kwargs = self.api._conn.putrequest.call_args
        self.assertEquals(args[0], 'GET')
        self.assertEquals(args[1], '/api/0.6/node/234/ways')

        self.assertEquals(len(result), 1)
        self.assertEquals(result[0]['id'], 60)
        self.assertEquals(result[0]['changeset'], 61)
        self.assertEquals(result[0]['tag'], {
            'highway': 'path',
            'name': 'Dog walking path',
        })

    def test_NodeRelations(self):
        self._conn_mock()

        result = self.api.NodeRelations(4295668179)

        args, kwargs = self.api._conn.putrequest.call_args
        self.assertEquals(args[0], 'GET')
        self.assertEquals(args[1], '/api/0.6/node/4295668179/relations')

        self.assertEquals(len(result), 1)
        self.assertEquals(result[0]['id'], 4294968148)
        self.assertEquals(result[0]['changeset'], 23123)
        self.assertEquals(result[0]['member'][1], {
            'role': 'point',
            'ref': 4295668179,
            'type': 'node',
        })
        self.assertEquals(result[0]['tag'], {
            'type': 'fancy',
        })

    def test_NodesGet(self):
        self._conn_mock()

        result = self.api.NodesGet([123, 345])

        args, kwargs = self.api._conn.putrequest.call_args
        self.assertEquals(args[0], 'GET')
        self.assertEquals(args[1], '/api/0.6/nodes?nodes=123,345')

        self.assertEquals(len(result), 2)
        self.assertEquals(
            result[123], {
                'id': 123,
                'changeset': 15293,
                'uid': 605,
                'timestamp': datetime.datetime(2012, 4, 18, 11, 14, 26),
                'lat': 51.8753146,
                'lon': -1.4857118,
                'visible': True,
                'version': 8,
                'user': '******',
                'tag': {
                    'amenity': 'school',
                    'foo': 'bar',
                    'name': 'Berolina & Schule'
                },
            })
        self.assertEquals(
            result[345], {
                'id': 345,
                'changeset': 244,
                'timestamp': datetime.datetime(2009, 9, 12, 3, 22, 59),
                'uid': 1,
                'visible': False,
                'version': 2,
                'user': '******',
                'tag': {},
            })