-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
71 lines (54 loc) · 2.92 KB
/
app.py
File metadata and controls
71 lines (54 loc) · 2.92 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from flask import Flask, render_template, request, session
import subprocess
import sys
import os
import pandas as pd
app = Flask(__name__)
app.secret_key = 'your_secret_key' # Change this to a secure key
# Define the directory where CSV files are stored
attendance_dir = "attendance_files"
# Define a list of valid sections
valid_sections = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
@app.route('/')
def index():
# Retrieve the selected section from the session if available
selected_section = session.get('selected_section', None)
return render_template('index.html', sections=valid_sections, selected_section=selected_section)
@app.route('/run_script', methods=['POST'])
def run_script():
if request.method == 'POST':
# Get the selected section from the form
selected_section = request.form.get('selected_section')
if selected_section not in valid_sections:
return render_template('index.html', message="Invalid section selected")
# Store the selected section in the session
session['selected_section'] = selected_section
# Get the path to the Python interpreter within the virtual environment
python_executable = sys.executable
# Specify the script to run based on the selected section
script_to_run = 'attendance_system.py'
# Append the section as a command-line argument
script_args = [python_executable, script_to_run, selected_section]
# Run the script with the section-specific CSV file
result = subprocess.run(script_args, capture_output=True, text=True)
output = result.stdout
return render_template('index.html', script_output=output, sections=valid_sections, selected_section=selected_section)
@app.route('/show_section_attendance', methods=['POST'])
def show_section_attendance():
if request.method == 'POST':
# Get the selected section and date to view
selected_section_view = request.form.get('selected_section_view')
selected_date = request.form.get('selected_date')
# Construct the CSV file path for the selected section and date
csv_file_path = os.path.join(attendance_dir, f"{selected_date}_section_{selected_section_view}.csv")
# Check if the CSV file exists
if os.path.exists(csv_file_path):
# Read the CSV data into a DataFrame
attendance_df = pd.read_csv(csv_file_path)
# Convert the DataFrame to an HTML table
attendance_table = attendance_df.to_html(classes='table table-bordered table-striped', index=False)
return render_template('index.html', attendance_table=attendance_table, sections=valid_sections, selected_section=session.get('selected_section', None))
else:
return render_template('index.html', message="File Not Present", sections=valid_sections, selected_section=session.get('selected_section', None))
if __name__ == '__main__':
app.run(debug=True)