A small Python script to pick lyrics, which I can use for our company lunch-game "LyricsPop".
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.

78 lines
1.4 KiB

12 years ago
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
12 years ago
import yaml
import random
def work(message):
print u'>>>', message, u'...'
12 years ago
def title(message):
print u"\n{0}\n".format(message)
12 years ago
def display(message):
print message
def get_songs():
work(u'Getting content')
12 years ago
result = None
with open('lyrics.yaml') as content:
result = yaml.load(content)
return result
def pick_song(songs):
work(u'Picking a song')
12 years ago
song = random.choice(songs)
while song['done']:
work(u'Song "{0}" was already picked, getting a new '
u'one'.format(song['song']))
12 years ago
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(u'Artist: {0}'.format(firstialize(song['artist'])))
display(u'Song: {0}'.format(firstialize(song['song'])))
12 years ago
def show_info(song):
display(u'Artist: {0}'.format(song['artist']))
display(u'Song: {0}'.format(song['song']))
12 years ago
def show_song(song):
title(u'Song picked, here it is:')
12 years ago
display(song['lyrics'])
display(u'')
12 years ago
show_hints(song)
raw_input(u'Press enter to display the answer:')
12 years ago
show_info(song)
def main():
songs = get_songs()
while True:
song = pick_song(songs)
show_song(song)
if __name__ == '__main__':
main()