Skip to content

Commit

Permalink
Merge pull request #25 from banodoco/main
Browse files Browse the repository at this point in the history
new changes
  • Loading branch information
piyushK52 authored Nov 7, 2023
2 parents ae86450 + a72d1af commit 1b921b7
Show file tree
Hide file tree
Showing 79 changed files with 7,502 additions and 5,836 deletions.
62 changes: 38 additions & 24 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import webbrowser
import threading
import time
import streamlit as st
from moviepy.editor import *
import time
import subprocess
import os
import django
from shared.constants import OFFLINE_MODE, SERVER, ServerType
import sentry_sdk
from shared.logging.logging import AppLogger
from utils.common_utils import is_process_active

from utils.constants import AUTH_TOKEN, LOGGED_USER
from utils.constants import AUTH_TOKEN, RUNNER_PROCESS_NAME
from utils.local_storage.url_storage import delete_url_param, get_url_param, set_url_param
from utils.third_party_auth.google.google_auth import get_google_auth_url
from streamlit_server_state import server_state_lock


# loading the django app
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "django_settings")
# Initialize Django
django.setup()
st.session_state['django_init'] = True

from banodoco_settings import project_init
from ui_components.models import InternalAppSettingObject
from utils.data_repo.data_repo import DataRepo


Expand All @@ -28,23 +31,40 @@
import boto3
ssm = boto3.client("ssm", region_name="ap-south-1")

SENTRY_ENV = ssm.get_parameter(Name='/banodoco-fe/sentry/environment')['Parameter']['Value']
SENTRY_DSN = ssm.get_parameter(Name='/banodoco-fe/sentry/dsn')['Parameter']['Value']
# SENTRY_ENV = ssm.get_parameter(Name='/banodoco-fe/sentry/environment')['Parameter']['Value']
# SENTRY_DSN = ssm.get_parameter(Name='/banodoco-fe/sentry/dsn')['Parameter']['Value']

sentry_sdk.init(
environment=SENTRY_ENV,
dsn=SENTRY_DSN,
traces_sample_rate=0
)
# sentry_sdk.init(
# environment=SENTRY_ENV,
# dsn=SENTRY_DSN,
# traces_sample_rate=0
# )

def start_runner():
if SERVER != ServerType.DEVELOPMENT.value:
return

with server_state_lock["runner"]:
app_logger = AppLogger()

if not is_process_active(RUNNER_PROCESS_NAME):
app_logger.info("Starting runner")
# _ = subprocess.Popen(["streamlit", "run", "banodoco_runner.py", "--runner.fastReruns", "false", "--server.port", "5502", "--server.headless", "true"])
_ = subprocess.Popen(["python", "banodoco_runner.py"])
while not is_process_active(RUNNER_PROCESS_NAME):
time.sleep(0.1)
else:
app_logger.debug("Runner already running")

def main():
st.set_page_config(page_title="Banodoco", page_icon="🎨", layout="wide")

auth_details = get_url_param(AUTH_TOKEN)
if (not auth_details or auth_details == 'None')\
and SERVER != ServerType.DEVELOPMENT.value:
st.subheader("Login with google to proceed")

st.markdown("# :red[ba]:green[no]:orange[do]:blue[co]")
st.subheader("Login with Google to proceed")

auth_url = get_google_auth_url()
st.markdown(auth_url, unsafe_allow_html=True)

Expand All @@ -57,28 +77,22 @@ def main():
data_repo = DataRepo()
user, token, refresh_token = data_repo.google_user_login(**data)
if user:
st.session_state[LOGGED_USER] = user.to_json() if user else None
set_url_param(AUTH_TOKEN, str(token))
# st.experimental_set_query_params(test='testing')
st.experimental_rerun()
st.rerun()
else:
delete_url_param(AUTH_TOKEN)
st.error("please login again")
else:
# initializing project constants
start_runner()
project_init()

data_repo = DataRepo()
app_settings: InternalAppSettingObject = data_repo.get_app_setting_from_uuid()
app_secret = data_repo.get_app_secrets_from_user_uuid()

from ui_components.setup import setup_app_ui
setup_app_ui()

if __name__ == '__main__':
try:
main()
except Exception as e:
sentry_sdk.capture_exception(e)
# sentry_sdk.capture_exception(e)
raise e

Loading

0 comments on commit 1b921b7

Please sign in to comment.