Esempio n. 1
0
def store_capitals_gcs(id):
    gcs = cloudstorage.Storage()
    content = request.get_json()
    bucket_name = content["bucket"]
    gcs.create_bucket(bucket_name)

    cap = capital.Capital_Service()
    empty_city = {}
    empty_city["code"] = 0
    empty_city["message"] = "string"
    try:
        query = cap.ds.query(kind=cap.kind)
        query.add_filter('id', '=', int(id))
        city = []
        for ent in list(query.fetch()):
            city.append(dict(ent))
        if len(city) != 0:
            cap_json = cap.good_json(city[0])
        else:
            return make_response("Capital record not found", 404)
    except Exception as e:
        return make_response("Unexpected error", 404)

    bucket = gcs.gcs.get_bucket(bucket_name)
    blob = bucket.blob(id)
    try:
        blob.upload_from_string(data=json.dumps(cap_json))
        return make_response("Successfully stored in GCS", 200)
    except Exception as e:
        return make_response("Unexpected error", 404)
Esempio n. 2
0
def map():
    cap = capital.Capital_Service()
    query = cap.ds.query(kind=cap.kind)
    query.order = ['id']
    city = []
    for ent in list(query.fetch()):
        city.append(dict(ent))
    lat = []
    lon = []
    for c in city:
        lon.append(str(c['longitude']))
        lat.append(str(c['latitude']))
    return render_template('map.html', lat_long=zip(lat, lon))
Esempio n. 3
0
def create_map():
    cap = capital.Capital_Service()
    query = cap.ds.query(kind=cap.kind)
    query.order = ['id']
    city = []
    for ent in list(query.fetch()):
        city.append(dict(ent))
    features = []
    for c in city:
        point = geojson.Point((float(c['longitude']), float(c['latitude'])))
        feature = geojson.Feature(geometry=point)
        features.append(feature)
    collection = geojson.FeatureCollection(features)
    return render_template('map_template.html', geocode=collection)
Esempio n. 4
0
def get_capital(id):
    cap = capital.Capital_Service()
    result = cap.get_capital(id)
    return result
Esempio n. 5
0
def put_capital(id):
    """inserts capital from datastore"""
    cap_service = capital.Capital_Service()
    text = request.get_json()
    result = cap_service.insert_capital(id, text)
    return result
Esempio n. 6
0
def publish(id):
    cap = capital.Capital_Service()
    ob = request.get_json()
    result = cap.publish_capital(int(id), ob)
    return result
Esempio n. 7
0
def capital_list():
    cap = capital.Capital_Service()
    entries = cap.get_list()
    return render_template('list_template.html', entries=entries)
Esempio n. 8
0
def get_all_capitals():
    cap = capital.Capital_Service()
    query_param = request.args.get('query', '')
    search_param = request.args.get('search', '')
    result = cap.fetch_capitals(query_param, search_param)
    return result
Esempio n. 9
0
def delete_capital(id):
    cap = capital.Capital_Service()
    result = cap.delete_capital(id)
    return result