Added search button

main
Lasse Server 3 years ago
parent 5740e8b92b
commit b98c6628b2
  1. 65
      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,23 +23,7 @@ def add_user():
else: else:
st.write('Användare finns redan.') st.write('Användare finns redan.')
def search(user_input):
name, authentication_status, username = authenticator.login('Logga in', 'main')
if authentication_status:
try:
# Say hello
st.markdown(f':blue[**Hej {name}!**]')
if username == 'admin':
add_user()
# Ask for input
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()
if user_input != '':
s = [] s = []
for i in user_input: for i in user_input:
if i.isnumeric(): if i.isnumeric():
@ -58,6 +33,7 @@ if authentication_status:
if s[0:2] == '07' and len(s) == 10: if s[0:2] == '07' and len(s) == 10:
s = '46' + s[1:] s = '46' + s[1:]
# Search for info. # Search for info.
r = main.search(s) r = main.search(s)
@ -66,6 +42,7 @@ if authentication_status:
if r['column_find'] == 'ID': if r['column_find'] == 'ID':
id = r['find'] id = r['find']
r['find'] = f'<a href="http://facebook.com/{id}">{id}</a>' 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) st.write(f"{r['name']}, {r['column_find']}: {r['find']}", unsafe_allow_html=True)
with st.expander('Mer information'): with st.expander('Mer information'):
@ -73,6 +50,40 @@ if authentication_status:
else: else:
st.text('Hittade inga uppgifter.') 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')
if authentication_status:
try:
# Say hello
st.markdown(f':blue[**Hej {name}!**]')
if username == 'admin':
add_user()
# Ask for input
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()
search_button = st.button('Sök')
if search_button and user_input != '':
sleep(0.1)
r = search(user_input)
more = st.expander('Övrigt', )
with more:
st.write('Byggd av Lasse Edfast. Används endast för journalistiskt syfte och med tillstånd.')
authenticator.logout('Logout', 'main') authenticator.logout('Logout', 'main')
except Exception as e: except Exception as e:
traceback.print_exc() traceback.print_exc()

Loading…
Cancel
Save