annotate tools/data_source/fetch.py @ 0:9071e359b9a3

Uploaded
author xuebing
date Fri, 09 Mar 2012 19:37:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
1 #!/usr/bin/env python
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
2
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
3 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
4 Script that just echos the command line.
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
5 """
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
6
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
7 import sys, os, urllib
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
8
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
9 assert sys.version_info[:2] >= ( 2, 4 )
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
10
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
11 BUFFER = 1048576
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
12
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
13 url = sys.argv[1]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
14 out_name = sys.argv[2]
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
15
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
16 out = open(out_name, 'wt')
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
17 try:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
18 page = urllib.urlopen(url)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
19 while 1:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
20 data = page.read(BUFFER)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
21 if not data:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
22 break
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
23 out.write(data)
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
24 except Exception, e:
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
25 print 'Error getting the data -> %s' % e
9071e359b9a3 Uploaded
xuebing
parents:
diff changeset
26 out.close()