Skip to content

Commit

Permalink
Switched to single embedded Spotify player using Javascript
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeye committed Jan 11, 2021
1 parent a0fcedb commit 6540acf
Show file tree
Hide file tree
Showing 32 changed files with 3,635 additions and 296 deletions.
2 changes: 1 addition & 1 deletion .idea/aggro-gator.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions boomkat.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ def get_page(year):
album = release.find(class_='release__title').text.strip()

# Create Boomkat review URL
review_url = "https://boomkat.com" + result.find('div', class_='chart-item-link chart-item-link--fulldetails')\
.find('a', href=True)['href']
try:
review_url = "https://boomkat.com" + \
result.find('div', class_='chart-item-link chart-item-link--fulldetails')\
.find('a', href=True)['href']
except:
review_url = "https://boomkat.com"

# Get album images
# try:
Expand Down
29 changes: 0 additions & 29 deletions css/style.css

This file was deleted.

101 changes: 0 additions & 101 deletions data/boomkat_2015.csv

This file was deleted.

101 changes: 101 additions & 0 deletions data/boomkat_2019_album-ids.csv

Large diffs are not rendered by default.

202 changes: 101 additions & 101 deletions data/boomkat_2020.csv

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions data/boomkat_2020_album-ids.csv

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions data/pitchfork_2019_album-ids.csv

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions data/pitchfork_2020_album-ids.csv

Large diffs are not rendered by default.

760 changes: 751 additions & 9 deletions html/boomkat-2019.html

Large diffs are not rendered by default.

760 changes: 751 additions & 9 deletions html/boomkat-2020.html

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions html/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
table.center {
margin-left: auto;
margin-right: auto;
}

th, td {
font-family: Helvetica, Arial, sans-serif;
font-size: 12px;
padding: 8px;
}

th {
padding-top: 10px;
padding-bottom: 10px;
text-align: left;
background-color: #4CAF50;
position: sticky;
top: 0;
box-shadow: 0 3px 2px -1px rgba(0, 0, 0, 0.4);
}

#tr:nth-child(even){background-color: #f2f2f2;}

tr:hover {background-color: #ddd;}

h1 {
font-family: Helvetica, Arial, sans-serif;
font-size: 50px;
color: black;
text-shadow: 2px 2px dimgrey;
text-align: center;
}

footer {
position: sticky;
left: 0;
right: 0;
bottom: 0;
height: 120px;
padding: 3px;
width: 100%;
background-color: #4CAF50;
/* align-items:center;*/
font-family: Helvetica, Arial, sans-serif;
text-align: center;
box-shadow: 0 -3px 2px -1px rgba(0, 0, 0, 0.4);
}

.container {
position: relative;
text-align: center;
color: white;
width: 100%;
margin-left: auto;
margin-right: auto;
padding-top: 10px;
padding-bottom: 10px;
}

* {
box-sizing: border-box;
}

.column {
float: left;
width: 33.33%;
padding: 5px;
}

/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
}

