-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
ddg.py
executable file
·34 lines (27 loc) · 1.14 KB
/
ddg.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
#!/usr/bin/env python
"""DuckDuckGo URL scrapper"""
from argparse import ArgumentParser, BooleanOptionalAction
from time import time
from lib.duckduckgo import DDG
if __name__ == '__main__':
try:
start_time = time()
ARGUMENTS = ArgumentParser(description='DuckDuckGo URL scraper by 0x08')
ARGUMENTS.add_argument('keyword', metavar='keyword', type=str, help='search string')
ARGUMENTS.add_argument('-n', dest='max_results', type=int, help='number of results(default: all)')
ARGUMENTS.add_argument('-t', dest='time', action=BooleanOptionalAction,
default=False, help='execution time')
ARGUMENTS.add_argument('-o', dest='file_output', type=str, help='save output to file')
args = ARGUMENTS.parse_args()
ddg = DDG(' '.join(args.keyword), max_results=args.max_results)
search = ddg.search()
for link in sorted(search):
print(link)
if args.time:
print(f'Execution time: {time()-start_time:.2f}s')
elif args.file_output:
with open(args.file_output, mode='w', encoding='utf-8') as file_output:
file_output.write('\n'.join(sorted(search)))
file_output.write('\n')
except KeyboardInterrupt:
print('\nCtrl+C was pressed!')