本文整理汇总了Python中flask.ext.api.FlaskAPI.config['MONGOTIME_DBNAME']方法的典型用法代码示例。如果您正苦于以下问题:Python FlaskAPI.config['MONGOTIME_DBNAME']方法的具体用法?Python FlaskAPI.config['MONGOTIME_DBNAME']怎么用?Python FlaskAPI.config['MONGOTIME_DBNAME']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.ext.api.FlaskAPI
的用法示例。
在下文中一共展示了FlaskAPI.config['MONGOTIME_DBNAME']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FlaskAPI
# 需要导入模块: from flask.ext.api import FlaskAPI [as 别名]
# 或者: from flask.ext.api.FlaskAPI import config['MONGOTIME_DBNAME'] [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