-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
69 lines (55 loc) · 2.06 KB
/
app.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
59
60
61
62
63
64
65
66
67
68
69
import logging
import os
from datetime import datetime
import pandas as pd
import streamlit as st
from dotenv import load_dotenv
from streamlit_authenticator import Authenticate, Hasher
from utils.mongo import MongoSingleton
from utils.process_guild_data import process_guild_data
logging.basicConfig(level=logging.INFO)
load_dotenv()
st.subheader("TogetherCrew's Amin Panel")
# Get environment variables
names = os.getenv("NAMES").split(",")
usernames = os.getenv("USERNAMES").split(",")
passwords = os.getenv("PASSWORDS").split(",")
secret_key = os.getenv("SECRET_KEY")
hashed_passwords = Hasher(passwords).generate()
# Set up the authenticator
authenticator = Authenticate(
credentials={
"usernames": {
usernames[i]: {"name": names[i], "password": hashed_passwords[i]}
for i in range(len(usernames))
}
},
cookie_name="auth_cookie",
key=secret_key,
cookie_expiry_days=30,
)
# Login function
name, authentication_status, username = authenticator.login()
if authentication_status:
authenticator.logout("Logout", "main")
st.write(f"Welcome *{name}*")
client = MongoSingleton.get_instance().client
cursor = client["Core"]["platforms"].find({"name": "discord"})
guild_documents = list(cursor)
guilds_data: list[dict[str, str | datetime]] = []
mybar = st.progress(0, text="Guild Analytics Extraction Running")
dataframe_widget = st.dataframe()
for idx, guild_doc in enumerate(guild_documents):
guild_id = guild_doc["metadata"]["id"]
message = f"Analyzing {idx + 1}/{len(guild_documents)} guild_id: {guild_id}"
logging.info(message)
mybar.progress((idx + 1) / len(guild_documents), message)
data = process_guild_data(guild_doc)
# TODO: bring the neo4j analytics too
guilds_data.append(data)
df = pd.DataFrame(guilds_data)
dataframe_widget.dataframe(df)
elif authentication_status is False:
st.error("Username/password is incorrect")
elif authentication_status is None:
st.warning("Please enter your username and password")