def parameters(environ, start_response): from json import dumps as tojson vocab = get_vocab(environ) parameters = vocab.getParameterIdsForSubThemeIds(environ['selector.vars']['broader'].split(',')) json = tojson(parameters) headers = [('Cache-Control', 'max-age=3600, must-revalidate'), ('Content-Type', 'application/json')] start_response('200 OK', headers) return [json]
def parameters(environ, start_response): from json import dumps as tojson vocab = get_vocab(environ) parameters = vocab.getParameterIdsForSubThemeIds( environ['selector.vars']['broader'].split(',')) json = tojson(parameters) headers = [('Cache-Control', 'max-age=3600, must-revalidate'), ('Content-Type', 'application/json')] start_response('200 OK', headers) return [json]
def __call__(self, environ, start_response): from json import dumps as tojson self.prepareSOAP(environ) r = self.request() json = tojson({'status': bool(r), 'hits': r.hits, 'time': environ['portal.timer'].runtime()}) headers = [('Content-Type', 'application/json')] start_response('200 OK', headers) return [json]
def query_criteria(environ, start_response): from json import dumps as tojson q = get_query(environ) # Check if the client needs a new version etag = check_etag(environ, str(q)) json = tojson(q.asDict()) headers = [('Content-Type', 'application/json'), ('Etag', etag), ('Cache-Control', 'max-age=3600, must-revalidate')] start_response('200 OK', headers) return [json]
def __call__(self, environ, start_response): from json import dumps as tojson self.prepareSOAP(environ) r = self.request() json = tojson({ 'status': bool(r), 'hits': r.hits, 'time': environ['portal.timer'].runtime() }) headers = [('Content-Type', 'application/json')] start_response('200 OK', headers) return [json]
def get_bbox(environ, start_response): from json import dumps as tojson from medin.spatial import Areas aid = environ['selector.vars']['id'] # the area ID # Check if the client needs a new version etag = check_etag(environ, aid) bbox = Areas(get_db(environ)).getBBOX(aid) if not bbox: raise HTTPError('404 Not Found', 'The area id does not exist: %s' % aid) json = tojson(bbox) headers = [('Content-Type', 'application/json'), ('Etag', etag), ('Cache-Control', 'max-age=3600, must-revalidate')] start_response('200 OK', headers) return [json]
def metadata_image(bboxes, mapfile): """Create a metadata image""" from json import dumps as tojson import mapnik2 as mapnik features = [] for bbox in bboxes: minx, miny, maxx, maxy = bbox # create the bounding box as a json string width, height = (maxx - minx, maxy - miny) min_dim = 0.0125 # minimum dimension for display as a rectangle (in degrees) if width < min_dim or height < min_dim: # it should be a point feature = { "type": "Feature", "geometry": { "type": "Point", "coordinates": [minx, miny] }, "properties": { "type": "point" } } width, height = (9, 9) else: feature = { "type": "Feature", "geometry": { "type": "Polygon", "coordinates": [[[minx, miny], [maxx, miny], [maxx, maxy], [minx, maxy], [minx, miny]]] }, "properties": { "type": "bbox" } } features.append(feature) json = tojson({ "type": "FeatureCollection", "features": features }) # instantiate the map m = mapnik.Map(250, 250) mapnik.load_map_from_string(m, mapfile) # set the datasource for the last layer to show the bounding box datasource = mapnik.Ogr(file=json, layer='OGRGeoJSON') m.layers[-1].datasource = datasource # create an image of the area of interest with a border border = 80.0 # percentage border dx = width * (border / 100) minx2 = minx - dx; maxx2 = maxx + dx dy = height * (border / 100) miny2 = miny - dy; maxy2 = maxy + dy # don't create a border larger than the globe's extent if minx2 < -180.0 or maxx2 > 180.0 or miny2 < -90.0 or maxy2 > 90.0: minx2 = minx; maxx2 = maxx; miny2 = miny; maxy2 = maxy bbox = mapnik.Envelope(mapnik.Coord(minx2, miny2), mapnik.Coord(maxx2, maxy2)) m.zoom_to_box(bbox) image = mapnik.Image(m.width, m.height) mapnik.render(m, image) return image
from json import dumps as tojson, loads as fromjson from os.path import split as splitpath from sys import argv import webbrowser py_filename,description = argv[1],argv[2] _,fname = splitpath(py_filename) content = open(py_filename,'r','utf8').read() data = { "files": { fname: { "content": content } }, "description": description, "public": True, } headers = { 'User-agent': fname, 'Content-type': 'application/json', } connection = http.client.HTTPSConnection('api.github.com') connection.request('POST', '/gists', tojson(data), headers) response = connection.getresponse().read().decode() url = 'https://gist.github.com/%s' % fromjson(response)['id'] print('Gist created: %s' % url) webbrowser.open_new_tab(url)