Пример #1
0
def updateSegmentState(segmentId, state):
    token = authInstance.getAccessToken()
    data = {'id_state': state}

    response = requests.put('http://api.map.vl.dev/traffic/segments/%s?token=%s'
                       % (segmentId, token), json=data)

    if response.status_code != requests.codes.ok:
        authInstance.invalidateAccessToken()
        updateSegmentState(segmentId, state)
    def __getCollections(self):
        token = authInstance.getAccessToken()

        response = requests.get('%s?token=%s' % (config.ALLOWED_SEGMENTS_API_URL, token))

        if response.status_code != requests.codes.ok:
            authInstance.invalidateAccessToken()
            return self.__getCollections()

        collections = {'device': None, 'bus': None}

        for collection in json.loads(response.text):
            if collection['id_collection'] == config.ALLOWED_SEGMENTS_ID_DEVICE_COLLECTION:
                collections['device'] = collection['ids']

            if collection['id_collection'] == config.ALLOWED_SEGMENTS_ID_BUS_COLLECTION:
                collections['bus'] = collection['ids']

        assert collections['device'] is not None, 'There is no device collection'
        assert collections['bus'] is not None, 'There is nit bus collection'

        return collections