You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.4 KiB
75 lines
1.4 KiB
#!/usr/bin/env python |
|
|
|
import yaml |
|
import random |
|
|
|
|
|
def work(message): |
|
print '>>>', message, '...' |
|
|
|
|
|
def title(message): |
|
print "\n{0}\n".format(message) |
|
|
|
|
|
def display(message): |
|
print message |
|
|
|
|
|
def get_songs(): |
|
work('Getting content') |
|
result = None |
|
with open('lyrics.yaml') as content: |
|
result = yaml.load(content) |
|
return result |
|
|
|
|
|
def pick_song(songs): |
|
work('Picking a song') |
|
song = random.choice(songs) |
|
|
|
while song['done']: |
|
work('Song "{0}" was already picked, getting a new ' |
|
'one'.format(song['song'])) |
|
song = random.choice(songs) |
|
|
|
return song |
|
|
|
|
|
def firstialize(string): |
|
result = [] |
|
for word in string.split(' '): |
|
result.append(word[0]) |
|
return ''.join(result).upper() |
|
|
|
|
|
def show_hints(song): |
|
display('Artist: {0}'.format(firstialize(song['artist']))) |
|
display('Song: {0}'.format(firstialize(song['song']))) |
|
|
|
|
|
def show_info(song): |
|
display('Artist: {0}'.format(song['artist'])) |
|
display('Song: {0}'.format(song['song'])) |
|
|
|
|
|
def show_song(song): |
|
title('Song picked, here it is:') |
|
display(song['lyrics']) |
|
display('') |
|
|
|
show_hints(song) |
|
|
|
raw_input('Press enter to display the answer:') |
|
|
|
show_info(song) |
|
|
|
|
|
def main(): |
|
songs = get_songs() |
|
while True: |
|
song = pick_song(songs) |
|
show_song(song) |
|
|
|
if __name__ == '__main__': |
|
main()
|
|
|