File size: 3,275 Bytes
c43be04
1a3f8bd
87f95e1
afa1625
1277e6b
c43be04
e665916
 
 
 
 
 
 
d050fe6
afa1625
 
 
 
 
 
d050fe6
 
ea59733
d050fe6
e665916
 
 
 
 
 
 
 
 
afa1625
 
 
 
 
 
 
 
250903a
d050fe6
e665916
 
afa1625
 
e665916
 
d050fe6
 
 
e665916
 
 
 
afa1625
 
e665916
 
afa1625
d050fe6
 
e665916
 
 
 
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
import streamlit as st
import pandas as pd
from songscope import *
import random
# !python -m pip install --upgrade pip

# main header
st.title("SongScope")

# web app explainer
st.write("Welcome to SongScope. This is a web app that lets you download lyrics and metadata of your favourite artist.\n")
st.write("Enter an artist name, and you can even select up to 5 songs to retrieve their data. If you don't specify any songs,\ndata on all songs by the artist will be retrieved.")

# delay times
# delay_min = float(st.text_input("Minimum delay per iteration. We recommend a value of at least 10 seconds per song, otherwise you may be banned from azlyrics.com for scraping."))
# delay_max = float(st.text_input("Maximum delay per iteration. We recommend a value of at least 10 seconds per song, otherwise you may be banned from azlyrics.com for scraping."))
delay_min = st.number_input(label = "Minimum delay per iteration. We recommend a value of at least 10 seconds per song, otherwise you may be banned from azlyrics.com for scraping.",
                            step = 1., format = "%.2f")
delay_max = st.number_input(label = "Maximum delay per iteration. We recommend a value of at least 10 seconds per song, otherwise you may be banned from azlyrics.com for scraping.",
                            step = 1., format = "%.2f")
# delay_min = 15
# delay_max = 30
# sysBP = st.number_input(label=“systolic blood pressure”,step=1.,format="%.2f")

# user-provided data
artist_name = st.text_input("Enter artist name here")
song_1 = st.text_input("Enter 1st song title here")
song_2 = st.text_input("Enter 2nd song title here")
song_3 = st.text_input("Enter 3rd song title here")
song_4 = st.text_input("Enter 4th song title here")
song_5 = st.text_input("Enter 5th song title here")

# data is found
find_button = st.button('Find Data')
if not find_button: # button to make everything run
    st.write("Once you've entered the above data, click the 'Find Data' button, above, to begin.")
else:
    artist_df = get_all_data(artist_name = artist_name, 
            song_titles = song_1 + song_2 + song_3 + song_4 + song_5,
            delay = (delay_min, delay_max), # random float value between (delay_min, delay_max) seconds
            print_progress = True)
        
# artist_df.to_csv(f"{artist_name.lower()}_data.csv")

# user downloads found data here
if find_button:
    dl_button = st.download_button('Download Data', artist_df, f"{artist_name.lower()}_data.csv")
# st.download_button('Download Data', DATA_TO_CSV)  # Defaults to 'text/plain'

# with open(f'{artist_name.lower()}_data.csv') as f:
#     st.download_button('Download CSV', f)  # Defaults to 'text/plain'
#     st.write("Your data should now be downloading.")
    
# fun facts
fun_fax = []
with open("fun_fax.txt", "r", encoding = "utf-8") as f:
    for fact in f.read().split("\n"):
        fun_fax.append(fact)
f.close() # closes connection to file

if dl_button:
    st.write("Your data should be downloaded. If not, please reload the page and try again.")

st.write(fun_fax[random.randint(0, len(fun_fax) - 1)])

# "thank you" blurb
st.write("\nThanks for checking out Wordle Wizard! If you have any feedback or requests for additions to this app, shoot me an email at kmaurinjones@gmail.com.")