1
1
import download_file
2
2
import csv
3
+ from PIL import Image
4
+ from PIL import ImageDraw
3
5
4
6
5
7
def main ():
6
8
url = "http://www.pythonchallenge.com/pc/ring/yankeedoodle.csv"
7
9
file_path = "relax/yankeedoodle.csv"
10
+ pic_path = "relax/hint.png"
8
11
user = "repeat"
9
12
password = "switch"
10
13
# first_step(url, file_path, user, password)
11
- second_step (file_path )
14
+ floats = second_step (file_path )
15
+ points = third_step (floats )
16
+ fourth_step (points , pic_path )
17
+ an = fifth_step (floats )
18
+ sixth_step (an )
12
19
13
20
14
21
def first_step (url , file_path , user , password ):
@@ -18,8 +25,63 @@ def first_step(url, file_path, user, password):
18
25
def second_step (file_path ):
19
26
with open (file_path , newline = "" ) as csvfile :
20
27
spamreader = csv .reader (csvfile , delimiter = ' ' , quotechar = '|' )
28
+ floats = []
21
29
for row in spamreader :
22
- print (" " .join (row ))
30
+ for i in range (len (row )):
31
+ floatStr = row [i ][0 :- 1 ]
32
+ floats .append (float (floatStr ))
33
+ return floats
34
+
35
+
36
+ def third_step (input ):
37
+ points = []
38
+ for i in range (len (input )):
39
+ point = input [i ] * 0x100
40
+ points .append (int (point ))
41
+ return points
42
+
43
+
44
+ def fourth_step (input , path ):
45
+ width = 139
46
+ height = 53
47
+ im = Image .new ("P" , (width , height ))
48
+ drawer = ImageDraw .Draw (im )
49
+ counter = 0
50
+ for x in range (width ):
51
+ for y in range (height ):
52
+ drawer .point ((x , y ), input [counter ])
53
+ counter += 1
54
+ im .save (path )
55
+
56
+
57
+ def fifth_step (input ):
58
+ an = []
59
+ x = "0"
60
+ y = "0"
61
+ z = "0"
62
+ for i in range (len (input )):
63
+ if i % 3 == 0 :
64
+ if len (str (input [i ])) > 5 :
65
+ x = str (input [i ])[5 ]
66
+ elif i % 3 == 1 :
67
+ if len (str (input [i ])) > 5 :
68
+ y = str (input [i ])[5 ]
69
+ elif i % 3 == 2 :
70
+ if len (str (input [i ])) > 6 :
71
+ z = str (input [i ])[6 ]
72
+ an .append (int (x + y + z ))
73
+ x = "0"
74
+ y = "0"
75
+ z = "0"
76
+ return an
77
+
78
+
79
+ def sixth_step (input ):
80
+ result = ""
81
+ for i in range (len (input )):
82
+ value = chr (input [i ])
83
+ result += value
84
+ print (result )
23
85
24
86
25
87
if __name__ == "__main__" :
0 commit comments