-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f3a052c
commit ad7a47e
Showing
4 changed files
with
93 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,41 +18,57 @@ | |
|
||
## Installation | ||
|
||
Install as you would with pip **using pypi** under the name `askquestions` - | ||
Install **using pypi** --> | ||
|
||
$ pip3 install askquestions | ||
|
||
Or **git** - | ||
Or **git** --> | ||
|
||
$ pip3 install git+https://github.com/ronnathaniel/how | ||
|
||
Or **from source** - | ||
Or **from source** --> | ||
|
||
$ git clone https://github.com/ronnathaniel/how.git | ||
$ cd how | ||
$ pip3 install . | ||
|
||
## Usage | ||
|
||
$ how QUERY ... [-n N] | ||
$ how QUERY* | ||
|
||
Ask your terminal directly. | ||
|
||
$ how do i exit vim | ||
➜ https://stackoverflow.com/questions/11828270/how-do-i-exit-the-vim-editor | ||
➜ https://stackoverflow.com/questions/25919461/i-cannot-exit-vim-i-hit-escape-and-tried-q-x-qx | ||
➜ https://stackoverflow.com/questions/47315349/how-to-exit-the-vim-editor-when-q-or-x-doesnt-work | ||
➜ https://stackoverflow.com/questions/1879219/how-to-temporarily-exit-vim-and-go-back | ||
➜ https://stackoverflow.com/questions/31140908/how-do-i-save-and-quit-from-vim | ||
➜ ... | ||
➜ ... | ||
|
||
Arguments | ||
Optional Arguments | ||
|
||
- `-n`: (int) Amount of links to return. Defaults to 5. | ||
**shorthand**|**longhand**|**type**|**default**|**description** | ||
:-----:|:-----:|:-----:|:-----:|:-----: | ||
-n|--num|int|5|Amount of links to return | ||
-g|--google|-|False|If exists | ||
-s|--sites|comma-sep list| stackoverflow.com| sites to check for using google.com | ||
|
||
And have fun. | ||
|
||
## FOSS | ||
$ how -n 10 -s youtube.com,stackoverflow.com,example.com exit vi | ||
|
||
Results from youtube.com: | ||
➜ ... | ||
➜ ... | ||
|
||
Results from stackoverflow.com: | ||
➜ ... | ||
➜ ... | ||
|
||
Results from example.com: | ||
None found. | ||
If a discrepency is found ➜ contact the team at [email protected]. | ||
|
||
[`googlesearch-python`](https://pypi.org/project/googlesearch-python/) - A Python library for scraping the Google search engine. | ||
## FOSS | ||
|
||
[`googlesearch-python`](https://pypi.org/project/googlesearch-python/) - "A Python library for scraping the Google search engine." | ||
|
||
|
||
## Community | ||
|
@@ -64,10 +80,8 @@ After all, it is only when we ask questions that we can learn anything. | |
Contributions are more than welcome, maintainers are always invited, and if you can ask questions you're a VIP. | ||
|
||
## Contributors | ||
>[![](https://github.com/ronnathaniel.png?size=50)](https://github.com/ronnathaniel) Ron Nathaniel | ||
>[![](https://github.com/itaybachar.png?size=50)](https://github.com/itaybachar) Itay Bachar | ||
|
||
[![](https://github.com/ronnathaniel.png?size=50)](https://github.com/ronnathaniel) [![](https://github.com/itaybachar.png?size=50)](https://github.com/itaybachar) | ||
## Copyright | ||
|
||
MIT License. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,34 @@ | ||
|
||
""" | ||
Ask More Questions. | ||
Author: Ron Nathaniel | ||
Author: Ron Nathaniel, Itay Bachar | ||
""" | ||
|
||
from how.cli import parse_args, display_results | ||
from how.util import gen_next_n | ||
from how.crawler import ask_any, ask_sof, ask_google | ||
|
||
|
||
def run(): | ||
args = parse_args() | ||
|
||
query = args.get('query', '') | ||
query = ' '.join(query) | ||
|
||
n = args.get('n') | ||
g = args.get('g') | ||
sites = args.get('sites') | ||
results = [] | ||
|
||
if not sites: | ||
results = ask_google(query,limit=n) if g else ask_sof(query, limit=n) | ||
display_results(results) | ||
else: | ||
if sites: | ||
for site in sites: | ||
results = ask_any(query,limit=n,site=site) | ||
print() | ||
display_results(results,site) | ||
results = ask_any(query, limit=n, site=site) | ||
display_results(results, site) | ||
elif g: | ||
results = ask_google(query, limit=n) | ||
display_results(results, 'google.com') | ||
else: | ||
results = ask_sof(query, limit=n) | ||
display_results(results, 'stackoverflow.com') | ||
|
||
|
||
if __name__ == '__main__': | ||
run() | ||
run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
|
||
""" | ||
Ask More Questions. | ||
Author: Ron Nathaniel | ||
Author: Ron Nathaniel, Itay Bachar | ||
""" | ||
|
||
import sys | ||
from enum import Enum | ||
import argparse | ||
import colorama | ||
|
||
|
@@ -18,27 +19,40 @@ | |
'nargs': '+', | ||
'help': 'Query to Search', | ||
}, | ||
('-n',): { | ||
('-n', '--num'): { | ||
'type': int, | ||
'metavar': 'n', | ||
'nargs': '?', | ||
'help': 'Query to Search', | ||
'default': 5, | ||
}, | ||
('-g','--google'): { | ||
('-g', '--google'): { | ||
'action': 'store_true', | ||
'help': 'Search on Google', | ||
}, | ||
('-a','--add-sites'): | ||
{ | ||
('-s', '--sites'): { | ||
'type': str, | ||
'nargs': 1, | ||
'help': 'Search different websites, this will not include stack overflow unless specified.', | ||
'help': 'Sites to search from', | ||
'metavar': 'url[,url,...]', | ||
}, | ||
} | ||
|
||
|
||
class ConsoleStyles(str, Enum): | ||
RIGHT_ARROW = u'\u279c' | ||
YELLOW = u'\033[1;33m' | ||
BLUE_LIGHT = u'\033[1;36m' | ||
TEST = u'\033[1;38m' | ||
PURPLE = u'\033[1;35m' | ||
BLUE_DARK = u'\033[1;34m' | ||
GREEN = u'\033[1;32m' | ||
RED = u'\033[1;31m' | ||
BOLD = u'\033[1m' | ||
UNDERLINE = u'\033[4m' | ||
END = u'\033[0m' | ||
|
||
|
||
def parse_args() -> dict: | ||
parser = argparse.ArgumentParser(description='how') | ||
for op, kwargs in ARGS.items(): | ||
|
@@ -47,13 +61,13 @@ def parse_args() -> dict: | |
args_parsed = vars(parser.parse_args()) | ||
|
||
query = args_parsed.get('query', []) | ||
n = args_parsed.get('n', 5) | ||
g = args_parsed.get('google',False) | ||
sites = args_parsed.get('add_sites') | ||
n = args_parsed.get('num', 5) | ||
g = args_parsed.get('google', False) | ||
|
||
#Process Sites | ||
if sites and len(sites)>0: | ||
sites = list(filter(lambda s: s != '',sites[0].split(','))) | ||
sites = args_parsed.get('sites', ['']) | ||
if sites: | ||
sites = sites[0] | ||
sites = sites.split(',') | ||
|
||
return { | ||
'query': query, | ||
|
@@ -63,9 +77,12 @@ def parse_args() -> dict: | |
} | ||
|
||
|
||
def display_results(res: list,header:str = None) -> None: | ||
def display_results(res: list = None, header: str = None) -> None: | ||
if header: | ||
print(u'\033[4m' + "Results from {0}".format(header) + u'\033[0m') | ||
print('\n' + "Results from " + ConsoleStyles.YELLOW + header + ConsoleStyles.END + ':' + ConsoleStyles.END) | ||
for r in res: | ||
print(u'\u279c' + '\r\t', end='') | ||
print(ConsoleStyles.RIGHT_ARROW + '\r\t', end='') | ||
print(r) | ||
if not res: | ||
print('None found.') | ||
print(ConsoleStyles.RED + 'If a discrepency is found ' + ConsoleStyles.RIGHT_ARROW + ' contact the team at [email protected].' + ConsoleStyles.END) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters