Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ================= APP.PY ===============================
- #!/usr/bin/env python
- import imp
- import os
- import sys
- try:
- zvirtenv = os.path.join(os.environ['OPENSHIFT_PYTHON_DIR'],
- 'virtenv', 'bin', 'activate_this.py')
- execfile(zvirtenv, dict(__file__ = zvirtenv) )
- except IOError:
- pass
- def run_gevent_server(app, ip, port=8080):
- from gevent.pywsgi import WSGIServer
- WSGIServer((ip, port), app).serve_forever()
- def run_simple_httpd_server(app, ip, port=8080):
- from wsgiref.simple_server import make_server
- make_server(ip, port, app).serve_forever()
- #
- # IMPORTANT: Put any additional includes below this line. If placed above this
- # line, it's possible required libraries won't be in your searchable path
- #
- #
- # main():
- #
- if __name__ == '__main__':
- #Setting path for external libs
- sys.path.append('libs')
- sys.path.append('wsgi')
- #
- ip = os.environ['OPENSHIFT_PYTHON_IP']
- port = int(os.environ['OPENSHIFT_PYTHON_PORT'])
- zapp = imp.load_source('application', 'wsgi/application')
- # Use gevent if we have it, otherwise run a simple httpd server.
- print 'Starting WSGIServer on %s:%d ... ' % (ip, port)
- try:
- run_gevent_server(zapp.application, ip, port)
- except:
- print 'gevent probably not installed - using default simple server ...'
- run_simple_httpd_server(zapp.application, ip, port)
- ================= APPLICATION.PY ==========================
- #!/usr/bin/python
- import os
- import sys
- sys.path.insert(0, os.path.dirname(__file__) or '.')
- if os.path.exists(os.path.join(os.environ['OPENSHIFT_HOMEDIR'], "python-2.6")):
- PY_DIR = os.path.join(os.environ['OPENSHIFT_HOMEDIR'], "python-2.6")
- else:
- PY_DIR = os.path.join(os.environ['OPENSHIFT_HOMEDIR'], "python")
- virtenv = PY_DIR + '/virtenv/'
- PY_CACHE = os.path.join(virtenv, 'lib', '2.6', 'site-packages')
- os.environ['PYTHON_EGG_CACHE'] = os.path.join(PY_CACHE)
- virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
- try:
- execfile(virtualenv, dict(__file__=virtualenv))
- except IOError:
- pass
- from rssfinderflaskapp import app as application
- =============rssfinderflaskapp.py =========================
- from flask import Flask
- from flask import request
- from flask import Response
- import json
- from myanalytics import myanalytics
- app = Flask(__name__)
- #add this so that flask doesn't swallow error messages
- app.config['PROPAGATE_EXCEPTIONS'] = True
- manal = myanalytics()
- def getArgs(rq):
- lang = rq.args.get('l', None)
- query = rq.args.get('q', None)
- force = rq.args.get('f', None)
- if not lang or not query:
- raise Exception
- return lang, query, force
- @app.errorhandler(404)
- def page_not_found(error):
- ip = request.remote_addr
- manal.track("ERROR", {"ip": ip, "type" : 404, "msg": request.path})
- return 'Hey man, this page does not exist', 404
- @app.route("/healthy")
- def health():
- return "OK", 200
- if __name__ == "__main__":
- debug_mode = True
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement