Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
antsdevs committed Mar 5, 2022
1 parent 52b6108 commit 9bf5fb0
Show file tree
Hide file tree
Showing 40 changed files with 1,657 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.8

WORKDIR /app

ENV STREAMLIT_SERVER_PORT=80

COPY . .
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

EXPOSE 80
CMD ["streamlit", "run", "app.py"]
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# transitclock-webapp
New Webapp for Transitclock in Streamlit
# Changelog 05-01-2021

1. Added extra information in popup bubbles when clicking icons.
2. Added autorefresh feature which realods entire map object once per 20 seconds.

# Scope of improvements

1. Autorefresh should not reload entire map object but only contents inside map.
Empty file added __init__.py
Empty file.
88 changes: 88 additions & 0 deletions admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import streamlit as st
st.set_page_config(page_title="Simple Auth", layout="wide")

import streamlit_debug
streamlit_debug.set(flag=False, wait_for_client=True, host='localhost', port=8765)

from os import environ as osenv
import env
env.verify()

import authlib.auth as auth

airtable_info = st.empty()

st.title('Database Admin')

OPTIONS = ['SQLITE', 'AIRTABLE']
idx = OPTIONS.index(osenv.get('STORAGE', 'SQLITE'))
provider = st.sidebar.selectbox('Choose storage provider', OPTIONS, index=idx)

try:
auth.override_env_storage_provider(provider)
auth.admin()
except Exception as ex:
st.write('## Trapped exception')
st.error(str(ex))

if provider == 'AIRTABLE' and st.sidebar.checkbox('Tell me about Airtable'):
airtable_info.expander('Getting started with an Airtable database', expanded=True)
airtable_info.info("Airtable **database creation** is not supported in this application.")
airtable_info.markdown(
'''
# Getting started with an Airtable database
## How to create an Airtable
1. First, login into or create a (free) [**Airtable account**](https://airtable.com/account).
2. Next, follow these steps to create an Airtable:
- Create a database (referred to as a _base_ in Airtable) and a table within the base.
- You can call the base `profile` and the table `users`
- Rename the primary key default table field (aka column) to `username` (field type 'Single line text')
- Add a `password` field (field type 'Single line text')
- Add a `su` (superuser) field (field type 'Number')
## Finding your Airtable settings
1. You can initially create and then manage your API key in the 'Account' overview area
2. For your base (e.g. `profile`) go to the 'Help menu' and select 'API documentation'
3. In 'API documentation' select 'METADATA'
4. Check 'show API key' in the code examples panel, and you will see something like this:
<pre>
EXAMPLE USING QUERY PARAMETER
$ curl https://api.airtable.com/v0/appv------X-----c/users?api_key=keyc------X-----i
</pre>
- `keyc------X-----i` is your 'API_KEY' (also in your 'Account' area)
- `appv------X-----c` is your 'BASE_ID',
- `users` will be your 'TABLE_NAME'
## Configuring Airtable's app settings
Assign these values to the keys in the Airtable section of the `.env` file in the application root folder.
For example:
**.env** file
<pre>
# Options are 'SQLITE', 'AIRTABLE'
STORAGE='AIRTABLE'
# Airtable account
AIRTABLE_API_KEY='keyc------X-----i'
AIRTABLE_PROFILE_BASE_ID = 'appv------X-----c'
USERS_TABLE = 'users'
</pre>
A full example (which includes SQLite settings) is available in `env.sample`.
That's it! You're ready now to use the admin application or Airtable directly to manage the credentials of your users.
---
''',
unsafe_allow_html=True
)

46 changes: 46 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import streamlit as st
st.set_page_config(page_title="TheTransitClock", layout="wide")

import streamlit_debug
streamlit_debug.set(flag=False, wait_for_client=True, host='localhost', port=8765)

import env
env.verify()

from authlib.auth import auth, authenticated, requires_auth
from authlib.common import trace_activity

st.title("The Transit Clock")
user = auth(sidebar=False, show_msgs=False)

# Custom imports
from multipage import MultiPage
from pages import api, schdAhr, positionByRoutes, reports, status, extentions, allPositions # import your pages here
from streamlit_autorefresh import st_autorefresh

count = st_autorefresh(interval=20000, key="auto")


# Create an instance of the app
app = MultiPage()
if authenticated():
app.add_page("Vehicles by Route", positionByRoutes.app)
app.add_page("Vehicle positions", allPositions.app)
app.add_page("Schedule Adherance", schdAhr.app)
app.add_page("Reports", reports.app)
#app.add_page("Status", status.app)
#app.add_page("API",api.app)
#app.add_page("Extentions",extentions.app)

# The main app
app.run()
hide_st_style = """
<style>
MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
</style>
"""
st.markdown(hide_st_style, unsafe_allow_html=True)
else:
st.warning(f'Not authenticated')
4 changes: 4 additions & 0 deletions authlib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .common import const, trace_activity, AppError, DatabaseError
from .common.dt_helpers import tnow_iso , tnow_iso_str, dt_from_str, dt_from_ts, dt_to_str
from .common.crypto import aes256cbcExtended

Loading

0 comments on commit 9bf5fb0

Please sign in to comment.