Skip to content

Commit

Permalink
Use resolve-uri.
Browse files Browse the repository at this point in the history
  • Loading branch information
mlang committed Apr 20, 2016
1 parent 0e22cc2 commit 7c4671d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions github_code_search.xq
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ declare function local:source_lines($table as node()*) as xs:string*

let $results := html//div[@id="code_search_results"]/div[@class="code-list"]
for $div in $results/div
let $user := data($div/p/a[1])
let $repo := data($div/p/a[1])
let $file := data($div/p/a[2])
let $link := data($div/p/a[2]/@href)
return ($user, concat($file, ": ", $link), local:source_lines($div//table),
let $link := resolve-uri(data($div/p/a[2]/@href))
return (concat($repo, ": ", $file), $link, local:source_lines($div//table),
"---------------------------------------------------------------")


16 changes: 8 additions & 8 deletions xq.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ def coins_and_precious_metals(term):
@click.argument('language')
@click.argument('query')
def github_code_search(language, query):
response = get('https://github.com/search', params={'l': language, 'q': query, 'type': 'code'})
"""Search for source code on GitHub."""
base = 'https://github.com/search'
response = get(base, params={'l': language, 'q': query, 'type': 'code'})
response.raise_for_status()
soup = BeautifulSoup(response.text, 'lxml')
print(xquery(function_name(), soup))
print(xquery(function_name(), BeautifulSoup(response.text, 'lxml'), base=base))

###############################################################################

Expand All @@ -56,7 +57,7 @@ def drop_dtd(soup):
dtd.extract()
return soup

def xquery(xq_base, context=None, variables={}):
def xquery(xq_base, context=None, variables={}, base=None):
cmd = ['xqilla']
if context is not None:
if type(context) is BeautifulSoup:
Expand All @@ -75,13 +76,12 @@ def xquery(xq_base, context=None, variables={}):
else:
cmd.extend(['-i', context])
cmd.extend(chain.from_iterable(['-v', k, v] for k, v in variables.items()))
if base is not None:
cmd.extend(['-b', base])
cmd.append(abspath(path.join(dirname(__file__), xq_base + ".xq")))

output = run(cmd, stdout=PIPE, check=True).stdout.decode('utf-8')

if type(context) is NamedTemporaryFile:
context.close()

if type(context) is NamedTemporaryFile: context.close()
return output

if __name__ == '__main__':
Expand Down

0 comments on commit 7c4671d

Please sign in to comment.