first commit

This commit is contained in:
Lasse Studion 2023-03-16 11:05:14 +01:00
commit 187e554d09
2 changed files with 139 additions and 0 deletions

90
app.py Normal file
View File

@ -0,0 +1,90 @@
#! python3
import pandas as pd
import streamlit as st
def get_seconds(t):
"""Translates duration to seconds"""
return int(t[: t.find(":")]) * 60 + int(t[t.find(":") + 1 :])
def get_time(s):
h = int(s/3600)
m = int((s%3600)/60)
s = int((s%3600)%60)
if s >= 3600:
t = f'{h}:{m}:{s}'
elif s >=60:
t = f'{m:s}'
else:
t= f'{s}'
st.title("Music Report for Hindenburg")
st.markdown(
"""
**Paste your music report från Hindenburg in the field below to
get a report with the total lenght of each song used. If you chose to download it
you will get a CSV where you find the start time for each music clip in the report.**
"""
)
# Get data from clipboard
data = st.text_area(
label="Paste your music report from Hindenburg here.",
label_visibility="hidden",
placeholder="Paste music report here.",
)
if data:
rows = data.split("\n")
# Dict to fill with info
d = {}
# Get data into dict
for row in rows:
l = row.split("\t")
if len(l) < 3: # Filter out empty rows
continue
start = str(l[0])
title = l[2]
duration = l[1]
if title in d: # If the song has been used already.
d[title] = {
"Starts": d[title]["Starts"] + ", " + start,
"Duration": d[title]["Duration"] + get_seconds(duration),
"Artist": l[3],
}
else:
d[title] = {
"Starts": start,
"Duration": get_seconds(duration),
"Artist": l[3],
}
# Put data into a dataframe.
df = pd.DataFrame.from_dict(d, orient="index")
df["Title"] = df.index
df.index = [i for i in range(1, df.shape[1] + 1)]
# CSS to inject contained in a string
hide_table_row_index = """
<style>
thead tr th:first-child {display:none}
tbody th {display:none}
</style>
"""
print(df)
# Inject CSS with Markdown
st.markdown(hide_table_row_index, unsafe_allow_html=True)
# Display as dataframe.
st.dataframe(df[["Title", "Artist", "Duration"]])
st.download_button(
"Download as CSV",
data=df[["Title", "Artist", "Duration", "Starts"]]
.to_csv(index=False, sep=";")
.encode("utf-8"),
file_name="music_report.csv",
mime="text/csv",
key="download-csv",
)

49
requirements.txt Normal file
View File

@ -0,0 +1,49 @@
altair==4.2.2
attrs==22.2.0
backports.zoneinfo==0.2.1
blinker==1.5
cachetools==5.3.0
certifi==2022.12.7
charset-normalizer==3.1.0
click==8.1.3
decorator==5.1.1
entrypoints==0.4
gitdb==4.0.10
GitPython==3.1.31
idna==3.4
importlib-metadata==6.0.0
importlib-resources==5.12.0
Jinja2==3.1.2
jsonschema==4.17.3
markdown-it-py==2.2.0
MarkupSafe==2.1.2
mdurl==0.1.2
numpy==1.24.2
packaging==23.0
pandas==1.5.3
Pillow==9.4.0
pkgutil_resolve_name==1.3.10
protobuf==3.20.3
pyarrow==11.0.0
pydeck==0.8.0
Pygments==2.14.0
Pympler==1.0.1
pyrsistent==0.19.3
python-dateutil==2.8.2
pytz==2022.7.1
pytz-deprecation-shim==0.1.0.post0
requests==2.28.2
rich==13.3.2
semver==2.13.0
six==1.16.0
smmap==5.0.0
streamlit==1.20.0
toml==0.10.2
toolz==0.12.0
tornado==6.2
typing_extensions==4.5.0
tzdata==2022.7
tzlocal==4.2
urllib3==1.26.15
validators==0.20.0
zipp==3.15.0