forked from trivedi/lyric-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.py
44 lines (36 loc) · 1.05 KB
/
example.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
#!/usr/bin/env python
"""
Minimal Example
===============
Generating a square wordcloud from a URL
"""
from PIL import Image
from os import path
from wordcloud import WordCloud, ImageColorGenerator
from requests import get
from StringIO import StringIO
import matplotlib.pyplot as plt
from numpy import array
from lyriccloud import scrape
url = 'http://genius.com/albums/Modest-mouse/Good-news-for-people-who-love-bad-news'
cover_url, tracks = scrape.get_tracks(url)
lyrics = ''
for track, url in tracks.items():
print 'Getting lyrics for', track.strip()
lyrics += scrape.get_lyrics(url)
img_content = get(cover_url).content
album_colors = alice_coloring = array(Image.open(StringIO(img_content)))
# create coloring based on album cover art
wordcloud_colors = ImageColorGenerator(album_colors)
# Generate a word cloud image
wordcloud = WordCloud(color_func=wordcloud_colors).generate(lyrics)
plt.imshow(wordcloud)
plt.axis("off")
plt.figure()
plt.show()
'''
# The pil way (if you don't have matplotlib)
image = wordcloud.to_image()
print image
image.show()
'''