.centered {
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Binary file added html/images/Andy Stott - It Should Be Us.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/images/Beyonce - Homecoming.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/images/Bon Iver - i, i.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/images/DJ Python - Mas Amable.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/images/Fennesz - Agora.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/images/Kelly Lee Owens - Inner Song.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/images/Lana Del Rey - The Greatest.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/images/Run the Jewels - RTJ4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/images/Sunn O - Life Metal.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
410 changes: 401 additions & 9 deletions html/pitchfork-2019.html

Large diffs are not rendered by default.

392 changes: 392 additions & 0 deletions html/pitchfork-2019_orig.html

Large diffs are not rendered by default.

410 changes: 401 additions & 9 deletions html/pitchfork-2020.html

Large diffs are not rendered by default.

391 changes: 391 additions & 0 deletions html/pitchfork-2020_orig.html

Large diffs are not rendered by default.

50 changes: 39 additions & 11 deletions html_table_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_input():

year = user_input.year

filename = site + "_" + year + "_html.csv"
filename = site + "_" + year + "_album-ids.csv"

# Import album data
df = pd.read_csv("data/" + filename)
Expand All @@ -45,13 +45,32 @@ def get_input():
# Create webpage header and footer content
html_head = '''
<html>
<head><title>''' + site.title() + ''''s Top Albums of ''' + year + '''</title></head>
<head>
<title>''' + site.title() + ''''s Top Albums of ''' + year + '''</title>
</head>
<link rel="stylesheet" href="css/style.css"/>
<body>
<h1>''' + site.title() + ''''s Top Albums of ''' + year + '''</h1>
<div class="container">
<div class="centered">
<h1>''' + site.title() + ''''s Top Albums of ''' + year + '''</h1>
</div>
</div>
<script type="text/javascript">
function getSpotfiyPlayer(album_id) {
var player_prefix = "<iframe src=\\\'https://open.spotify.com/embed/album/";
var player_suffix = "\\\' width=\\\"300\\\" height=\\\"80\\\" frameborder=\\\"0\\\" allowtransparency=\\\"true\\\" allow=\\\"encrypted-media\\\"></iframe>";
document.getElementById("player").innerHTML = player_prefix.concat(album_id, player_suffix);
}
</script>
'''

html_end = '''
</body>
<footer>
<p id="player"></p>
</footer>
</html>
'''

Expand All @@ -60,16 +79,16 @@ def get_input():

with open("html/" + outfile, 'w', encoding="utf-8-sig") as f:
f.write(html_head)
f.write('<table width=1280px class="center">')
f.write('<col style = "width:5%">')
f.write('<table class="center">')
f.write('<col style = "width:5%">')
f.write('<col style = "width:15%">')
f.write('<col style = "width:50%">')
f.write('<col style = "width:25%">')
f.write('<col style = "width:15%">')
f.write('<col style = "width:30%">')
f.write('<col style = "width:10%">')
f.write('<thead>')
f.write('<tr>')
for header in df.columns:
if header == 'html':
if header == 'album_id':
f.write('<th>' + "Play Album" + '</th>')
else:
f.write('<th>' + str(header).title() + '</th>')
Expand All @@ -80,9 +99,18 @@ def get_input():
f.write('<tr>')
for col in df.columns:
value = df.iloc[i][col]
f.write('<td>' + str(value) + '</td>')
f.write('<tr>')
f.write('</table>')
if col == 'rank':
f.write('<td align="center">' + str(value) + '</td>')
elif col == 'album_id':
if value == 'Not available':
f.write('<td align="center">' + str(value) + '</td>')
else:
f.write('<td align="center"><button onclick="getSpotfiyPlayer(\'' \
+ value + '\')">Load Player</button></td>')
else:
f.write('<td>' + str(value) + '</td>')
f.write('\t\t</tr>')
f.write('\t</table>')
f.write(html_end)


Expand Down
28 changes: 14 additions & 14 deletions spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def get_input():
# Import album data
df = pd.read_csv("data/" + filename)

html = []
album_ids = []

# Get Spotify ID for each album and create HTML code for embeddable Spotify player
for i in range(len(df)):
Expand Down Expand Up @@ -80,24 +80,24 @@ def get_input():
album_data = data.json()
album_id = album_data['albums']['items'][0]['id']

width = '"300"'
height = '"80"'
base = '<iframe src="https://open.spotify.com/embed/album/'
frame_border = '"0"'
allow_transparency = '"true"'
allow = '"encrypted-media'
code = base + album_id + '"' + ' width=' + width + ' height=' + height + ' frameborder=' + frame_border \
+ ' allowtransparency=' + allow_transparency + ' allow=' + allow + '"></iframe>'
# width = '"300"'
# height = '"80"'
# base = '<iframe src="https://open.spotify.com/embed/album/'
# frame_border = '"0"'
# allow_transparency = '"true"'
# allow = '"encrypted-media'
# code = base + album_id + '"' + ' width=' + width + ' height=' + height + ' frameborder=' + frame_border \
# + ' allowtransparency=' + allow_transparency + ' allow=' + allow + '"></iframe>'
else:
print(str(i + 1), ':', 'artist:', artist, 'album:', album, 'available: No')
code = "Not available"
album_id = "Not available"
else:
print(str(i + 1), ':', 'artist:', artist, 'album:', album, 'available: No')
code = 'Not available'
album_id = 'Not available'

html.append(code)
album_ids.append(album_id)

df['html'] = pd.Series(html)
df['album_id'] = pd.Series(album_ids)

# Output data to file
df.to_csv("data/" + site + "_" + year + "_html.csv", index=False)
df.to_csv("data/" + site + "_" + year + "_album-ids.csv", index=False)

0 comments on commit 6540acf

Please sign in to comment.