代码拉取完成,页面将自动刷新
同步操作将从 lucky/nationalparks-katacoda 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from __future__ import print_function
import os
import json
from flask import Flask, request
from flask_restful import Resource, Api
application = Flask(__name__)
api = Api(application)
class HealthCheck(Resource):
def get(self):
return 'OK'
api.add_resource(HealthCheck, '/ws/healthz/')
class Info(Resource):
description = {
'id': 'nationalparks-py',
'displayName': 'National Parks (PY)',
'type': 'cluster',
'center': {'latitude': '47.039304', 'longitude': '14.505178'},
'zoom': 4
}
def get(self):
return self.description
api.add_resource(Info, '/ws/info/')
def format_result(entries):
result = []
for entry in entries:
data = {}
data['id'] = entry['name']
data['latitude'] = str(entry['coordinates'][0])
data['longitude'] = str(entry['coordinates'][1])
data['name'] = entry['toponymName']
result.append(data)
return result
DATASET_FILE = 'nationalparks.json'
dataset = []
def load_data(filename):
global dataset
dataset = []
with open(filename, 'r') as fp:
for data in fp.readlines():
dataset.append(json.loads(data))
return len(dataset)
load_data(DATASET_FILE)
class DataLoad(Resource):
def get(self):
count = load_data(DATASET_FILE)
return 'Inserted %s items.' % count
api.add_resource(DataLoad, '/ws/data/load')
class DataAll(Resource):
def get(self):
return format_result(dataset)
api.add_resource(DataAll, '/ws/data/all')
@application.route('/')
def index():
return 'Welcome to the National Parks data service.'
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。