-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (57 loc) · 2.28 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from flask import Flask, jsonify, request, url_for, render_template
from flask_migrate import Migrate
import time
import os
import random
from modulos import get_current_directory
appUrls = 'https://flaskchatbotmoz.herokuapp.com'
def create_app():
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + \
os.path.join(os.path.dirname(__file__), 'dados.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
from app.db import init_db
init_db(app)
Migrate(app,app.db)
from app.models.admin import User
from app.views.users.bp_users import users_bp
app.register_blueprint(users_bp, url_prefix='/users_page')
@app.route("/", methods=['GET', 'POST'])
def index():
# clie = User(username='admin', email='[email protected]')
# db.session.add(admin)
# db.session.commit()
# print(algo)
return render_template('index.html')
routa2 = 'https://flaskchatbotmoz.herokuapp.com/bot'
# @app.shell_context_processor
# def make_shell_context():
# # com isto aki posso entrar no shell e fazer testes esporatico
# '''
# db.create_all() >> criare o banco
# '''
# return dict(app=app, db=app.db, User=User)
@app.route('/bot', methods=['POST', 'GET'])
def response():
print(request.method)
if request.method == 'GET':
return jsonify({'method': request.method, 'info': 'fizeste um GET por isso esta tendo esta resposta queira entao fazer um POST?'})
# recebo o posto mandado por cliente
# e devolvo para ele o result + a hora que este response foi feita
query = dict(request.form)['query']
result = 'comando nao reconhecido'
if 'name' in query:
result = 'my name is saidinoBot from python'
elif 'image' in query.lower():
result = 'thats is saidino image https://flaskchatbotmoz.herokuapp.com/static/image/hacking_tool.png'
else:
result = 'That command have not implemented yet'
response = result+" \ntime is :"+time.ctime()
return jsonify(response)
return app
def main():
app = create_app()
port = int(os.environ.get('PORT', 8000))
app.run(host='0.0.0.0', port=port)
if __name__ == '__main__':
main()