-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (39 loc) · 1.26 KB
/
main.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import json
import streamlit as st
# File storage
class SimpleFileDB:
def __init__(self):
self.myfile = "data.json"
def add(self, row: str):
with open(self.myfile, "r") as fp:
all_data = json.load(fp)
all_data.append(row)
with open(self.myfile, "w") as fp:
json.dump(all_data, fp)
def search(self, substr: str):
with open(self.myfile, "r") as fp:
rows = json.load(fp)
for row in rows:
if substr in row:
return row
return "Not Found"
def printall(self):
with open(self.myfile, "r") as fp:
all_data = json.load(fp)
for row in all_data:
st.write(row)
# Main app
st.title("Simple string storage app")
mystr = st.text_input("Enter string to storage", key="mystr")
go_button = st.button("Store")
search_substr = st.text_input("Substring to search", key="substr")
search_button = st.button("Search")
db = SimpleFileDB()
if go_button:
# here you will take care of scrapping permissions etc.
# store permission info to bigquery directly
db.add(mystr)
db.printall()
if search_button:
res = db.search(search_substr)
st.write(f"Your result is: {res}")