def main(): # falcon.API instances are callable WSGI apps #api = falcon.API() api = falcon.API(middleware=[ falcon_jsonify.Middleware(help_messages=True), ]) # Resources are represented by long-lived class instances pgclient = PgResource(config['db']) # things will handle all requests to the '/things' URL path api.add_route('/', pgclient) api.add_route('/q', pgclient) #httpd = simple_server.make_server('127.0.0.1', 8000, api) log.info('start') #httpd.serve_forever() serve(api, host='0.0.0.0', port=8000, threads=6, _quiet=True)
def create(settings_module_name=None) -> falcon.API: """Create and return an app instance.""" settings = load_settings(module_name=settings_module_name) session_factory = get_session_factory(settings.DATABASE_BACKEND.url) cors = CORS( allow_all_methods=True, allow_all_origins=True, allowed_headers=['content-type'], ) middleware = [ cors.Middleware(), falcon_jsonify.Middleware(help_messages=True), SQLAlchemySessionManager(factory=session_factory), ] if settings.LOG: middleware.append(ResponseLoggerMiddleware()) app = falcon.API(middleware=middleware) add_routes(app, routes) return app
nltk.download('punkt') nltk.download('averaged_perceptron_tagger') nltk.download('maxent_ne_chunker') nltk.download('words') dbcfg = { 'host': '10.0.42.168', # or external server address 'port': 27017, #'username': os.environ.get('MONGO_USER'), 'username': '******', #'password': os.environ.get('MONGO_PASS'), 'password': '******', } middleware = [ falcon_jsonify.Middleware(help_messages=True), ] class ArticleModel(Document): #_id = ObjectIdField(required=True) meta = {'collection': 'prelp'} _id = ObjectIdField() title = StringField(max_length=100, required=True) href = URLField(max_length=100, required=True, unique=True) ts = FloatField(required=True) pri = IntField() kr = StringField(max_length=100) h1 = StringField(max_length=100, required=True) h2 = StringField(max_length=100) txt = StringField(max_length=10000, required=True)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import asyncio import uvloop import falcon import falcon_jsonify from tornado import ioloop from motorengine import connect from middlewares.error import ErrorHandler asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) api = falcon.API(middleware=[ falcon_jsonify.Middleware( help_messages=True), # show helpful debug messages ErrorHandler() ]) connect("py-api", host="localhost", port=27017, io_loop=ioloop.IOLoop.instance())
import falcon import falcon_jsonify import mongoengine as mongo import settings mongo.connect(host=settings.MONGO) print(settings.MONGO) print("Mongo Connected!") api = falcon.API(middleware=[ falcon_jsonify.Middleware(help_messages=settings.DEBUG), ])