-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsave_info.py
43 lines (39 loc) · 1.6 KB
/
save_info.py
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
def app():
import streamlit as st
import pandas as pd
import os
#make a title for your webapp
st.title("Employee Form")
#lets try a both a text input and area as well as a date
name = st.text_input('Full Name')
eid = st.text_input('Employee ID')
dept = st.text_input('Department Name')
sal = st.text_input('Salary')
address = st.text_area("Address")
mob_no = st.text_input('Mobile Number')
header = ['Employee_ID', 'Name', 'Department', 'Salary', 'Address', 'Mobile_Number']
clickSubmit = st.button('Submit')
if clickSubmit == True:
if(os.path.isfile('user.txt')):
df = pd.read_csv('user.txt')
id_list = df['Employee_ID'].tolist()
if(int(eid) in id_list):
st.error("Please enter a unique Employee ID.")
else:
data = [eid, name, dept, sal, address, mob_no]
st.markdown('<h3>Thank you for your feedback!</h3>', unsafe_allow_html=True)
file = open('user.txt', 'a')
file.write(','.join(data))
file.write("\n")
file.close()
else:
data = [eid, name, dept, sal, address, mob_no]
st.markdown('<h3>Thank you for your feedback!</h3>', unsafe_allow_html=True)
file = open('user.txt', 'a')
file.write(','.join(header))
file.write("\n")
file.write(','.join(data))
file.write("\n")
file.close()
else:
st.markdown("Click submit to save form responses.")