Spaces:
Running
Running
Kastg
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -10,10 +10,6 @@ app = Flask(__name__)
|
|
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)
|
@@ -44,10 +40,11 @@ def info():
|
|
44 |
visitor_count = 0
|
45 |
visitor_today = 0
|
46 |
last_update_date = datetime.datetime.now().date()
|
|
|
47 |
|
48 |
@app.before_request
|
49 |
def update_visitor_counts():
|
50 |
-
global visitor_count, visitor_today, last_update_date
|
51 |
allowed_paths = ['/ai', '/api', '/tool']
|
52 |
if request.path.startswith(tuple(allowed_paths)):
|
53 |
current_date = datetime.datetime.now().date()
|
@@ -56,18 +53,25 @@ def update_visitor_counts():
|
|
56 |
last_update_date = current_date
|
57 |
visitor_count += 1
|
58 |
visitor_today += 1
|
59 |
-
|
60 |
-
|
61 |
-
|
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 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
|
72 |
# Define the status route
|
73 |
@app.route('/status')
|
|
|
10 |
# Define the path to static files
|
11 |
static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)))
|
12 |
|
|
|
|
|
|
|
|
|
13 |
@app.route('/css/<path:filename>')
|
14 |
def css(filename):
|
15 |
return send_from_directory(os.path.join(static_dir, 'css'), filename)
|
|
|
40 |
visitor_count = 0
|
41 |
visitor_today = 0
|
42 |
last_update_date = datetime.datetime.now().date()
|
43 |
+
visitor_total = 0
|
44 |
|
45 |
@app.before_request
|
46 |
def update_visitor_counts():
|
47 |
+
global visitor_count, visitor_today, last_update_date, visitor_total
|
48 |
allowed_paths = ['/ai', '/api', '/tool']
|
49 |
if request.path.startswith(tuple(allowed_paths)):
|
50 |
current_date = datetime.datetime.now().date()
|
|
|
53 |
last_update_date = current_date
|
54 |
visitor_count += 1
|
55 |
visitor_today += 1
|
56 |
+
visitor_total += 1
|
57 |
+
if datetime.datetime.now().hour == 0 and datetime.datetime.now().minute == 0:
|
58 |
+
reset_visitor_count()
|
|
|
|
|
|
|
59 |
|
60 |
@app.route('/count')
|
61 |
def count():
|
62 |
+
return jsonify({
|
63 |
+
'visitor_count': visitor_count,
|
64 |
+
'visitor_today': visitor_today,
|
65 |
+
'visitor_total': visitor_total
|
66 |
+
})
|
67 |
+
|
68 |
+
@app.route('/reset')
|
69 |
+
def reset_visitor_count():
|
70 |
+
global visitor_count, visitor_today, last_update_date
|
71 |
+
visitor_count = 0
|
72 |
+
visitor_today = 0
|
73 |
+
last_update_date = datetime.datetime.now().date()
|
74 |
+
return jsonify({'visitor_count': visitor_count, 'visitor_today': visitor_today})
|
75 |
|
76 |
# Define the status route
|
77 |
@app.route('/status')
|