Kastg commited on
Commit
48e1f5b
·
verified ·
1 Parent(s): 98ed28f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -3,12 +3,17 @@ import os
3
  import psutil
4
  import time
5
  import datetime
 
6
 
7
  app = Flask(__name__)
8
 
9
  # Define the path to static files
10
  static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
11
 
 
 
 
 
12
  @app.route('/css/<path:filename>')
13
  def css(filename):
14
  return send_from_directory(os.path.join(static_dir, 'css'), filename)
@@ -51,10 +56,18 @@ def update_visitor_counts():
51
  last_update_date = current_date
52
  visitor_count += 1
53
  visitor_today += 1
 
 
 
 
 
 
54
 
55
  @app.route('/count')
56
  def count():
57
- return jsonify({'visitor_count': visitor_count, 'visitor_today': visitor_today})
 
 
58
 
59
  # Define the status route
60
  @app.route('/status')
@@ -66,7 +79,7 @@ def status():
66
  return jsonify({'runtime': uptime, 'memory': f'{memory_free} / {memory_total}'})
67
 
68
  # Handle 404 errors
69
- @app.errorhandler(404)
70
  def page_not_found(e):
71
  return send_from_directory(static_dir, '404.html'), 404
72
 
 
3
  import psutil
4
  import time
5
  import datetime
6
+ import json
7
 
8
  app = Flask(__name__)
9
 
10
  # Define the path to static files
11
  static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
12
 
13
+ def write_visitor_count_to_json(data):
14
+ with open('visit_data.json', 'w') as f:
15
+ json.dump(data, f)
16
+
17
  @app.route('/css/<path:filename>')
18
  def css(filename):
19
  return send_from_directory(os.path.join(static_dir, 'css'), filename)
 
56
  last_update_date = current_date
57
  visitor_count += 1
58
  visitor_today += 1
59
+ data = {
60
+ 'visitor_count': visitor_count,
61
+ 'visitor_today': visitor_today,
62
+ 'last_update_date': last_update_date.strftime('%Y-%m-%d')
63
+ }
64
+ write_visitor_count_to_json(data)
65
 
66
  @app.route('/count')
67
  def count():
68
+ with open('visit_data.json', 'r') as f:
69
+ data = json.load(f)
70
+ return jsonify(data)
71
 
72
  # Define the status route
73
  @app.route('/status')
 
79
  return jsonify({'runtime': uptime, 'memory': f'{memory_free} / {memory_total}'})
80
 
81
  # Handle 404 errors
82
+ @app.errorhandler(40)
83
  def page_not_found(e):
84
  return send_from_directory(static_dir, '404.html'), 404
85