-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcurl3.py
More file actions
28 lines (23 loc) · 890 Bytes
/
curl3.py
File metadata and controls
28 lines (23 loc) · 890 Bytes
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
import os
import urllib.request, urllib.parse, urllib.error
print('Παρακαλώ εισαγάγετε μια διεύθυνση URL όπωςhttp://data.pr4e.org/cover3.jpg')
urlstr = input().strip()
img = urllib.request.urlopen(urlstr)
# Πάρε την τελευταία "λέξη"
words = urlstr.split('/')
fname = words[-1]
# Μην αντικαταστήσεις το αρχείο
if os.path.exists(fname):
if input('Να αντικατασταθεί το ' + fname + ' (Ν/ο)?') != 'Ν':
print('Τα δεδομένα δεν αντιγράφηκαν')
exit()
print('Αντικατάσταση του', fname)
fhand = open(fname, 'wb')
size = 0
while True:
info = img.read(100000)
if len(info) < 1: break
size = size + len(info)
fhand.write(info)
print(size, 'χαρακτήρες αντιγράφηκαν στο ', fname)
fhand.close()