Projects STRLCPY maigret Commits b5db3f00
🤬
  • Added search wizard script as an API usage example

  • Loading...
  • Soxoj committed 4 years ago
    b5db3f00
    1 parent 53d698bb
  • ■ ■ ■ ■ ■
    maigret/__init__.py
    1 1  """Maigret"""
    2 2   
    3 3  from .checking import maigret as search
    4  - 
     4 +from .sites import MaigretEngine, MaigretSite, MaigretDatabase
     5 +from .notify import QueryNotifyPrint as Notifier
  • ■ ■ ■ ■ ■ ■
    maigret/result.py
    skipped 83 lines
    84 84   'tags': self.tags,
    85 85   }
    86 86   
     87 + def is_found(self):
     88 + return self.status == QueryStatus.CLAIMED
     89 + 
    87 90   def __str__(self):
    88 91   """Convert Object To String.
    89 92   
    skipped 14 lines
  • ■ ■ ■ ■
    maigret.py
    1  -#! /usr/bin/env python3
     1 +#!/usr/bin/env python3
    2 2  import asyncio
    3 3  import sys
    4 4   
    skipped 14 lines
  • ■ ■ ■ ■ ■ ■
    wizard.py
     1 +#!/usr/bin/env python3
     2 +import asyncio
     3 +import logging
     4 +import maigret
     5 + 
     6 + 
     7 +# top popular sites from the Maigret database
     8 +TOP_SITES_COUNT = 300
     9 +# Maigret HTTP requests timeout
     10 +TIMEOUT = 10
     11 +# max parallel requests
     12 +MAX_CONNECTIONS = 50
     13 + 
     14 + 
     15 +if __name__ == '__main__':
     16 + # setup logging and asyncio
     17 + logger = logging.getLogger('maigret')
     18 + logger.setLevel(logging.WARNING)
     19 + loop = asyncio.get_event_loop()
     20 + 
     21 + # setup Maigret
     22 + 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 + 
     26 + # user input
     27 + username = input('Enter username to search: ')
     28 + 
     29 + sites_count_raw = input(f'Select the number of sites to search ({TOP_SITES_COUNT} for default, {len(db.sites_dict)} max): ')
     30 + sites_count = int(sites_count_raw) or TOP_SITES_COUNT
     31 + 
     32 + sites = db.ranked_sites_dict(top=sites_count)
     33 + 
     34 + show_progressbar_raw = input('Do you want to show a progressbar? [Yn] ')
     35 + show_progressbar = show_progressbar_raw.lower() != 'n'
     36 + 
     37 + extract_info_raw = input('Do you want to extract additional info from accounts\' pages? [Yn] ')
     38 + extract_info = extract_info_raw.lower() != 'n'
     39 + 
     40 + use_notifier_raw = input('Do you want to use notifier for displaying results while searching? [Yn] ')
     41 + use_notifier = use_notifier_raw.lower() != 'n'
     42 + 
     43 + notifier = None
     44 + if use_notifier:
     45 + notifier = maigret.Notifier(print_found_only=True, skip_check_errors=True)
     46 + 
     47 + # search!
     48 + search_func = maigret.search(username=username,
     49 + site_dict=sites,
     50 + timeout=TIMEOUT,
     51 + logger=logger,
     52 + max_connections=MAX_CONNECTIONS,
     53 + query_notify=notifier,
     54 + no_progressbar=(not show_progressbar),
     55 + is_parsing_enabled=extract_info,
     56 + )
     57 + 
     58 + results = loop.run_until_complete(search_func)
     59 + 
     60 + input('Search completed. Press any key to show results.')
     61 + 
     62 + for sitename, data in results.items():
     63 + is_found = data['status'].is_found()
     64 + print(f'{sitename} - {"Found!" if is_found else "Not found"}')
     65 + 
Please wait...
Page is in error, reload to recover