diff --git a/README.md b/README.md index 13f5194..c5ae617 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,13 @@ Python 2.7 is already installed on most of the Linux distro. 1. Render the HTML on CLI using pandoc. 2. Get some source website to search for commands. +## Usage + +- Search linux command +```shell +python main.py -s wikipedia -q pwd +``` + ### EXAMPLE *Video and screenshot will be added soon.* diff --git a/main.py b/main.py index 746975d..714403c 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import requests +import argparse from bs4 import BeautifulSoup import os import textwrap @@ -6,14 +7,18 @@ import wikipedia from GPT_API import * +sources = ['wikipedia', 'wiki', 'google', 'stackoverflow'] -query = str(sys.argv[2]) -site = str(sys.argv[1]) -print("Want to know about the command : " + query) -print("Fetching information for the command "+query+" from "+site+".") -if(site == "wikipedia" or site == "wiki"): +parser = argparse.ArgumentParser() +parser.add_argument("-s", "--site", default="wikipedia", choices=sources) +parser.add_argument("-q", "--query", default="", required=True, help="command to search") + +args = parser.parse_args() +print("Want to know about the command : " + args.query) +print("Fetching information for the command "+args.query+" from "+args.site+".") +if(args.site == "wikipedia" or args.site == "wiki"): - result = wikipedia.summary("'%s' linux command" %query, sentences = 7) + result = wikipedia.summary("'%s' linux command" %args.query, sentences = 7) print(result) # soup=BeautifulSoup(html_doc, 'html.parser') diff --git a/requirements.txt b/requirements.txt index 191a644..04867aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ + bs4 requests wikipedia