Skip to content

Commit

Permalink
Merge pull request #1 from Maxz44/master
Browse files Browse the repository at this point in the history
Adding usage info + better param gestions
  • Loading branch information
victorgarric committed Jan 22, 2021
2 parents 70036fa + 827d056 commit f0ecdb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions pip_search/pip_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@
from urllib import request
from tabulate import tabulate

def usage():
print("Usage:\n pip_search <keywords>")

def main():
if (
len(sys.argv) < 2 or "-h" in sys.argv
or "--help" in sys.argv or "--usage" in sys.argv
):
usage()
else:
search()

def search () :
keyword = ' '.join(sys.argv[1::]).replace(' ', '+')

f = request.urlopen('https://pypi.org/search/?q=%s' % sys.argv[1])
f = request.urlopen('https://pypi.org/search/?q=%s' % keyword)
raw_text=str(f.read())

raw_names=raw_text.split('<span class="package-snippet__name">')[1:-2]
Expand All @@ -23,4 +36,4 @@ def search () :
print(tabulate(header+rows))

if __name__ == '__main__':
search()
main()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
python_requires='>=3.',
entry_points={
"console_scripts": [
"pip_search=pip_search.pip_search:search",
"pip_search=pip_search.pip_search:main",
],
},
)

0 comments on commit f0ecdb7

Please sign in to comment.