GenAITeamInfobell commited on
Commit
140daf4
1 Parent(s): 76e2d7a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +81 -87
app.py CHANGED
@@ -3,42 +3,33 @@ import random
3
  import json
4
  import os
5
  from datetime import datetime
6
- import hashlib
7
- from dotenv import load_dotenv
 
8
 
9
- # Load environment variables
10
- load_dotenv()
 
11
 
12
- # Configuration
13
- HISTORY_FILE = "selection_history.json"
14
-
15
- # Team members
16
  team_members = [
17
- "Akhil", "Sarthak", "Sai Charitha", "Prasad K", "Anand S", "Harsh Naik",
18
- "Divya Singh", "Ritesh Kumar Tiwary", "Balamurali Ommi", "Lalit Singh",
19
- "Bhavana K", "Bickramjit Basu", "C R Tejavardhan", "Ashok M", "Harshitha T",
20
- "Man Mohan Nayak", "Prasad Dattatray Amale", "Praveena Bharathi",
21
- "Ranga Bhashyams", "Sahil Singh Diwan", "Sathwika", "Sayali Vinod",
22
- "Yashwanth Gundala", "Gopinath", "Arun Kumar Tiwary"
 
23
  ]
24
 
25
- # Initialize history file
26
- def initialize_history_file():
27
- if not os.path.exists(HISTORY_FILE):
28
- with open(HISTORY_FILE, 'w') as f:
29
- json.dump([], f)
30
-
31
- # Hash password
32
- def hash_password(password):
33
- return hashlib.sha256(password.encode()).hexdigest()
34
 
35
- # Authenticate user
36
- def authenticate(username, password):
37
- stored_username = os.getenv("APP_USERNAME")
38
- stored_password_hash = os.getenv("APP_PASSWORD_HASH")
39
- return username == stored_username and hash_password(password) == stored_password_hash
40
 
41
- # Team member selection
42
  def select_members(members, last_selected, num_to_select=2):
43
  available_members = [member for member in members if member not in last_selected]
44
  if len(available_members) < num_to_select:
@@ -48,67 +39,70 @@ def select_members(members, last_selected, num_to_select=2):
48
  last_selected.extend(selected_members)
49
  return selected_members
50
 
51
- # Save history
52
  def save_history(selection):
53
- with open(HISTORY_FILE, 'r+') as f:
54
  history = json.load(f)
55
- history.append(selection)
56
- f.seek(0)
57
  json.dump(history, f)
58
- f.truncate()
59
 
