|
1 |
| -#!/usr/bin/env python3 |
2 | 1 | import asyncio
|
3 | 2 | import logging
|
4 | 3 | import maigret
|
5 | 4 |
|
6 | 5 |
|
7 |
| -# top popular sites from the Maigret database |
8 | 6 | TOP_SITES_COUNT = 300
|
9 |
| -# Maigret HTTP requests timeout |
10 | 7 | TIMEOUT = 10
|
11 |
| -# max parallel requests |
12 | 8 | MAX_CONNECTIONS = 50
|
13 | 9 |
|
14 | 10 |
|
15 |
| -if __name__ == '__main__': |
16 |
| - # setup logging and asyncio |
| 11 | +def main(): |
17 | 12 | logger = logging.getLogger('maigret')
|
18 | 13 | logger.setLevel(logging.WARNING)
|
19 | 14 | loop = asyncio.get_event_loop()
|
20 | 15 |
|
21 |
| - # setup Maigret |
22 | 16 | db = maigret.MaigretDatabase().load_from_file('./maigret/resources/data.json')
|
23 |
| - # also can be downloaded from web |
24 |
| - # db = MaigretDatabase().load_from_url(MAIGRET_DB_URL) |
25 | 17 |
|
26 |
| - # user input |
27 | 18 | username = input('Enter username to search: ')
|
28 |
| - |
29 |
| - sites_count_raw = input( |
| 19 | + sites_count = int(input( |
30 | 20 | f'Select the number of sites to search ({TOP_SITES_COUNT} for default, {len(db.sites_dict)} max): '
|
31 |
| - ) |
32 |
| - sites_count = int(sites_count_raw) or TOP_SITES_COUNT |
33 |
| - |
| 21 | + )) or TOP_SITES_COUNT |
34 | 22 | sites = db.ranked_sites_dict(top=sites_count)
|
35 | 23 |
|
36 |
| - show_progressbar_raw = input('Do you want to show a progressbar? [Yn] ') |
37 |
| - show_progressbar = show_progressbar_raw.lower() != 'n' |
38 |
| - |
39 |
| - extract_info_raw = input( |
| 24 | + show_progressbar = input('Do you want to show a progressbar? [Yn] ').lower() != 'n' |
| 25 | + extract_info = input( |
40 | 26 | 'Do you want to extract additional info from accounts\' pages? [Yn] '
|
41 |
| - ) |
42 |
| - extract_info = extract_info_raw.lower() != 'n' |
43 |
| - |
44 |
| - use_notifier_raw = input( |
| 27 | + ).lower() != 'n' |
| 28 | + use_notifier = input( |
45 | 29 | 'Do you want to use notifier for displaying results while searching? [Yn] '
|
46 |
| - ) |
47 |
| - use_notifier = use_notifier_raw.lower() != 'n' |
| 30 | + ).lower() != 'n' |
48 | 31 |
|
49 | 32 | notifier = None
|
50 | 33 | if use_notifier:
|
51 | 34 | notifier = maigret.Notifier(print_found_only=True, skip_check_errors=True)
|
52 | 35 |
|
53 |
| - # search! |
54 | 36 | search_func = maigret.search(
|
55 | 37 | username=username,
|
56 | 38 | site_dict=sites,
|
57 | 39 | timeout=TIMEOUT,
|
58 | 40 | logger=logger,
|
59 | 41 | max_connections=MAX_CONNECTIONS,
|
60 | 42 | query_notify=notifier,
|
61 |
| - no_progressbar=(not show_progressbar), |
| 43 | + no_progressbar=not show_progressbar, |
62 | 44 | is_parsing_enabled=extract_info,
|
63 | 45 | )
|
64 | 46 |
|
|
69 | 51 | for sitename, data in results.items():
|
70 | 52 | is_found = data['status'].is_found()
|
71 | 53 | print(f'{sitename} - {"Found!" if is_found else "Not found"}')
|
| 54 | + |
| 55 | + |
| 56 | +if __name__ == '__main__': |
| 57 | + main() |
0 commit comments