-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilefunctions.py
More file actions
35 lines (28 loc) · 999 Bytes
/
Copy pathfilefunctions.py
File metadata and controls
35 lines (28 loc) · 999 Bytes
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
import csv
from io import StringIO
import yaml
import streamlit as st
def read_database_config(file_path):
with open(file_path, 'r') as file:
config = yaml.safe_load(file)
return config
def export_to_csv(data, file_name):
# Create a CSV string from the data
csv_data = StringIO()
writer = csv.writer(csv_data, delimiter=';')
writer.writerows(data)
# Create a download link for the CSV file
csv_data_str = csv_data.getvalue().encode('utf-8').strip()
st.download_button(
label="Download CSV",
data=csv_data_str,
file_name=file_name,
mime="text/csv"
)
def string_to_filename(s):
# Replace invalid characters with underscores
valid_chars = '-_.() abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
filename = ''.join(c if c in valid_chars else '_' for c in s)
# Remove leading/trailing spaces and double underscores
filename = filename.strip().replace('__', '_')
return filename