60
- # Clear history
61
- def clear_history():
62
- with open(HISTORY_FILE, 'w') as f:
63
- json.dump([], f)
64
- st.success("History cleared.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  # Streamlit UI
67
- def main():
68
- st.title("AI Learning Presentation - Team Member Selection")
69
-
70
- initialize_history_file()
71
-
72
- if 'authenticated' not in st.session_state:
73
- st.session_state.authenticated = False
74
-
75
- if not st.session_state.authenticated:
76
- username = st.text_input("Username")
77
- password = st.text_input("Password", type="password")
78
- if st.button("Login"):
79
- if authenticate(username, password):
80
- st.session_state.authenticated = True
81
- st.success("Logged in successfully!")
82
- else:
83
- st.error("Invalid username or password")
84
- else:
85
- st.write("Select random team members for the next session.")
86
- num_selections = st.slider("Number of times to run the selection", 1, 10, 3)
87
-
88
- if st.button("Run Selection"):
89
- last_selected = []
90
- for i in range(num_selections):
91
- try:
92
- selected_members = select_members(team_members, last_selected)
93
- timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
94
- st.write(f"Run: {i + 1}, Time: {timestamp} \n Selected members: {', '.join(selected_members)}")
95
- save_history({"run": i + 1, "timestamp": timestamp, "members": selected_members})
96
- except ValueError as e:
97
- st.error(str(e))
98
-
99
- if st.button("View History"):
100
- with open(HISTORY_FILE, 'r') as f:
101
- history = json.load(f)
102
- st.write("Selection History:")
103
- for entry in history:
104
- timestamp = entry.get('timestamp', 'No timestamp available')
105
- st.write(f"Run {entry['run']}, Time: {timestamp}, Selected members: {', '.join(entry['members'])}")
106
-
107
- if st.button("Clear History"):
108
- clear_history()
109
-
110
- if st.button("Logout"):
111
- st.session_state.authenticated = False
112
-
113
- if __name__ == "__main__":
114
- main()
 
3
  import json
4
  import os
5
  from datetime import datetime
6
+ import schedule
7
+ import time
8
+ import threading
9
 
10
+ # Use environment variables for authentication
11
+ USERNAME = os.getenv("USERNAME")
12
+ PASSWORD = os.getenv("PASSWORD")
13
 
14
+ # List of team members
 
 
 
15
  team_members = [
16
+ "Akhil", "Sarthak", "Sai Charitha", "Prasad K", "Anand S",
17
+ "Harsh Naik", "Divya Singh", "Ritesh Kumar Tiwary",
18
+ "Balamurali Ommi", "Lalit Singh", "Bhavana K", "Bickramjit Basu",
19
+ "C R Tejavardhan", "Ashok M", "Harshitha T", "Man Mohan Nayak",
20
+ "Prasad Dattatray Amale", "Praveena Bharathi", "Ranga Bhashyams",
21
+ "Sahil Singh Diwan", "Sathwika", "Sayali Vinod", "Yashwanth Gundala",
22
+ "Gopinath", "Arun Kumar Tiwary"
23
  ]
24
 
25
+ # File path to store history
26
+ HISTORY_FILE = "selection_history.json"
 
 
 
 
 
 
 
27
 
28
+ # Initialize the history file if it doesn't exist
29
+ if not os.path.exists(HISTORY_FILE):
30
+ with open(HISTORY_FILE, 'w') as f:
31
+ json.dump([], f)
 
32
 
 
33
  def select_members(members, last_selected, num_to_select=2):
34
  available_members = [member for member in members if member not in last_selected]
35
  if len(available_members) < num_to_select:
 
39
  last_selected.extend(selected_members)
40
  return selected_members
41
 
 
42
  def save_history(selection):
43
+ with open(HISTORY_FILE, 'r') as f:
44
  history = json.load(f)
45
+ history.append(selection)
46
+ with open(HISTORY_FILE, 'w') as f:
47
  json.dump(history, f)
 
48
 
49
+ def authenticate(username, password):
50
+ return username == USERNAME and password == PASSWORD
51
+
52
+ def run_daily_selection():
53
+ last_selected = []
54
+ try:
55
+ selected_members = select_members(team_members, last_selected)
56
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
57
+ save_history({"run": "Scheduled", "members": selected_members, "timestamp": timestamp})
58
+ print(f"Scheduled Run - Selected members: {', '.join(selected_members)} at {timestamp}")
59
+ except ValueError as e:
60
+ print(f"Error during scheduled run: {e}")
61
+
62
+ def start_scheduler():
63
+ schedule.every().day.at("09:30").do(run_daily_selection) # 09:30 UTC is 3:00 PM IST
64
+
65
+ while True:
66
+ schedule.run_pending()
67
+ time.sleep(1)
68
+
69
+ # Start the scheduler in a separate thread
70
+ scheduler_thread = threading.Thread(target=start_scheduler, daemon=True)
71
+ scheduler_thread.start()
72
 
73
  # Streamlit UI
74
+ st.title("AI Learning Presentation - Team Member Selection")
75
+
76
+ # Login
77
+ if 'authenticated' not in st.session_state or not st.session_state.authenticated:
78
+ username = st.text_input("Username")
79
+ password = st.text_input("Password", type="password")
80
+ if st.button("Login"):
81
+ if authenticate(username, password):
82
+ st.session_state.authenticated = True
83
+ st.success("Logged in successfully!")
84
+ else:
85
+ st.error("Invalid username or password")
86
+ else:
87
+ st.write("Select random team members for the next session.")
88
+
89
+ num_selections = st.slider("Number of times to run the selection", 1, 10, 3)
90
+
91
+ if st.button("Run Selection"):
92
+ last_selected = []
93
+
94
+ for i in range(num_selections):
95
+ try:
96
+ selected_members = select_members(team_members, last_selected)
97
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
98
+ st.write(f"Run {i + 1} - Selected members: {', '.join(selected_members)} at {timestamp}")
99
+ save_history({"run": i + 1, "members": selected_members, "timestamp": timestamp})
100
+ except ValueError as e:
101
+ st.error(e)
102
+
103
+ if st.button("View History"):
104
+ with open(HISTORY_FILE, 'r') as f:
105
+ history = json.load(f)
106
+ st.write("Selection History:")
107
+ for entry in history:
108
+ st.write(f"Run {entry['run']} - Selected members: {', '.join(entry['members'])} at {entry['timestamp']}")