Ryugen22 commited on
Commit
98cd1cc
Β·
verified Β·
1 Parent(s): b33491a

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +12 -0
  2. app.py +95 -0
  3. requirements.txt +1 -0
Dockerfile ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ WORKDIR /app
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install --no-cache-dir -r requirements.txt
7
+
8
+ COPY . .
9
+
10
+ EXPOSE 7860
11
+
12
+ CMD ["python", "app.py"]
app.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify, redirect, url_for, session
2
+ import json
3
+ import os
4
+ from datetime import datetime
5
+
6
+ app = Flask(__name__)
7
+ app.secret_key = "recom_secret_2024"
8
+
9
+ DATA_FILE = "students.json"
10
+ ADMIN_PASSWORD = "Sugar220307"
11
+
12
+ def load_students():
13
+ if not os.path.exists(DATA_FILE):
14
+ return []
15
+ with open(DATA_FILE, "r") as f:
16
+ return json.load(f)
17
+
18
+ def save_student(student):
19
+ students = load_students()
20
+ student["id"] = len(students) + 1
21
+ student["registered_at"] = datetime.now().strftime("%d-%m-%Y %H:%M")
22
+ students.append(student)
23
+ with open(DATA_FILE, "w") as f:
24
+ json.dump(students, f, indent=2)
25
+ return student["id"]
26
+
27
+ @app.route("/")
28
+ def index():
29
+ return render_template("index.html")
30
+
31
+ @app.route("/instructions")
32
+ def instructions():
33
+ name = request.args.get("name", "")
34
+ cls = request.args.get("class", "")
35
+ section = request.args.get("section", "")
36
+ if not name:
37
+ return redirect(url_for("index"))
38
+ return render_template("instructions.html", name=name, cls=cls, section=section)
39
+
40
+ @app.route("/contact")
41
+ def contact():
42
+ name = request.args.get("name", "")
43
+ cls = request.args.get("class", "")
44
+ section = request.args.get("section", "")
45
+ if not name:
46
+ return redirect(url_for("index"))
47
+ return render_template("contact.html", name=name, cls=cls, section=section)
48
+
49
+ @app.route("/submit", methods=["POST"])
50
+ def submit():
51
+ data = request.get_json()
52
+ student_id = save_student(data)
53
+ return jsonify({"success": True, "id": student_id})
54
+
55
+ @app.route("/success")
56
+ def success():
57
+ return render_template("success.html")
58
+
59
+ @app.route("/admin", methods=["GET", "POST"])
60
+ def admin():
61
+ if request.method == "POST":
62
+ pwd = request.form.get("password", "")
63
+ if pwd == ADMIN_PASSWORD:
64
+ session["admin"] = True
65
+ return redirect(url_for("admin"))
66
+ else:
67
+ return render_template("admin_login.html", error="Wrong password. Try again.")
68
+ if not session.get("admin"):
69
+ return render_template("admin_login.html", error=None)
70
+ students = load_students()
71
+ return render_template("admin_dashboard.html", students=students)
72
+
73
+ @app.route("/admin/logout")
74
+ def admin_logout():
75
+ session.pop("admin", None)
76
+ return redirect(url_for("admin"))
77
+
78
+ if __name__ == "__main__":
79
+ import sys
80
+ if len(sys.argv) > 1 and sys.argv[1] == "list":
81
+ students = load_students()
82
+ if not students:
83
+ print("No students registered yet.")
84
+ else:
85
+ print(f"\n{'─'*60}")
86
+ print(f" RECOM β€” Registered Students ({len(students)} total)")
87
+ print(f"{'─'*60}")
88
+ for s in students:
89
+ print(f"\n #{s['id']} {s['name']} | Class {s['class']} - {s['section']}")
90
+ print(f" πŸ“ž {s.get('phone','β€”')} πŸ’¬ WhatsApp: {s.get('whatsapp','β€”')}")
91
+ print(f" πŸ“ {s.get('address','β€”')}")
92
+ print(f" πŸ• Registered: {s.get('registered_at','β€”')}")
93
+ print(f"\n{'─'*60}\n")
94
+ else:
95
+ app.run(host="0.0.0.0", port=7860, debug=False)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ flask