|
|
|
|
@ -195,6 +195,11 @@ def search_user(search_for, engine): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
|
|
|
|
|
|
# Say hi. |
|
|
|
|
st.markdown(f'<h4 style="color:#ff748c";>Hej {name}!</h4>', unsafe_allow_html=True) |
|
|
|
|
|
|
|
|
|
# Define connection to sqlite database. |
|
|
|
|
engine = create_engine('sqlite:///db.sqlite') |
|
|
|
|
|
|
|
|
|
# Create query_params class and set empty parameters. |
|
|
|
|
@ -206,7 +211,7 @@ def main(): |
|
|
|
|
index_category = categories.index(params.category[0]) |
|
|
|
|
else: |
|
|
|
|
index_category = 0 |
|
|
|
|
search_category = st.selectbox('Vad vill du söka efter?', categories, index_category, on_change=reset_q) |
|
|
|
|
search_category = st.selectbox('Vill du söka efter meddelanden eller användare?', categories, index_category, on_change=reset_q) |
|
|
|
|
params.update('category', search_category) |
|
|
|
|
|
|
|
|
|
# Let user chose what words to search for. |
|
|
|
|
@ -215,8 +220,14 @@ def main(): |
|
|
|
|
else: |
|
|
|
|
placeholder = 'Skriv här' |
|
|
|
|
|
|
|
|
|
# Set text to be shown above search field. |
|
|
|
|
if search_category == 'Meddelanden': |
|
|
|
|
search_text = 'Vilka ord vill du söka efter?' |
|
|
|
|
elif search_category == 'Användare': |
|
|
|
|
search_text = 'Skriv email-adress eller användarnamn.' |
|
|
|
|
|
|
|
|
|
helpt_text = 'Du kan använda asterix (*), minus(-), citattecken ("") och OR.' |
|
|
|
|
search_for = st.text_input('Vad vill du söka efter?', placeholder=placeholder, help=helpt_text).lower() |
|
|
|
|
search_for = st.text_input(search_text, placeholder=placeholder, help=helpt_text).lower() |
|
|
|
|
|
|
|
|
|
# Set search input from params if nothing else is input. |
|
|
|
|
# This is the case when the user is coming from an url with q param. |
|
|
|
|
@ -226,17 +237,18 @@ def main(): |
|
|
|
|
# Start the search. |
|
|
|
|
if search_for != '': |
|
|
|
|
params.update('q', search_for) |
|
|
|
|
search_for = search_for.replace('å', '?').replace('ä', '?').replace('ö', '?') #TODO Do better. |
|
|
|
|
|
|
|
|
|
#* Search message |
|
|
|
|
# Replace å, ä, ö with ?. |
|
|
|
|
search_for = search_for.replace('å', '?').replace('ä', '?').replace('ö', '?') |
|
|
|
|
|
|
|
|
|
#* Search message. |
|
|
|
|
if search_category == 'Meddelanden': |
|
|
|
|
search_messages(search_for, engine) |
|
|
|
|
|
|
|
|
|
#* Sök användare |
|
|
|
|
#* Seach user. |
|
|
|
|
elif search_category == 'Användare': |
|
|
|
|
search_user(search_for, engine) |
|
|
|
|
|
|
|
|
|
#main() |
|
|
|
|
with open('credentials.yaml') as file: |
|
|
|
|
config = yaml.load(file, Loader=SafeLoader) |
|
|
|
|
|
|
|
|
|
|