Example #1
0
def run_flask(host='0.0.0.0', port='8000'):
    """Run Flask server."""
    from autoapp import app

    app.run(
        host=host,
        port=port,
        # FIXME: reloader only works in the main thread. Find a way to run Flask that way
        use_reloader=False,
    )
Example #2
0
def start_api():
    """Helper function to run the API and listen for incoming connections"""
    try:
        app.run(host='0.0.0.0', port=8000, reloader=True, debug=True)
    except Exception:
        bottle.response.headers['Content-Type'] = 'application/json'
        bottle.response.headers['Cache-Control'] = 'no-cache'
        bottle.response.status = 500

        json.dumps({
            'status':  'error',
            'message': 'Internal Server Error',
            'code':    500
        })
    add_cors_headers()


@bottle.hook('after_request')
def enable_cors_after_request_hook():
    """
    This executes after every route. We use it to attach CORS headers when
    applicable.
    """
    add_cors_headers()

def add_cors_headers():

    '''allow only this ip address'''
    logging.info("printing cors request below")
    logging.info(request)
    allowed_url = 'http://127.0.0.1:' + bottle.request.environ['HTTP_ORIGIN'][-4:]
    bottle.response.headers['Access-Control-Allow-Origin'] = '*'
    bottle.response.headers['Access-Control-Allow-Methods'] = \
        'GET, POST, PUT, OPTIONS'
    bottle.response.headers['Access-Control-Allow-Headers'] = \
        'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'

app = bottle.app()
app.run(port=8070)
# run(server='gunicorn', host='localhost', port=8070, debug=True, timeout=9999)
# The following lines will call the BottleDaemon script and launch a daemon in the background.
# if __name__ == "__main__":
#     daemon_run()

from bottle import route, get, post, view, run, app, default_app, static_file
from palpite import palpite

@get('/')
@view('index.html')
def index_get():
    return dict()

@post('/')
@view('index.html')
def index_post():
    gera_palpite = palpite()
    return dict(jogo=gera_palpite)

@get('/favicon.ico')
@get('/favicon.png')
def favicon():
    return static_file('/static/favicon.png', root='.')

@get('/normalize.css')
def normalizecss():
    return static_file('normalize.css', root='static')

@get('/skeleton.css')
def skeletoncss():
    arq = 'skeleton.css'
    return static_file(arq, root='./static')

app = default_app()
app.run(server='gae',debug=True)
Example #5
0
    myredis.set("name", "Василий")
    return "set foo=bar, name=Василий"


# --------------- getredis
#REDO


@redis_dec
@app.get('/getredis')
def getredis():
    """ test req to get redis value """

    foo = myredis.get("foo")
    name = myredis.get("name")
    return "got foo=%s, name=%s" % (str(foo), str(name))


# ---------------- caller

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80, debug=True, reload=True)
#    app.run (server='gunicorn', host='0.0.0.0', port=80, debug=True, reload=True)

#    app.debug (True)
#    app.run (host='0.0.0.0', port=8080)
#    app.run (host='localhost', port=8080)

# the end.
# =======================================================
Example #6
0
File: web.py Project: mykespb/damba
# --------------- getredis
#REDO


@redis_dec
@app.get('/getredis')
def getredis():
    """ test req to get redis value """

    foo = myredis.get("foo")
    name = myredis.get("name")

    return "got foo=%s, name=%s" % (str(foo), str(name))


# ---------------- caller

if __name__ == '__main__':
    app.run(server='gunicorn',
            host='0.0.0.0',
            port=80,
            debug=True,
            reload=True)

#    app.debug (True)
#    app.run (host='0.0.0.0', port=8080)
#    app.run (host='localhost', port=8080)

# the end.
# =======================================================
Example #7
0

# --------------- getredis


@redis_dec
@app.get('/getredis')
def getredis():
    """ test req to get redis value """

    foo = myredis.get("foo")
    name = myredis.get("name")
    return "got foo=%s, name=%s" % (str(foo), str(name))


# ---------------- caller

if __name__ == '__main__':
    app.run(server=params["web_driver"],
            host='0.0.0.0',
            port=8001,
            debug=True,
            reload=True)

#    app.debug (True)
#    app.run (host='0.0.0.0', port=8080)
#    app.run (host='localhost', port=8080)

# the end.
# =======================================================
Example #8
0
def articleCreate():
	c.execute('SELECT user_id, name FROM friends')
	a = dataToDict(c.fetchall())
	return template('view/header.html', title=l_title.get("myDiary","???"), url=url, lan=l_header) + template('view/diaryAdd.html', people=a, url=url, lan=l_diaryAC, textEditor=l_textEditor) + template('view/footer.html', lan=l_footer)

# Diary create article POST
@app.post('/diary/create')
def add():
	title = str(request.forms.get('title')).rstrip().lstrip()
	article = request.forms.get('article').rstrip().lstrip()
	c.execute('INSERT INTO diary (title, article, date) VALUES (?, ?, ?)', (title, article, time.strftime("%d.%m.%Y")))
	conn.commit()
	redirect('/diary/' + str(c.lastrowid))

# Settings GET
@app.route('/settings')
def settings(): 
	return template('view/header.html', title="Settings", url=url, lan=l_header) + template('view/settings.html', url=url, language=lan, lan=l_settings) + template('view/footer.html', lan=l_footer)

# Settings POST
@app.post('/settings')
def settingsSave():
	redirect('/settings')

# Routing for static files
@app.route('/static/<filename:path>', name="static")
def static(filename): return static_file(filename, root='static/') 

# getLan()
app.run(host='localhost', port=8080)