-
Notifications
You must be signed in to change notification settings - Fork 0
/
song.py
69 lines (55 loc) · 1.75 KB
/
song.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
"""This module contains the song class and its methods.
Classes:
Song
Functions:
assign_lyrics_and_wordcount
"""
class Song:
"""
A class to represent a song and its attributes.
...
Attributes
----------
title : str
the title of the song
lyrics_found : bool
whether the lyrics for the song were found with a lyricsovh api call
lyrics : str
the lyrics for the song.
word_count : int
the word count for the lyrics
Methods
-------
assign_lyrics_and_wordcount
"""
def __init__(self, title, lyrics=None, lyrics_found=False, word_count=0) -> None:
"""
Constructs all the necessary attributes for the song object.
Parameters
----------
title : str
the title of the song
lyrics_found : bool
whether the lyrics for the song were found with a lyricsovh api call
lyrics : str
the lyrics for the song.
word_count : int
the word count for the lyrics
"""
self.title = title
self.lyrics = None
self.lyrics_found = False
self.word_count = 0
def assign_lyrics_and_wordcount(self, lyrics: str) -> None:
"""
A function to assign the lyrics and the lyrics wordcount for a song to the song object.
Also sets lyrics_found to True for this object
:param lyrics: a str of the lyrics for the song
:return: None
"""
# assign the lyrics to the object and set lyrics_found to True
self.lyrics = lyrics
self.lyrics_found = True
# calculate the word count for the lyrics
word_count = len(lyrics.split())
self.word_count = word_count