11import download_file
22import csv
3+ from PIL import Image
4+ from PIL import ImageDraw
35
46
57def main ():
68 url = "http://www.pythonchallenge.com/pc/ring/yankeedoodle.csv"
79 file_path = "relax/yankeedoodle.csv"
10+ pic_path = "relax/hint.png"
811 user = "repeat"
912 password = "switch"
1013 # 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 )
1219
1320
1421def first_step (url , file_path , user , password ):
@@ -18,8 +25,63 @@ def first_step(url, file_path, user, password):
1825def second_step (file_path ):
1926 with open (file_path , newline = "" ) as csvfile :
2027 spamreader = csv .reader (csvfile , delimiter = ' ' , quotechar = '|' )
28+ floats = []
2129 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 )
2385
2486
2587if __name__ == "__main__" :
0 commit comments