Always hacking at something, rabbitear's thoughts and notes about free software, computer security, and the random.

About Me bLog Resume' tHe sHacK! My GitHub

Python Its Easy Language To Learn

21 Sep 2012

Python!  Well its an easy language to learn.  I want to master it, so I'm making myself commit to at least three random that may or may not be useful, python tools a week.  This to keep my python skill sharp, and I will post my discoveries here.

The script grabs a url of unconditional file type to a file.

# grabs a url to a file.

import sys
import urllib2
from os.path import basename
from urlparse import urlsplit

if len(sys.argv) < 2:
print "Usage: %s <URL>" % sys.argv[0]

url = sys.argv[1]
urlContent = urllib2.urlopen(url).read()
fileName = basename(urlsplit(url)[2])
print "filename is: %s" % fileName
output = open(fileName,'wb')

Trying to keep it simple as possible with minimal error checking.  You can add your own if you use the code.