OzoneAsai commited on
Commit
12581a3
1 Parent(s): 8fd9b48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -17
app.py CHANGED
@@ -1,12 +1,10 @@
1
-
2
  import hashlib
3
  import time
4
- import csv
5
  from flask import Flask, render_template, request, jsonify
6
 
7
  app = Flask(__name__)
8
  current_text = ""
9
- log_file = 'text_log.csv'
10
 
11
  def get_ip_hash(ip):
12
  return hashlib.sha256(ip.encode()).hexdigest()[:8]
@@ -14,9 +12,7 @@ def get_ip_hash(ip):
14
  def log_text(ip, text):
15
  timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
16
  ip_hash = get_ip_hash(ip)
17
- with open(log_file, 'a', newline='') as csvfile:
18
- writer = csv.writer(csvfile)
19
- writer.writerow([timestamp, ip_hash, text])
20
 
21
  @app.route('/')
22
  def index():
@@ -44,16 +40,7 @@ def get_text():
44
 
45
  @app.route('/log')
46
  def log():
47
- log_data = []
48
- with open(log_file, newline='') as csvfile:
49
- reader = csv.reader(csvfile)
50
- for row in reader:
51
- log_data.append(row)
52
- return render_template('log.html', log_data=log_data)
53
 
54
  if __name__ == '__main__':
55
- # Create log file with headers if it doesn't exist
56
- with open(log_file, 'a', newline='') as csvfile:
57
- writer = csv.writer(csvfile)
58
- writer.writerow(['Timestamp', 'IP Hash', 'Text'])
59
- app.run(debug=True, host="0.0.0.0", )
 
 
1
  import hashlib
2
  import time
 
3
  from flask import Flask, render_template, request, jsonify
4
 
5
  app = Flask(__name__)
6
  current_text = ""
7
+ logs = []
8
 
9
  def get_ip_hash(ip):
10
  return hashlib.sha256(ip.encode()).hexdigest()[:8]
 
12
  def log_text(ip, text):
13
  timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
14
  ip_hash = get_ip_hash(ip)
15
+ logs.append([timestamp, ip_hash, text])
 
 
16
 
17
  @app.route('/')
18
  def index():
 
40
 
41
  @app.route('/log')
42
  def log():
43
+ return render_template('log.html', log_data=logs)
 
 
 
 
 
44
 
45
  if __name__ == '__main__':
46
+ app.run(debug=True, host="0.0.0.0")