-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.py
41 lines (29 loc) · 1.07 KB
/
notes.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
from flask import request, jsonify, render_template, url_for, redirect, session
def index1():
# Verifica se a sessão login está definida como False
if session.get("login") == False:
return redirect(url_for("login")) # Redireciona para a página de login
return render_template('index.html')
# Função para carregar os textos salvos de um arquivo
def load_texts():
try:
with open('shared_text.txt', 'r') as file:
return file.read()
except FileNotFoundError:
return ""
# Função para salvar o texto digitado no arquivo
def save_text(text):
with open('shared_text.txt', 'w') as file:
file.write(text)
def index():
shared_text = load_texts() # Carregar o texto
return render_template('index.html', shared_text=shared_text)
def save():
try:
text = request.json['text']
text = text.replace('<br>', '\n') # Substituir <br> por quebras de linha
save_text(text)
return jsonify(success=True)
except Exception as e:
print(e)
return jsonify(success=False)