Created
April 6, 2017 14:51
-
-
Save WalterS/8b0bca7613e949bce476f55ccd7c2914 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
import os, re, requests | |
site = 'http://download.opensuse.org/repositories/devel:/languages:/haskell:/lts:/6/openSUSE_Backports_SLE-12-SP2/x86_64/' | |
response = requests.get(site) | |
if response.status_code == 404: | |
raise Exception('Website not available, HTTP response code: ' + str(response.status_code)) | |
filename = sorted(set(re.findall('ShellCheck-[0-9].*?rpm',response.content)))[-1] | |
if filename == '': | |
raise Exception('Remote file not found') | |
else: | |
print 'Found ' + filename | |
if os.path.isfile(filename): | |
raise Exception('File exists already') | |
import urllib2 | |
url = os.path.join(site, filename) | |
u = urllib2.urlopen(url) | |
f = open(filename, 'wb') | |
meta = u.info() | |
file_size = int(meta.getheaders("Content-Length")[0]) | |
print "Downloading: %s Bytes: %s" % (filename, file_size) | |
file_size_dl = 0 | |
block_sz = 8192 | |
while True: | |
buffer = u.read(block_sz) | |
if not buffer: | |
break | |
file_size_dl += len(buffer) | |
f.write(buffer) | |
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size) | |
status = status + chr(8)*(len(status)+1) | |
print status, | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment