-
Notifications
You must be signed in to change notification settings - Fork 36
/
main.py
62 lines (54 loc) · 1.27 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import click
from searchor import Engine
import searchor.history
@click.group()
def cli():
pass
@cli.command()
@click.option(
"-o",
"--open",
is_flag=True,
default=False,
show_default=True,
help="Opens your web browser to the generated link address",
)
@click.option(
"-c",
"--copy",
is_flag=True,
default=False,
show_default=True,
help="Copies the generated link address to your clipboard",
)
@click.argument("engine")
@click.argument("query")
def search(engine, query, open, copy):
try:
url = eval(
f"Engine.{engine}.search('{query}', copy_url={copy}, open_web={open})"
)
click.echo(url)
searchor.history.update(engine, query, url)
if open:
click.echo("opening browser...")
if copy:
click.echo("link copied to clipboard")
except AttributeError:
print("engine not recognized")
@cli.command()
@click.option(
"-c",
"--clear",
is_flag=True,
default=False,
show_default=True,
help="clears the search history",
)
def history(clear):
if clear:
searchor.history.clear()
else:
searchor.history.view()
if __name__ == "__main__":
cli()