-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateOutput.py
More file actions
57 lines (47 loc) · 1.84 KB
/
createOutput.py
File metadata and controls
57 lines (47 loc) · 1.84 KB
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
outputStartStr = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Spotify Data</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="app-shell">
<header class="app-header">
<h1>{}</h1>
<p>Generated using Python + Spotify API</p>
</header>
<main class="song-list">"""
outputEndStr = """</main>
</div>
</body>
</html>"""
middleStrSkeleton = """<div class="song-row">
<img class="song-cover" src="{}" alt="Album Cover" />
<div class="song-info">
<div class="song-title">{}</div>
<div class="song-artist">{} / {}</div>
</div>
<div class="song-data">{}</div>
</div>"""
#this function will take an ordered list of tuples of song information and create an
#output html file that holds the song information in a pretty way
#inSongs :: {(SongName, SongAlbum, SongArtist, SongAlbumCover, Data)}
#SongName::string
#SongArtist::string
#SongAlbum::string
#SongAlbumCover::URL
#Data::string/int/double/float (will be cast to string)
#DataType::String
def createOutputFile(inSongs, DataType="Songs", outFileName="createdOutput"):
outputMiddleStr = ""
for song in inSongs:
outputMiddleStr += middleStrSkeleton.format(song[3], song[0], song[2], song[1], str(song[4]))
with open(outFileName+".html", 'w') as f:
f.write(outputStartStr.format(DataType)+outputMiddleStr+outputEndStr)
return
#TesterCode to make sure that this works
"""testList = [("Bags", "Immunity", "Clairo", "https://upload.wikimedia.org/wikipedia/en/5/56/Clairo_-_Immunity.png", "3:20"),
("Alewife", "Immunity", "Clairo", "https://upload.wikimedia.org/wikipedia/en/5/56/Clairo_-_Immunity.png", "4:10") ]
createOutputFile(testList, "Songs", "createdOutput)"""