You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

98 lines
2.9 KiB

import streamlit as st
import streamlit_authenticator as stauth
import yaml
from yaml.loader import SafeLoader
import main
import create_credentials
import traceback
from time import sleep
def add_user():
st.write(':red[Skapa ny användare]')
with st.form("new_credentials"):
new_username = st.text_input('Användarnamn')
new_name = st.text_input('Namn')
new_pwd = st.text_input('Lösenord')
submitted = st.form_submit_button("Lägg till användare", )
if submitted:
credentials, valid = create_credentials.credentials(new_username, new_name, new_pwd)
if valid:
create_credentials.update(credentials, print_out=False, update=True)
st.write('Användare tillagd.')
else:
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')
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')
except Exception as e:
traceback.print_exc()
st.write('Något gick fel :(')
elif authentication_status is False:
st.error('Fel användarnamn/lösenord')
elif authentication_status is None:
st.warning('Skriv in användarnamn och lösenord')