本文整理匯總了Python中flask.ext.api.FlaskAPI.config['MONGOTIME_HOST']方法的典型用法代碼示例。如果您正苦於以下問題:Python FlaskAPI.config['MONGOTIME_HOST']方法的具體用法?Python FlaskAPI.config['MONGOTIME_HOST']怎麽用?Python FlaskAPI.config['MONGOTIME_HOST']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flask.ext.api.FlaskAPI
的用法示例。
在下文中一共展示了FlaskAPI.config['MONGOTIME_HOST']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: FlaskAPI
# 需要導入模塊: from flask.ext.api import FlaskAPI [as 別名]
# 或者: from flask.ext.api.FlaskAPI import config['MONGOTIME_HOST'] [as 別名]
# mongodb://ktruong:[email protected]:57702/canopy_test
import datetime
from flask import request, url_for
from flask.ext.api import FlaskAPI, status, exceptions
from flask_pymongo import PyMongo
import requests
app = FlaskAPI(__name__)
mongo = PyMongo(app, config_prefix='MONGOTIME')
app.config['MONGOTIME_HOST'] = 'mongodb://ktruong:[email protected]:57702/canopy_test'
app.config['MONGOTIME_PORT'] = 57702
app.config['MONGOTIME_DBNAME'] = 'canopy_test'
google_api_key = 'AIzaSyD9XTc6eSisK4Qgy37RHMOE3MlFLUjwFu0' # NOTE: save in .env with python-dotenv
@app.route('/<string:postal>', methods=['GET'])
def get_postal_code(postal):
if request.method == 'GET' and postal:
# postal_info = mongo.db.MONGOTIME.find_one_or_404(postal)
# return postal_info
# Get latitude, longitude
zippo_request = requests.get('http://api.zippopotam.us/us/{}'.format(postal))
if zippo_request and int(zippo_request.status_code) <= 300:
json_data = zippo_request.json()
zip_code = json_data.get('post code', None)
latitude = json_data.get('places', {})[0].get('latitude') # string format that can be negative
longitude = json_data.get('places', {})[0].get('longitude')
timestamp = datetime.datetime.now().timestamp()
# Get timezone