Skip to content

Commit 9b7909c

Browse files
committed
Add the -r flag, letting you grab a path relative to the match
1 parent fc2e7c4 commit 9b7909c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ghrabber.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
import argparse
33
import os.path
4+
import urllib
45

56
import BeautifulSoup
67
import requests
@@ -40,7 +41,7 @@ def make_fname(p):
4041
return parts[0] + "." + parts[1]
4142

4243

43-
def get(query, outdir, listonly=False):
44+
def get(query, relative, outdir, listonly=False):
4445
page = 1
4546
while 1:
4647
params = dict(
@@ -54,6 +55,8 @@ def get(query, outdir, listonly=False):
5455
break
5556
for u in extract(r.content):
5657
ru = raw_url(u)
58+
if relative:
59+
ru = urllib.basejoin(ru, relative)
5760
if listonly:
5861
print ru
5962
else:
@@ -83,11 +86,15 @@ def get(query, outdir, listonly=False):
8386
"-o", type=str, default=".",
8487
help="Output directory. Created if it doesn't exist."
8588
)
89+
parser.add_argument(
90+
"-r", type=str, default=None,
91+
help="Grab a path relative to the match"
92+
)
8693
parser.add_argument("query", type=str, help="Github Code Search query")
8794
args = parser.parse_args()
8895
if not os.path.exists(args.o):
8996
os.makedirs(args.o)
9097
try:
91-
get(args.query, args.o, listonly=args.l)
98+
get(args.query, args.r, args.o, listonly=args.l)
9299
except KeyboardInterrupt:
93100
pass

0 commit comments

Comments
 (0)