# The token must provide CRUD (create read update delete) privileges
username = '******'
access_token = '{insert your own Mapbox API here}'

# IEC API credentials
ELusername = '******'
ELpassword = '******'
ELaccess_token = '{insert your own IEC API token here}'

# Set the HTTP Basic Auth header for the IEC API
headers = {'Authorization': 'bearer ' + ELaccess_token}

# Lets see how many datasets we have at Mapbox and ensure our credentials work
# https://docs.mapbox.com/api/maps/#datasets
datasets = Datasets(access_token=access_token)
listing_resp = datasets.list()
if listing_resp.status_code != 200:
    raise ApiError('GET dataset failed {}'.format(resp.status_code))
for dataset in listing_resp.json():
    print('Found Mapbox dataset: {}'.format(dataset['name']))

# Now lets create a test feature in Cape Town for each of our datasets
# This can be any GeoJson object - http://geojson.org/
#feature = {'type': 'Feature', 'id': '100001', 'properties': {'name': 'Just a Test Feature with fake ID'},
#			'geometry': {'type': 'Point', 'coordinates': [18.4, -33.9]}}
#resp = datasets.update_feature(dataset['id'], '100001', feature)
#print('Created feature response: {} '.format(str(resp.status_code)))

# While testing your environment - we stop the engine here
# When ready comment these two lines out to run the actual engine
print('It works!')
Esempio n. 2
0
from requests.packages.urllib3.exceptions import InsecureRequestWarning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

idlayer = 'cin2p1rmm0bqvvhm47cjvcsor'
access_token = 'pk.eyJ1Ijoic2Vkb25hY2hhbWJlciIsImEiOiJjaW13Zmp3cGswMzd0d2tsdXBnYmVjNmRjIn0.PlcjviLrxQht-_tBEbQQeg'
secretkey = 'sk.eyJ1Ijoic2Vkb25hY2hhbWJlciIsImEiOiJjaW5qYXFjeHYweG5hdWlranFxZHpxYXhrIn0.2oaLx8HQUCtSzef6ozEaiQ'
datasets = Datasets()


#tokenurl = "https://www.mapbox.com/core/tokens/v1?_="+str(int(time.time()))
#r = requests.get(tokenurl);

datasets.session.params['access_token'] = access_token

datasets.list().json()

response = Datasets(access_token=secretkey).read_dataset(idlayer).json()

collection = datasets.list_features(idlayer).json()

for q in collection:
	
#read
#resp = datasets.read_feature(idlayer, '2')

#update
#update = {'type': 'Feature', 'id': '2', 'properties': {'name': 'Insula Nulla C'},
#	'geometry': {'type': 'Point', 'coordinates': [0, 0]}}

#update = datasets.update_feature(idlayer, '2', update).json()