amirhoseinsedaghati
commited on
Commit
•
9132d63
1
Parent(s):
719c4c9
Upload configs files
Browse files- configs/db_configs.py +24 -0
- configs/download_files.py +21 -0
- configs/html_features.py +7 -0
configs/db_configs.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sqlite3
|
2 |
+
|
3 |
+
engine = sqlite3.connect('configs/text_app.db', check_same_thread=False)
|
4 |
+
cur = engine.cursor()
|
5 |
+
|
6 |
+
def create_table():
|
7 |
+
cur.execute("""
|
8 |
+
CREATE TABLE IF NOT EXISTS input_text(
|
9 |
+
id INTEGER PRIMARY KEY,
|
10 |
+
text TEXT NOT NULL,
|
11 |
+
app NVARCHAR(20) NOT NULL
|
12 |
+
)
|
13 |
+
""")
|
14 |
+
|
15 |
+
|
16 |
+
def add_one_item(text, app, table='input_text'):
|
17 |
+
cur.execute(f"INSERT INTO {table} (text, app) VALUES (?, ?)", (text, app,))
|
18 |
+
engine.commit()
|
19 |
+
|
20 |
+
|
21 |
+
def get_all_data(table='input_text'):
|
22 |
+
data = cur.execute('SELECT * FROM {}'.format(table))
|
23 |
+
return data.fetchall()
|
24 |
+
|
configs/download_files.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import base64
|
3 |
+
import time
|
4 |
+
|
5 |
+
time_str = time.strftime('%Y%m%d-%H%M%S')
|
6 |
+
|
7 |
+
class FileDownloader(object):
|
8 |
+
def __init__(self, data, file_ext, file_name='myfile') -> None:
|
9 |
+
super(FileDownloader, self).__init__()
|
10 |
+
self.data = data
|
11 |
+
self.file_ext = file_ext
|
12 |
+
self.file_name = file_name
|
13 |
+
|
14 |
+
def download(self):
|
15 |
+
b64 = base64.b64encode(self.data.encode()).decode()
|
16 |
+
new_file_name = '{0}_{1}.{2}'.format(self.file_name, time_str, self.file_ext)
|
17 |
+
href = """
|
18 |
+
<a href="data: file/{}; base64,{}" download="{}">Download it</a>
|
19 |
+
""".format(self.file_ext, b64, new_file_name)
|
20 |
+
st.markdown(href, unsafe_allow_html=True)
|
21 |
+
|
configs/html_features.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
HTML_WRAPPER = """
|
2 |
+
<div style="overflow-x: auto; border: 1px solid #e6e9ef;">{}</div>
|
3 |
+
"""
|
4 |
+
|
5 |
+
def set_image(url):
|
6 |
+
HTML_BACKGROUND_IMG = f"<style> body {{ background-image: url('{url}'); background-size: 100%; background-repeat: no-repeat; }} </style>"
|
7 |
+
return HTML_BACKGROUND_IMG
|