adil9858 commited on
Commit
caef5b0
·
verified ·
1 Parent(s): bfc21f7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +172 -170
app.py CHANGED
@@ -1,171 +1,173 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import requests
4
- from datetime import datetime
5
-
6
- # SheetDB API Endpoint for Timecard Data
7
- SHEETDB_API_URL_TIMECARD = "https://sheetdb.io/api/v1/jsh4nri7t8rko" # Replace with your SheetDB API URL for timecard
8
-
9
- # Define password
10
- PASSWORD = "ma_12345" # Replace with your desired password
11
-
12
- # Hardcoded Metadata
13
- METADATA = {
14
- "Employee Names": [
15
- "Ubaid Bashir", "Shoaib Ahmad", "Rumaan Hassan Alamgeer",
16
- "Sana Sanaullah", "Aafreen Mushtaq", "Andleeb Gul"
17
- ],
18
- "Project Names": [
19
- "ICCL", "Reston", "Stormwater", "NISA Engineering",
20
- "Paramount", "Preng", "Misc.", "Marketing"
21
- ],
22
- "Project Codes": [
23
- "US 001", "US 003", "US 004", "US 005", "US 006", "IND 001", "IND 007"
24
- ]
25
- }
26
-
27
- # Load timecard data from SheetDB
28
- def load_data():
29
- response = requests.get(SHEETDB_API_URL_TIMECARD)
30
- if response.status_code == 200:
31
- return pd.DataFrame(response.json())
32
- else:
33
- return pd.DataFrame(columns=["Employee Name", "Project Name", "Project Code", "Date", "Hours", "Notes"])
34
-
35
- # Save timecard data to SheetDB
36
- def save_data(employee_name, project_name, project_code, date, hours, notes):
37
- new_entry = {
38
- "Employee Name": employee_name,
39
- "Project Name": project_name,
40
- "Project Code": project_code,
41
- "Date": str(date),
42
- "Hours": hours,
43
- "Notes": notes
44
- }
45
- response = requests.post(SHEETDB_API_URL_TIMECARD, json=new_entry)
46
- if response.status_code == 201:
47
- st.success("Entry added successfully!")
48
- else:
49
- st.error("Failed to add entry. Please try again.")
50
-
51
- # Custom Cyberpunk CSS (Less Glowy)
52
- st.markdown(
53
- """
54
- <style>
55
- /* General Styling */
56
- body {
57
- background-color: #000000;
58
- color: #00FF00;
59
- font-family: 'Courier New', monospace;
60
- }
61
- h1, h2, h3, h4, h5, h6 {
62
- color: #00FF00;
63
- font-family: 'Courier New', monospace;
64
- }
65
- .stButton button {
66
- background-color: #00FF00;
67
- color: #000000;
68
- border: 2px solid #00FF00;
69
- border-radius: 5px;
70
- font-family: 'Courier New', monospace;
71
- font-weight: bold;
72
- }
73
- .stButton button:hover {
74
- background-color: #000000;
75
- color: #00FF00;
76
- border: 2px solid #00FF00;
77
- }
78
- .stTextInput input, .stSelectbox select, .stDateInput input, .stNumberInput input, .stTextArea textarea {
79
- background-color: #000000;
80
- color: #00FF00;
81
- border: 2px solid #00FF00;
82
- font-family: 'Courier New', monospace;
83
- }
84
- .stDataFrame {
85
- background-color: #000000;
86
- color: #00FF00;
87
- border: 2px solid #00FF00;
88
- }
89
- .stSidebar {
90
- background-color: #000000;
91
- color: #00FF00;
92
- border-right: 2px solid #00FF00;
93
- }
94
- .stMarkdown {
95
- color: #00FF00;
96
- }
97
- /* Reduced Neon Glow Effect */
98
- .neon-text {
99
- color: #00FF00;
100
- text-shadow: 0 0 3px #00FF00, 0 0 5px #00FF00;
101
- }
102
- .neon-border {
103
- border: 2px solid #00FF00;
104
- box-shadow: 0 0 3px #00FF00, 0 0 5px #00FF00;
105
- }
106
- </style>
107
- """,
108
- unsafe_allow_html=True
109
- )
110
-
111
- # Password authentication
112
- if "authenticated" not in st.session_state:
113
- st.session_state.authenticated = False
114
-
115
- if not st.session_state.authenticated:
116
- st.markdown("<h1 class='neon-text' style='text-align: center;'>Munshi Associates Dashboard</h1>", unsafe_allow_html=True)
117
- st.markdown("<p class='neon-text'>Please enter the password to access the application.</p>", unsafe_allow_html=True)
118
- password = st.text_input("Password", type="password")
119
-
120
- if st.button("Login"):
121
- if password == PASSWORD:
122
- st.session_state.authenticated = True
123
- st.success("Login successful!")
124
- else:
125
- st.error("Incorrect password. Please try again.")
126
- else:
127
- # Display company logo and title in the sidebar
128
- st.sidebar.image("ma_logo.png") # Replace with your logo
129
- st.sidebar.markdown("<h1 class='neon-text'>Munshi Associates Dashboard</h1>", unsafe_allow_html=True)
130
- st.sidebar.markdown("<p class='neon-text'>Employee Timecard Management System</p>", unsafe_allow_html=True)
131
-
132
- # Main section
133
- st.markdown("<h1 class='neon-text'>Employee Time Card Management</h1>", unsafe_allow_html=True)
134
- st.markdown("<p class='neon-text'>Welcome to the <strong>Munshi Associates Time Card Management System</strong></p>", unsafe_allow_html=True)
135
-
136
- # Load metadata (hardcoded)
137
- employee_names = METADATA["Employee Names"]
138
- project_names = METADATA["Project Names"]
139
- project_codes = METADATA["Project Codes"]
140
-
141
- # Form for adding timecard entries
142
- st.markdown("<h3 class='neon-text'>Add Timecard Entry</h3>", unsafe_allow_html=True)
143
- with st.form("timecard_form"):
144
- st.markdown("<p class='neon-text'>Fill out the form below to add a new entry.</p>", unsafe_allow_html=True)
145
- col1, col2 = st.columns(2)
146
- with col1:
147
- employee_name = st.selectbox("Select Employee Name", employee_names)
148
- project_name = st.selectbox("Select Project Name", project_names)
149
- project_code = st.selectbox("Select Project Code", project_codes)
150
- with col2:
151
- date = st.date_input("Date", datetime.today())
152
- hours = st.number_input("Hours Worked", min_value=0.0, step=0.5)
153
- notes = st.text_area("Notes", placeholder="Add any relevant notes here...")
154
-
155
- submitted = st.form_submit_button("Add Entry")
156
- if submitted:
157
- save_data(employee_name, project_name, project_code, date, hours, notes)
158
-
159
- # Display existing timecard data
160
- st.markdown("<h3 class='neon-text'>Existing Time Card Data</h3>", unsafe_allow_html=True)
161
- data = load_data()
162
- st.dataframe(data, use_container_width=True)
163
-
164
- # Option to download the data
165
- st.markdown("<h3 class='neon-text'>Download Time Card Data</h3>", unsafe_allow_html=True)
166
- st.download_button(
167
- label="Download CSV",
168
- data=data.to_csv(index=False),
169
- file_name="timecard_data.csv",
170
- mime="text/csv"
 
 
171
  )
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import requests
4
+ from datetime import datetime
5
+
6
+ # SheetDB API Endpoint for Timecard Data
7
+ SHEETDB_API_URL_TIMECARD = "https://sheetdb.io/api/v1/jsh4nri7t8rko" # Replace with your SheetDB API URL for timecard
8
+
9
+ # Define password
10
+ PASSWORD = "ma_12345" # Replace with your desired password
11
+
12
+ # Hardcoded Metadata
13
+ METADATA = {
14
+ "Employee Names": [
15
+ "Ubaid Bashir", "Shoaib Ahmad", "Rumaan Hassan Alamgeer",
16
+ "Sana Sanaullah", "Aafreen Mushtaq", "Andleeb Gul"
17
+ ],
18
+ "Project Names": [
19
+ "ICCL", "Reston", "Stormwater", "NISA Engineering",
20
+ "Paramount", "Preng", "Misc.", "Marketing"
21
+ ],
22
+ "Project Codes": [
23
+ "US 001", "US 003", "US 004", "US 005", "US 006", "IND 001", "IND 007"
24
+ ]
25
+ }
26
+
27
+ # Load timecard data from SheetDB
28
+ def load_data():
29
+ response = requests.get(SHEETDB_API_URL_TIMECARD)
30
+ if response.status_code == 200:
31
+ return pd.DataFrame(response.json())
32
+ else:
33
+ return pd.DataFrame(columns=["Employee Name", "Project Name", "Project Code", "Date", "Hours", "Notes"])
34
+
35
+ # Save timecard data to SheetDB
36
+ def save_data(employee_name, project_name, project_code, hours, notes):
37
+ # Automatically set the date to the current date
38
+ formatted_date = datetime.today().isoformat()
39
+
40
+ new_entry = {
41
+ "Employee Name": employee_name,
42
+ "Project Name": project_name,
43
+ "Project Code": project_code,
44
+ "Date": formatted_date,
45
+ "Hours": hours,
46
+ "Notes": notes
47
+ }
48
+ response = requests.post(SHEETDB_API_URL_TIMECARD, json=new_entry)
49
+ if response.status_code == 201:
50
+ st.success("Entry added successfully!")
51
+ else:
52
+ st.error("Failed to add entry. Please try again.")
53
+
54
+ # Custom Cyberpunk CSS (Less Glowy)
55
+ st.markdown(
56
+ """
57
+ <style>
58
+ /* General Styling */
59
+ body {
60
+ background-color: #000000;
61
+ color: #00FF00;
62
+ font-family: 'Courier New', monospace;
63
+ }
64
+ h1, h2, h3, h4, h5, h6 {
65
+ color: #00FF00;
66
+ font-family: 'Courier New', monospace;
67
+ }
68
+ .stButton button {
69
+ background-color: #00FF00;
70
+ color: #000000;
71
+ border: 2px solid #00FF00;
72
+ border-radius: 5px;
73
+ font-family: 'Courier New', monospace;
74
+ font-weight: bold;
75
+ }
76
+ .stButton button:hover {
77
+ background-color: #000000;
78
+ color: #00FF00;
79
+ border: 2px solid #00FF00;
80
+ }
81
+ .stTextInput input, .stSelectbox select, .stDateInput input, .stNumberInput input, .stTextArea textarea {
82
+ background-color: #000000;
83
+ color: #00FF00;
84
+ border: 2px solid #00FF00;
85
+ font-family: 'Courier New', monospace;
86
+ }
87
+ .stDataFrame {
88
+ background-color: #000000;
89
+ color: #00FF00;
90
+ border: 2px solid #00FF00;
91
+ }
92
+ .stSidebar {
93
+ background-color: #000000;
94
+ color: #00FF00;
95
+ border-right: 2px solid #00FF00;
96
+ }
97
+ .stMarkdown {
98
+ color: #00FF00;
99
+ }
100
+ /* Reduced Neon Glow Effect */
101
+ .neon-text {
102
+ color: #00FF00;
103
+ text-shadow: 0 0 3px #00FF00, 0 0 5px #00FF00;
104
+ }
105
+ .neon-border {
106
+ border: 2px solid #00FF00;
107
+ box-shadow: 0 0 3px #00FF00, 0 0 5px #00FF00;
108
+ }
109
+ </style>
110
+ """,
111
+ unsafe_allow_html=True
112
+ )
113
+
114
+ # Password authentication
115
+ if "authenticated" not in st.session_state:
116
+ st.session_state.authenticated = False
117
+
118
+ if not st.session_state.authenticated:
119
+ st.markdown("<h1 class='neon-text' style='text-align: center;'>Munshi Associates Dashboard</h1>", unsafe_allow_html=True)
120
+ st.markdown("<p class='neon-text'>Please enter the password to access the application.</p>", unsafe_allow_html=True)
121
+ password = st.text_input("Password", type="password")
122
+
123
+ if st.button("Login"):
124
+ if password == PASSWORD:
125
+ st.session_state.authenticated = True
126
+ st.success("Login successful!")
127
+ else:
128
+ st.error("Incorrect password. Please try again.")
129
+ else:
130
+ # Display company logo and title in the sidebar
131
+ st.sidebar.image("ma_logo.png") # Replace with your logo
132
+ st.sidebar.markdown("<h1 class='neon-text'>Munshi Associates Dashboard</h1>", unsafe_allow_html=True)
133
+ st.sidebar.markdown("<p class='neon-text'>Employee Timecard Management System</p>", unsafe_allow_html=True)
134
+
135
+ # Main section
136
+ st.markdown("<h1 class='neon-text'>Employee Time Card Management</h1>", unsafe_allow_html=True)
137
+ st.markdown("<p class='neon-text'>Welcome to the <strong>Munshi Associates Time Card Management System</strong></p>", unsafe_allow_html=True)
138
+
139
+ # Load metadata (hardcoded)
140
+ employee_names = METADATA["Employee Names"]
141
+ project_names = METADATA["Project Names"]
142
+ project_codes = METADATA["Project Codes"]
143
+
144
+ # Form for adding timecard entries
145
+ st.markdown("<h3 class='neon-text'>Add Timecard Entry</h3>", unsafe_allow_html=True)
146
+ with st.form("timecard_form"):
147
+ st.markdown("<p class='neon-text'>Fill out the form below to add a new entry.</p>", unsafe_allow_html=True)
148
+ col1, col2 = st.columns(2)
149
+ with col1:
150
+ employee_name = st.selectbox("Select Employee Name", employee_names)
151
+ project_name = st.selectbox("Select Project Name", project_names)
152
+ project_code = st.selectbox("Select Project Code", project_codes)
153
+ with col2:
154
+ hours = st.number_input("Hours Worked", min_value=0.0, step=0.5)
155
+ notes = st.text_area("Notes", placeholder="Add any relevant notes here...")
156
+
157
+ submitted = st.form_submit_button("Add Entry")
158
+ if submitted:
159
+ save_data(employee_name, project_name, project_code, hours, notes)
160
+
161
+ # Display existing timecard data
162
+ st.markdown("<h3 class='neon-text'>Existing Time Card Data</h3>", unsafe_allow_html=True)
163
+ data = load_data()
164
+ st.dataframe(data, use_container_width=True)
165
+
166
+ # Option to download the data
167
+ st.markdown("<h3 class='neon-text'>Download Time Card Data</h3>", unsafe_allow_html=True)
168
+ st.download_button(
169
+ label="Download CSV",
170
+ data=data.to_csv(index=False),
171
+ file_name="timecard_data.csv",
172
+ mime="text/csv"
173
  )