def index(request): if bool(request): request = request.replace("%2C", "," ) request = request.replace("%20", " " ) fromm, to, percent, maxmin = request.split(":") from_cds = [gmaps.geocode(fromm)[0]['geometry']['location']['lat'], gmaps.geocode(fromm)[0]['geometry']['location']['lng']] to_cds = [gmaps.geocode(to)[0]['geometry']['location']['lat'], gmaps.geocode(to)[0]['geometry']['location']['lng']] print (from_cds) print (to_cds) print (percent) print (maxmin) current_session = Session_data(from_cds,to_cds,float(int(percent)/100)) if maxmin == 'min': print ("Minimum elevation route follows these co-ordinates:") dist, ele_gain, route = current_session.min_elevation_route() route_coords = current_session.route_coordinates(route) print (route_coords) elif maxmin == 'max': print ("Maximum elevation route follows these co-ordinates:") dist, ele_gain, route = current_session.max_elevation_route() route_coords = current_session.route_coordinates(route) print (route_coords) return jsonify(elevation=ele_gain, distance=dist, waypoints=route_coords)
def get_genres_dict(API_KEY): request = 'https://api.themoviedb.org/3/genre/movie/list?api_key={API_KEY}&language=en-US' request = request.replace('{API_KEY}', API_KEY) resp = requests.get(request) genres = resp.json()['genres'] genres_dict = {} for i in range(len(genres)): genres_dict[genres[i]['name'].lower()] = genres[i]['id'] return genres_dict
def __check_request(method: str = "") -> str: """ 检查返回的错误信息是否合规则 :param request: 返回的请求地址 :return: 如果请求的地址为空,则返回空字符串 """ methods: List[str] = ["get", "post", "put", "patch", "delete", "*"] request: str = method.lower() request = request.strip() if len(request) == 0: return "" for method in methods: if request.startswith(method): request = request.replace(method, method.upper()) break else: request = "GET {}".format(request) return request
def __checkRequest(request="") -> str: """ 检查返回的错误信息是否合规则 :param request: 返回的请求地址 :return: 如果请求的地址为空,则返回空字符串 """ methods = ['get', 'post', 'put', 'patch', 'delete', '*'] request = request.lower() request = request.strip() if len(request) == 0: return "" for method in methods: if request.startswith(method): request = request.replace(method, method.upper()) break else: request = "GET {}".format(request) return request
def download_plot(request): print request return send_from_directory(directory='static/plots_maps/', filename=request.replace('png', 'pdf'), as_attachment=True)