| skipped 804 lines |
805 | 805 | | if args.top_sites == 0 or args.all_sites: |
806 | 806 | | args.top_sites = sys.maxsize |
807 | 807 | | |
| 808 | + | # Create notify object for query results. |
| 809 | + | query_notify = QueryNotifyPrint(result=None, |
| 810 | + | verbose=args.verbose, |
| 811 | + | print_found_only=not args.print_not_found, |
| 812 | + | skip_check_errors=not args.print_check_errors, |
| 813 | + | color=not args.no_color) |
| 814 | + | |
808 | 815 | | # Create object with all information about sites we are aware of. |
809 | | - | try: |
810 | | - | db = MaigretDatabase().load_from_file(args.json_file) |
811 | | - | site_data = db.ranked_sites_dict(top=args.top_sites, tags=args.tags, names=args.site_list) |
812 | | - | except Exception as error: |
813 | | - | print(f"ERROR: {error}") |
814 | | - | sys.exit(1) |
| 816 | + | db = MaigretDatabase().load_from_file(args.json_file) |
| 817 | + | get_top_sites_for_id = lambda x: db.ranked_sites_dict(top=args.top_sites, tags=args.tags, |
| 818 | + | names=args.site_list, |
| 819 | + | disabled=False, id_type=x) |
| 820 | + | |
| 821 | + | site_data = get_top_sites_for_id(args.id_type) |
815 | 822 | | |
816 | 823 | | # Database self-checking |
817 | 824 | | if args.self_check: |
| skipped 14 lines |
832 | 839 | | # Define one report filename template |
833 | 840 | | report_filepath_tpl = os.path.join(args.folderoutput, 'report_{username}{postfix}') |
834 | 841 | | |
835 | | - | # Database consistency |
836 | | - | enabled_count = len(list(filter(lambda x: not x.disabled, site_data.values()))) |
837 | | - | print(f'Sites in database, enabled/total: {enabled_count}/{len(site_data)}') |
838 | | - | |
839 | | - | if not enabled_count: |
840 | | - | print('No sites to check, exiting!') |
841 | | - | sys.exit(2) |
| 842 | + | # Database stats |
| 843 | + | # TODO: verbose info about filtered sites |
| 844 | + | # enabled_count = len(list(filter(lambda x: not x.disabled, site_data.values()))) |
| 845 | + | # print(f'Sites in database, enabled/total: {enabled_count}/{len(site_data)}') |
842 | 846 | | |
843 | | - | if usernames == ['-']: |
| 847 | + | if usernames == {}: |
844 | 848 | | # magic params to exit after init |
845 | | - | print('No usernames to check, exiting.') |
| 849 | + | query_notify.warning('No usernames to check, exiting.') |
846 | 850 | | sys.exit(0) |
847 | 851 | | |
848 | | - | # Create notify object for query results. |
849 | | - | query_notify = QueryNotifyPrint(result=None, |
850 | | - | verbose=args.verbose, |
851 | | - | print_found_only=not args.print_not_found, |
852 | | - | skip_check_errors=not args.print_check_errors, |
853 | | - | color=not args.no_color) |
| 852 | + | if not site_data: |
| 853 | + | query_notify.warning('No sites to check, exiting!') |
| 854 | + | sys.exit(2) |
| 855 | + | else: |
| 856 | + | query_notify.warning(f'Starting a search on top {len(site_data)} sites from the Maigret database...') |
| 857 | + | if not args.all_sites: |
| 858 | + | query_notify.warning(f'You can run search by full list of sites with flag `-a`', '!') |
854 | 859 | | |
855 | 860 | | already_checked = set() |
856 | | - | |
857 | 861 | | general_results = [] |
858 | 862 | | |
859 | 863 | | while usernames: |
| skipped 10 lines |
870 | 874 | | |
871 | 875 | | if found_unsupported_chars: |
872 | 876 | | pretty_chars_str = ','.join(map(lambda s: f'"{s}"', found_unsupported_chars)) |
873 | | - | print(f'Found unsupported URL characters: {pretty_chars_str}, skip search by username "{username}"') |
| 877 | + | query_notify.warning(f'Found unsupported URL characters: {pretty_chars_str}, skip search by username "{username}"') |
874 | 878 | | continue |
875 | 879 | | |
| 880 | + | sites_to_check = get_top_sites_for_id(id_type) |
| 881 | + | |
876 | 882 | | results = await maigret(username, |
877 | | - | dict(site_data), |
| 883 | + | dict(sites_to_check), |
878 | 884 | | query_notify, |
879 | 885 | | proxy=args.proxy, |
880 | 886 | | timeout=args.timeout, |
| skipped 24 lines |
905 | 911 | | if args.xmind: |
906 | 912 | | filename = report_filepath_tpl.format(username=username, postfix='.xmind') |
907 | 913 | | save_xmind_report(filename, username, results) |
908 | | - | print(f'XMind report for {username} saved in {filename}') |
| 914 | + | query_notify.warning(f'XMind report for {username} saved in {filename}') |
909 | 915 | | |
910 | 916 | | if args.csv: |
911 | 917 | | filename = report_filepath_tpl.format(username=username, postfix='.csv') |
912 | 918 | | save_csv_report(filename, username, results) |
913 | | - | print(f'CSV report for {username} saved in {filename}') |
| 919 | + | query_notify.warning(f'CSV report for {username} saved in {filename}') |
914 | 920 | | |
915 | 921 | | if args.txt: |
916 | 922 | | filename = report_filepath_tpl.format(username=username, postfix='.txt') |
917 | 923 | | save_txt_report(filename, username, results) |
918 | | - | print(f'TXT report for {username} saved in {filename}') |
| 924 | + | query_notify.warning(f'TXT report for {username} saved in {filename}') |
919 | 925 | | |
920 | 926 | | # reporting for all the result |
921 | 927 | | if general_results: |
922 | 928 | | if args.html or args.pdf: |
923 | | - | print('Generating report info...') |
| 929 | + | query_notify.warning('Generating report info...') |
924 | 930 | | report_context = generate_report_context(general_results) |
925 | 931 | | # determine main username |
926 | 932 | | username = report_context['username'] |
| skipped 1 lines |
928 | 934 | | if args.html: |
929 | 935 | | filename = report_filepath_tpl.format(username=username, postfix='.html') |
930 | 936 | | save_html_report(filename, report_context) |
931 | | - | print(f'HTML report on all usernames saved in {filename}') |
| 937 | + | query_notify.warning(f'HTML report on all usernames saved in {filename}') |
932 | 938 | | |
933 | 939 | | if args.pdf: |
934 | 940 | | filename = report_filepath_tpl.format(username=username, postfix='.pdf') |
935 | 941 | | save_pdf_report(filename, report_context) |
936 | | - | print(f'PDF report on all usernames saved in {filename}') |
| 942 | + | query_notify.warning(f'PDF report on all usernames saved in {filename}') |
937 | 943 | | # update database |
938 | 944 | | db.save_to_file(args.json_file) |
939 | 945 | | |
| skipped 11 lines |