awacke1 commited on
Commit
d45b3ad
ยท
1 Parent(s): 6ee2107

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -13
app.py CHANGED
@@ -3,7 +3,6 @@ import csv
3
  import os
4
  import random
5
 
6
- # Define function to save form data as text file
7
  def save_data(name, email, phone):
8
  with open('community.csv', mode='a') as csv_file:
9
  fieldnames = ['Name', 'Email', 'Phone']
@@ -14,14 +13,12 @@ def save_data(name, email, phone):
14
  with open(f'{name}.txt', mode='w') as file:
15
  file.write(f'Name: {name}\nEmail: {email}\nPhone: {phone}\n')
16
 
17
- # Define function to reset form data
18
  def reset_data():
19
  os.remove('community.csv')
20
  for file in os.listdir():
21
  if file.endswith('.txt'):
22
  os.remove(file)
23
 
24
- # Define function to show data after three views
25
  def show_data():
26
  count = 0
27
  with open('community.csv', mode='r') as csv_file:
@@ -32,30 +29,24 @@ def show_data():
32
  st.write(f'{row["Name"]}: {row["Email"]} - {row["Phone"]}')
33
  count = 0
34
 
35
- # Define Streamlit app
36
  def app():
37
  st.title('Community Hub Form')
38
 
39
- # Get form inputs
40
  name = st.text_input('Name', key='name_input')
41
  email = st.text_input('Email', key='email_input')
42
  phone = st.text_input('Phone', key='phone_input')
43
 
44
- # Save form data when user submits
45
  if st.button('Submit', key='submit_button'):
46
  save_data(name, email, phone)
47
  st.success('Form submitted!')
48
 
49
- # Reset form data when user clicks button
50
  if st.button('Reset', key='reset_button'):
51
  reset_data()
52
  st.success('Data reset!')
53
 
54
- # Show data when user clicks button
55
  if st.button('Show data', key='show_data_button'):
56
  show_data()
57
 
58
- # Reply and vote buttons
59
  st.write('Emails/SMS')
60
  with open('community.csv', mode='r') as csv_file:
61
  csv_reader = csv.DictReader(csv_file)
@@ -74,14 +65,13 @@ def app():
74
  file.write(f'Life points: 0\n')
75
  st.write('')
76
 
77
- # Add tip and emoji
78
  st.write('Add tip')
79
  tip = st.text_input('Tip', key='tip_input')
80
  if st.button('Submit tip', key='submit_tip_button'):
81
  emoji = random.choice(['๐Ÿ‘', '๐Ÿ‘Œ', '๐Ÿ‘', '๐Ÿ’ก'])
82
  with open(f'{name}.txt', mode='a') as file:
83
  file.write(f'Tip' + ': {tip} {emoji}\nLife points: 10\n')
84
- st.success('Tip submitted!')
85
 
86
- if name == 'main':
87
- app()
 
3
  import os
4
  import random
5
 
 
6
  def save_data(name, email, phone):
7
  with open('community.csv', mode='a') as csv_file:
8
  fieldnames = ['Name', 'Email', 'Phone']
 
13
  with open(f'{name}.txt', mode='w') as file:
14
  file.write(f'Name: {name}\nEmail: {email}\nPhone: {phone}\n')
15
 
 
16
  def reset_data():
17
  os.remove('community.csv')
18
  for file in os.listdir():
19
  if file.endswith('.txt'):
20
  os.remove(file)
21
 
 
22
  def show_data():
23
  count = 0
24
  with open('community.csv', mode='r') as csv_file:
 
29
  st.write(f'{row["Name"]}: {row["Email"]} - {row["Phone"]}')
30
  count = 0
31
 
 
32
  def app():
33
  st.title('Community Hub Form')
34
 
 
35
  name = st.text_input('Name', key='name_input')
36
  email = st.text_input('Email', key='email_input')
37
  phone = st.text_input('Phone', key='phone_input')
38
 
 
39
  if st.button('Submit', key='submit_button'):
40
  save_data(name, email, phone)
41
  st.success('Form submitted!')
42
 
 
43
  if st.button('Reset', key='reset_button'):
44
  reset_data()
45
  st.success('Data reset!')
46
 
 
47
  if st.button('Show data', key='show_data_button'):
48
  show_data()
49
 
 
50
  st.write('Emails/SMS')
51
  with open('community.csv', mode='r') as csv_file:
52
  csv_reader = csv.DictReader(csv_file)
 
65
  file.write(f'Life points: 0\n')
66
  st.write('')
67
 
 
68
  st.write('Add tip')
69
  tip = st.text_input('Tip', key='tip_input')
70
  if st.button('Submit tip', key='submit_tip_button'):
71
  emoji = random.choice(['๐Ÿ‘', '๐Ÿ‘Œ', '๐Ÿ‘', '๐Ÿ’ก'])
72
  with open(f'{name}.txt', mode='a') as file:
73
  file.write(f'Tip' + ': {tip} {emoji}\nLife points: 10\n')
74
+ st.success('Tip submitted!')
75
 
76
+ if __name__ == '__main__':
77
+ app()