Kastg commited on
Commit
c882742
·
verified ·
1 Parent(s): 61a1e59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -3
app.py CHANGED
@@ -1,14 +1,65 @@
1
  from flask import Flask, request, jsonify, send_from_directory
2
  import os
3
  import requests
4
- from PIL import Image
5
- from io import BytesIO
6
  import psutil
7
  import time
8
- import datetime # Add this line to import datetime module
9
 
10
  app = Flask(__name__)
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  @app.route("/uptime")
13
  def uptime():
14
  # Get system uptime using psutil
 
1
  from flask import Flask, request, jsonify, send_from_directory
2
  import os
3
  import requests
4
+ import json
 
5
  import psutil
6
  import time
7
+ import datetime
8
 
9
  app = Flask(__name__)
10
 
11
+ # Define the path to static files
12
+ static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static')
13
+
14
+ @app.route('/')
15
+ def index():
16
+ return send_from_directory(static_dir, 'index.html')
17
+
18
+ @app.route('/ai')
19
+ def ai():
20
+ return send_from_directory(static_dir, 'views/ai.html')
21
+
22
+ @app.route('/info')
23
+ def info():
24
+ ip = request.remote_addr
25
+ current_time = datetime.datetime.now().strftime("%H:%M:%S")
26
+ return jsonify({'ip': ip, 'current_time': current_time})
27
+
28
+ # Define the visitor count routes
29
+ visitor_count = 0
30
+ visitor_today = 0
31
+ last_update_date = datetime.datetime.now().date()
32
+
33
+ @app.before_request
34
+ def update_visitor_counts():
35
+ global visitor_count, visitor_today, last_update_date
36
+ allowed_paths = ['/ai', '/api', '/tool']
37
+ if request.path.startswith(tuple(allowed_paths)):
38
+ current_date = datetime.datetime.now().date()
39
+ if current_date != last_update_date:
40
+ visitor_today = 0
41
+ last_update_date = current_date
42
+ visitor_count += 1
43
+ visitor_today += 1
44
+
45
+ @app.route('/count')
46
+ def count():
47
+ return jsonify({'visitor_count': visitor_count, 'visitor_today': visitor_today})
48
+
49
+ # Define the status route
50
+ @app.route('/status')
51
+ def status():
52
+ uptime_seconds = int(time.time() - psutil.boot_time())
53
+ uptime = str(datetime.timedelta(seconds=uptime_seconds))
54
+ memory_free = psutil.virtual_memory().available
55
+ memory_total = psutil.virtual_memory().total
56
+ return jsonify({'runtime': uptime, 'memory': f'{memory_free} / {memory_total}'})
57
+
58
+ # Handle 404 errors
59
+ @app.errorhandler(404)
60
+ def page_not_found(e):
61
+ return send_from_directory(static_dir, '404.html'), 404
62
+
63
  @app.route("/uptime")
64
  def uptime():
65
  # Get system uptime using psutil