def create_app(name=None): app = Flask(name) if os.environ.get("PRODUCTION"): app.config.from_object(ProductionConfig) print "running with ProductionConfig" else: app.config.from_object(DefaultConfig) print "running with DefaultConfig" # sentry if app.config.get("SENTRY_DSN"): sentry = Sentry() sentry.init_app(app) app.sentry = sentry # assets assets = Environment(app) assets.url = app.static_url_path scss_bundle = Bundle( "css/*.scss", "css/*.css", filters=["scss", "cssmin"], depends="css/*.scss", output="css/all.css" ) assets.register("scss_all", scss_bundle) js_bundle = Bundle("js/*.js", filters="rjsmin", output="js/all.js") assets.register("js_all", js_bundle) Compress(app) # cache if app.config["DEBUG"]: cache_type = "null" else: cache_type = "simple" cache = Cache(config={"CACHE_TYPE": cache_type}) cache.init_app(app) app.cache = cache # CDN cdn = CDN() cdn.init_app(app) # workaround flask-assets / flask-cdn integration if app.config.get("CDN_HTTPS"): cdn_scheme = "https" else: cdn_scheme = "http" if app.config.get("FLASK_ASSETS_USE_CDN") and app.config.get("CDN_DOMAIN"): app.jinja_env.globals["FLASK_CDN"] = "%s://%s" % (cdn_scheme, app.config["CDN_DOMAIN"]) return app
from flask import Flask, request, current_app from bot import Osmbot from configobj import ConfigObj import os from raven.contrib.flask import Sentry application = Flask(__name__) application.debug = True Osmbot(application, "") config = ConfigObj("bot.conf") token = config["token"] bot = OSMbot(token) if "sentry_dsn" in config: application.config["sentry_dsn"] = config["sentry_dsn"] sentry = Sentry(application, dsn=config["sentry_dsn"]) sentry.captureMessage("OSMBot started", level=logging.INFO) application.sentry = sentry f = open("nginx.crt", "r") cert_data = f.read() f.close() webhook = os.path.join(config["webhook"], config["token"]) application.logger.debug("webhook:%s", config["webhook"]) response = bot.setWebhook(webhook, cert_data) application.logger.debug("response:%s", response) if __name__ == "__main__": application.run(host="0.0.0.0", debug=True)