-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotipy.py
142 lines (108 loc) · 4.09 KB
/
spotipy.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from song import *
from album import *
from artist import *
class SpotiPy:
def __init__(self):
self.__artists = []
def getArtists(self):
return self.__artists
def addArtists(self, *newArtist):
for j in newArtist:
if self.__artists == []:
self.__artists.append(j)
continue
flag = True
for i in self.__artists:
if not ((i.getFirstName() != j.getFirstName()) or (i.getLastName() != j.getLastName()) or (i.getBirthYear() != j.getBirthYear())):
flag = False
break
if flag:
self.__artists.append(j)
def getTopTrendingArtist(self):
if self.__artists != []:
artistLikes = []
for l in self.__artists:
artistLikes.append(l.totalLikes())
artistLikes.sort()
trendingArtist = artistLikes[-1]
for j in self.__artists:
if j.totalLikes() == trendingArtist:
return (j.getFirstName(), j.getLastName())
else:
return None
def getTopTrendingAlbum(self):
if self.__artists != []:
albumLikes = []
for i in self.__artists:
for j in i.getAlbums():
albumLikes.append(j.helperTotalLikes())
albumLikes.sort()
trendingAlbum = albumLikes[-1]
for artists in self.__artists:
for albums in artists.getAlbums():
if albums.helperTotalLikes() == trendingAlbum:
return albums
else:
return None
def getTopTrendingSong(self):
mostLiked = 0
topLikes = []
for i in self.__artists:
for j in i.getAlbums():
for l in j.getSongs():
topLikes.append(l.getLikes())
for k in topLikes:
if k >= mostLiked:
mostLiked = k
topLikedSingle = 0
topLikesOfSingles = []
for i in self.__artists:
for j in i.getSingles():
topLikesOfSingles.append(j.getLikes())
for k in topLikesOfSingles:
if k >= topLikedSingle:
topLikedSingle = k
topLikedSongVar = 0
if mostLiked >= topLikedSingle:
topLikedSongVar = mostLiked
else:
topLikedSongVar = topLikedSingle
for albums in self.__artists:
if albums.getAlbums() != []:
for i in albums.getAlbums():
for j in i.getSongs():
if j.getLikes() == topLikedSongVar:
return j
for singles in self.__artists:
for i in singles.getSingles():
if i.getLikes() == topLikedSongVar:
return i
def loadFromFile(self):
def loadFromFile(self):
with open("artists.txt", "r") as f:
for line in f:
line = line.strip()
line = line.split(",")
artist = Artist(line[0], line[1], line[2])
self.__artists.append(artist)
with open("albums.txt", "r") as f:
for line in f:
line = line.strip()
line = line.split(",")
album = Album(line[0], line[1], line[2], line[3])
for i in self.__artists:
if i.getFirstName() == line[3]:
i.addAlbums(album)
with open("songs.txt", "r") as f:
for line in f:
line = line.strip()
line = line.split(",")
song = Song(line[0], line[1], line[2], line[3])
for i in self.__artists:
if i.getFirstName() == line[3]:
if line[2] == "single":
i.addSingles(song)
else:
for j in i.getAlbums():
if j.getName() == line[2]:
j.addSongs(song)