usr bin python coding utf8 import sys os urllib2 def getsize gurl if g

 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
#!/usr/bin/python
# -*- coding: utf8 -*-
import sys, os, urllib2
def getsize(gurl=''):
if gurl == "\r\n" or gurl == "": return -1 #FIXME
req = urllib2.Request(url=gurl)
try:
ut = urllib2.urlopen(req)
except:
return -1
return ut.headers.getheader('Content-Length')
open_filename = 'urls.txt'
try:
fl = open(open_filename, 'r')
except IOError:
sys.exit("Невозможно открыть файл %s" % (open_filename))
url_lines = fl.readlines()
fl.close
for file_url in url_lines:
url_fs = 1 #getsize(file_url)
if url_fs == -1: continue
#file_url = file_url[:len(file_url)-2] #FIXME
file_url = urlparse.urlsplit(file_url).geturl()
print file_url
file_name = os.path.basename(file_url)
file_dir = os.getcwd()
file_path = os.path.join(file_dir, file_name).replace('\\','/')
if os.path.isfile(file_path):
local_fs = os.path.getsize(file_path)
if int(local_fs) == int(url_fs): continue
#os.system('wget -c -P %s -o %s/wget.log %s' % (file_dir, file_dir, file_url))
#os.system('wget -c -P %s %s' % (file_dir, file_url))
print 'wget -c -P %s %s' % (file_dir, file_url)
#os.system('echo "wget -c -P %s %s"' % (file_dir, file_url))