2015-06-20 06:43:14 +03:00
|
|
|
import os
|
2016-08-29 14:53:48 +03:00
|
|
|
import sys
|
2015-06-20 06:43:14 +03:00
|
|
|
import urllib.parse
|
|
|
|
import urllib.request
|
|
|
|
|
2014-03-25 09:09:53 +04:00
|
|
|
|
|
|
|
def fetch(url):
|
|
|
|
name = urllib.parse.urlsplit(url)[2].split('/')[-1]
|
|
|
|
|
|
|
|
if not os.path.exists(name):
|
|
|
|
print("Fetching", url)
|
2019-03-12 12:44:00 +03:00
|
|
|
try:
|
|
|
|
r = urllib.request.urlopen(url)
|
|
|
|
except urllib.error.URLError:
|
|
|
|
r = urllib.request.urlopen(url)
|
|
|
|
content = r.read()
|
2014-03-25 09:09:53 +04:00
|
|
|
with open(name, 'wb') as fd:
|
|
|
|
fd.write(content)
|
|
|
|
return name
|
|
|
|
|
2018-03-03 12:54:00 +03:00
|
|
|
|
2015-06-20 06:43:14 +03:00
|
|
|
if __name__ == '__main__':
|
2014-03-25 09:09:53 +04:00
|
|
|
fetch(sys.argv[1])
|