Added search button

main
Lasse Server 3 years ago
parent 5740e8b92b
commit b98c6628b2
  1. 81
      app.py

@ -5,17 +5,8 @@ from yaml.loader import SafeLoader
import main import main
import create_credentials import create_credentials
import traceback import traceback
from time import sleep
with open('credentials.yaml') as file:
config = yaml.load(file, Loader=SafeLoader)
authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized']
)
def add_user(): def add_user():
st.write(':red[Skapa ny användare]') st.write(':red[Skapa ny användare]')
@ -32,7 +23,43 @@ def add_user():
else: else:
st.write('Användare finns redan.') st.write('Användare finns redan.')
def search(user_input):
s = []
for i in user_input:
if i.isnumeric():
s.append(str(i))
s = ''.join(s)
if s[0:2] == '07' and len(s) == 10:
s = '46' + s[1:]
# Search for info.
r = main.search(s)
# Present result.
if r != None:
if r['column_find'] == 'ID':
id = r['find']
r['find'] = f'<a href="http://facebook.com/{id}">{id}</a>'
st.write(f"{r['name']}, {r['column_find']}: {r['find']}", unsafe_allow_html=True)
with st.expander('Mer information'):
st.dataframe(r['df'], use_container_width=True)
else:
st.text('Hittade inga uppgifter.')
with open('credentials.yaml') as file:
config = yaml.load(file, Loader=SafeLoader)
authenticator = stauth.Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized']
)
name, authentication_status, username = authenticator.login('Logga in', 'main') name, authentication_status, username = authenticator.login('Logga in', 'main')
@ -44,36 +71,20 @@ if authentication_status:
if username == 'admin': if username == 'admin':
add_user() add_user()
# Ask for input # Ask for input
help_text = '[Du kan hitta en profils Facebook-ID här](https://findidfb.com/)' help_text = '[Du kan hitta en profils Facebook-ID här](https://findidfb.com/)'
user_input = str(st.text_input('Skriv in telefonnummer eller Facebook-ID', help=help_text, placeholder='Skriv här...')).strip() user_input = str(st.text_input('Skriv in telefonnummer eller Facebook-ID', help=help_text, placeholder='Skriv här...')).strip()
if user_input != '': search_button = st.button('Sök')
s = [] if search_button and user_input != '':
for i in user_input: sleep(0.1)
if i.isnumeric(): r = search(user_input)
s.append(str(i))
s = ''.join(s)
if s[0:2] == '07' and len(s) == 10:
s = '46' + s[1:]
# Search for info.
r = main.search(s)
# Present result. more = st.expander('Övrigt', )
if r != None:
if r['column_find'] == 'ID':
id = r['find']
r['find'] = f'<a href="http://facebook.com/{id}">{id}</a>'
st.write(f"{r['name']}, {r['column_find']}: {r['find']}", unsafe_allow_html=True)
with st.expander('Mer information'):
st.dataframe(r['df'], use_container_width=True)
else:
st.text('Hittade inga uppgifter.')
authenticator.logout('Logout', 'main') with more:
st.write('Byggd av Lasse Edfast. Används endast för journalistiskt syfte och med tillstånd.')
authenticator.logout('Logout', 'main')
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()
st.write('Något gick fel :(') st.write('Något gick fel :(')

Loading…
Cancel
Save