Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add the -r flag, letting you grab a path relative to the match
  • Loading branch information
cortesi committed Nov 23, 2015
1 parent fc2e7c4 commit 9b7909c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ghrabber.py
@@ -1,6 +1,7 @@
#!/usr/bin/env python
import argparse
import os.path
import urllib

import BeautifulSoup
import requests
Expand Down Expand Up @@ -40,7 +41,7 @@ def make_fname(p):
return parts[0] + "." + parts[1]


def get(query, outdir, listonly=False):
def get(query, relative, outdir, listonly=False):
page = 1
while 1:
params = dict(
Expand All @@ -54,6 +55,8 @@ def get(query, outdir, listonly=False):
break
for u in extract(r.content):
ru = raw_url(u)
if relative:
ru = urllib.basejoin(ru, relative)
if listonly:
print ru
else:
Expand Down Expand Up @@ -83,11 +86,15 @@ def get(query, outdir, listonly=False):
"-o", type=str, default=".",
help="Output directory. Created if it doesn't exist."
)
parser.add_argument(
"-r", type=str, default=None,
help="Grab a path relative to the match"
)
parser.add_argument("query", type=str, help="Github Code Search query")
args = parser.parse_args()
if not os.path.exists(args.o):
os.makedirs(args.o)
try:
get(args.query, args.o, listonly=args.l)
get(args.query, args.r, args.o, listonly=args.l)
except KeyboardInterrupt:
pass

0 comments on commit 9b7909c

Please sign in to comment.