12
12
13
13
from auth import get_last_src_url
14
14
from auth import read_url
15
+ from cache import autocached
16
+ from image import image_to_text
15
17
from itertools import chain
16
18
from PIL import Image
17
19
18
20
import io
19
21
import wave
20
22
21
23
24
+ @autocached
22
25
def read_waves (url ):
23
26
"""Reads all the WAVE files there are available under similar URLs"""
24
27
i , waves = 1 , []
@@ -32,6 +35,7 @@ def read_waves(url):
32
35
return waves
33
36
34
37
38
+ @autocached
35
39
def create_image (waves ):
36
40
"""Creates an image out of the WAVE frames"""
37
41
wav_size = int ((len (waves [0 ]) / 3 ) ** 0.5 ) # a square with len(waves[0]) RGB pixels
@@ -52,7 +56,18 @@ def create_image(waves):
52
56
return new_image
53
57
54
58
59
+ @autocached
60
+ def blue_only (image ):
61
+ """Creates a new image with only the bluest pixels"""
62
+ img = Image .new ("L" , (image .width , image .height ))
63
+ for y in range (image .height ):
64
+ for x in range (image .width ):
65
+ r , g , b = image .getpixel ((x , y ))
66
+ if b > 1.2 * r and b > 1.2 * g :
67
+ img .putpixel ((x , y ), b )
68
+ return img
69
+
70
+
55
71
url = get_last_src_url ("http://www.pythonchallenge.com/pc/hex/lake.html" )
56
- image_name = "25-lake.png"
57
- create_image (read_waves (url .replace ("jpg" , "wav" ))).save (image_name )
58
- print ("Check" , image_name )
72
+ image = create_image (read_waves (url .replace ("jpg" , "wav" )))
73
+ print (image_to_text (blue_only (image )))
0 commit comments