File tree 1 file changed +17
-0
lines changed 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 6
6
import argparse
7
7
import requests
8
8
9
+ try :
10
+ from urllib .parse import urlparse
11
+ except ImportError :
12
+ from urlparse import urlparse
13
+
9
14
try :
10
15
import clipboard
11
16
except ImportError :
@@ -16,6 +21,12 @@ def main(args):
16
21
ap = argparse .ArgumentParser ()
17
22
ap .add_argument ('url' , nargs = '?' , help = 'the url to read (default to clipboard' )
18
23
ap .add_argument ('-o' , '--output-file' , help = 'write output to file instead of stdout' )
24
+ ap .add_argument (
25
+ '-O' ,
26
+ '--remote-name' ,
27
+ action = 'store_true' ,
28
+ help = 'write output to a local file named like the remote file we get'
29
+ )
19
30
ap .add_argument (
20
31
'-X' ,
21
32
'--request-method' ,
@@ -50,6 +61,12 @@ def main(args):
50
61
if ns .output_file :
51
62
with open (ns .output_file , 'w' ) as outs :
52
63
outs .write (r .text )
64
+ elif ns .remote_name :
65
+ # get basename of url
66
+ url_path = urlparse (url ).path
67
+ filename = url_path .split ('/' )[- 1 ]
68
+ with open (filename , 'w' ) as outs :
69
+ outs .write (r .text )
53
70
else :
54
71
print (r .text )
55
72
You can’t perform that action at this time.
0 commit comments