示例#1
0
文件: lyrics.py 项目: aaronyo/lyrics
def count_cmd(args, options):
    f_stop_words = open(os.path.join(DATA_DIR, 'stop_words.txt'))
    stop_words = f_stop_words.read().split('\n')
    song_list = repo.list()
    for _, artist, title in song_list:
        lyrics = repo.load(artist, title)['lyrics']
        cnt = count.unique_words(lyrics, stop_words)
        print "%(cnt)3d: %(artist)s - %(title)s" % locals()
示例#2
0
文件: lyrics.py 项目: aaronyo/lyrics
def update_cmd(args, options):
    if args[0].endswith('yaml'):
        song_list_file = args[0]
        song_list = load_song_list( open(song_list_file) )
        for s in song_list:
            page = get_page(s['artist'], s['title'], url=s.get('lyrics-url', None), request=not options.no_request)
            if page == None:
                continue
            lyrics = parse.extract_lyrics(page)
            song = repo.load(s['artist'], s['title'], default=s)
            song['lyrics'] = lyrics
            repo.save(song)

    elif args[0].startswith('http://'):
        song_url = args[0]
        lyrics_page = get_lyrics_page(song_url)
        print parse.parse_lyrics(song_url)

    else:
        parser.print_help()
        return