File: cat_url.py

package info (click to toggle)
ghostscript 10.05.1~dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 93,508 kB
  • sloc: ansic: 908,895; python: 7,676; cpp: 6,534; cs: 6,457; sh: 6,168; java: 4,028; perl: 2,373; tcl: 1,639; makefile: 529; awk: 66; yacc: 18
file content (41 lines) | stat: -rwxr-xr-x 852 bytes parent folder | download | duplicates (5)
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
40
41
#!/usr/bin/env python

# print a url's to stdout

from urllib import *
from urlparse import *

debug = 0

def error(msg):
	print sys.argv[0], "error: ", msg
        print "\t", sys.argv[0], "http://host[:port]/path"
        print "\t", sys.argv[0], "ftp://username:password@host/dir/file"
	print "\t", sys.argv[0], "file:/usr/dict/words"
	sys.exit(1)

try:
	for url in sys.argv[1:]:

		scheme, netloc, url, params, query, fragment = urlparse(url)
		if debug:
			print "scheme", "=", scheme
			print "netloc", "=",  netloc
			print "url", "=", url
			print "params", "=", params
			print "query", "=", query
			print "fragment", "=", fragment

except:
	error("all arguments must be urls")


for url in sys.argv[1:]:
	try:
		fn, h = urlretrieve(url)
	except:
		error("Couldn't retrive url")

	fp = open(fn, 'rb')
	sys.stdout.write(fp.read())
	fp.close()