-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
70 lines (54 loc) · 1.61 KB
/
app.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
from flask import Flask, render_template, request, jsonify, session
import sqlite3
app = Flask(__name__)
app.secret_key = 'your_secret_key'
# Conectar ao banco de dados SQLite
def get_db():
conn = sqlite3.connect('database.db')
return conn
# Criar tabela para armazenar itens
def create_table():
with get_db() as conn:
conn.execute('''
CREATE TABLE IF NOT EXISTS items (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id TEXT,
name TEXT,
link TEXT
)
''')
# Rota para a página inicial
@app.route('/')
def index():
return render_template('index.html')
@app.route('/add-item', methods=['POST'])
def add_item():
if 'user_id' not in session:
# Exemplo de ID do usuário
session['user_id'] = 'user123'
data = request.json
user_id = session['user_id']
name = data['name']
link = data['link']
with get_db() as conn:
conn.execute('INSERT INTO items (user_id, name, link) VALUES (?, ?, ?)', (user_id, name, link))
return jsonify({'success': True})
@app.route('/get-items', methods=['GET'])
def get_items():
if 'user_id' not in session:
return jsonify({'items': []})
user_id = session['user_id']
with get_db() as conn:
cursor = conn.execute('SELECT name, link FROM items WHERE user_id = ?', (user_id,))
items = cursor.fetchall()
return jsonify({'items': items})
if __name__ == '__main__':
create_table()
app.run(debug=True)
"""
100.20.92.101
44.225.181.72
44.227.217.144
http://<sua-url-render>/
http://44.227.217.144/
"""