- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path30.py
More file actions
Latest commit
88 lines (72 loc) · 2.06 KB
/
Copy path30.py
File metadata and controls
88 lines (72 loc) · 2.06 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
importdownload_file
importcsv
fromPILimportImage
fromPILimportImageDraw
defmain():
url="http://www.pythonchallenge.com/pc/ring/yankeedoodle.csv"
file_path="relax/yankeedoodle.csv"
pic_path="relax/hint.png"
user="repeat"
password="switch"
# first_step(url, file_path, user, password)
floats=second_step(file_path)
points=third_step(floats)
fourth_step(points, pic_path)
an=fifth_step(floats)
sixth_step(an)
deffirst_step(url, file_path, user, password):
download_file.download_with_auth(url, file_path, user, password)
defsecond_step(file_path):
withopen(file_path, newline="") ascsvfile:
spamreader=csv.reader(csvfile, delimiter=' ', quotechar='|')
floats= []
forrowinspamreader:
foriinrange(len(row)):
floatStr=row[i][0:-1]
floats.append(float(floatStr))
returnfloats
defthird_step(input):
points= []
foriinrange(len(input)):
point=input[i] *0x100
points.append(int(point))
returnpoints
deffourth_step(input, path):
width=139
height=53
im=Image.new("P", (width, height))
drawer=ImageDraw.Draw(im)
counter=0
forxinrange(width):
foryinrange(height):
drawer.point((x, y), input[counter])
counter+=1
im.save(path)
deffifth_step(input):
an= []
x="0"
y="0"
z="0"
foriinrange(len(input)):
ifi%3==0:
iflen(str(input[i])) >5:
x=str(input[i])[5]
elifi%3==1:
iflen(str(input[i])) >5:
y=str(input[i])[5]
elifi%3==2:
iflen(str(input[i])) >6:
z=str(input[i])[6]
an.append(int(x+y+z))
x="0"
y="0"
z="0"
returnan
defsixth_step(input):
result=""
foriinrange(len(input)):
value=chr(input[i])
result+=value
print(result)
if__name__=="__main__":
main()