Created
January 13, 2013 09:02
-
-
Save 0xKD/4523076 to your computer and use it in GitHub Desktop.
BeautifulSoup 4 download and install script.
This file contains 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
import urllib2 | |
import tarfile | |
import os | |
url = 'http://pypi.python.org/packages/source/b/beautifulsoup4/beautifulsoup4-4.1.3.tar.gz' | |
file_name = url.split('/')[-1] | |
u = urllib2.urlopen(url) | |
f = open(file_name, 'wb') | |
meta = u.info() | |
file_size = int(meta.getheaders("Content-Length")[0]) | |
print "Downloading: %s Bytes: %s" % (file_name, file_size) | |
file_size_dl = 0 | |
block_sz = 4096 | |
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, | |
print '\n' | |
f.close() | |
tar = tarfile.open(file_name,'r') | |
for items in tar: | |
tar.extract(items,'bs4') | |
os.chdir('bs4') | |
os.chdir('beautifulsoup4-4.1.3') | |
os.system('python setup.py install') | |
print '\nBeautifulSoup should now be installed. If not, check if the python executable is in your PATH.' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment