-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from dmdhrumilmistry/implement-mass-check
implement async email checker
- Loading branch information
Showing
6 changed files
with
148 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,3 +184,7 @@ poetry.toml | |
|
||
# LSP config files | ||
pyrightconfig.json | ||
|
||
# breach-check data | ||
*.txt | ||
output_*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from argparse import ArgumentParser | ||
from breach_check.breach import BreachChecker | ||
from breach_check.logger import console | ||
from breach_check.utils import generate_unique_filename, extract_emails, write_json_file | ||
from asyncio import run | ||
from sys import exit | ||
|
||
|
||
def main(): | ||
parser = ArgumentParser('breach-check') | ||
parser.add_argument('-i', '--input', dest='input_file', | ||
help='input file containing emails on each line', type=str, required=True) | ||
parser.add_argument('-o', '--output', dest='output_file', | ||
help='output json file path', required=False, default=generate_unique_filename(), type=str) | ||
|
||
args = parser.parse_args() | ||
|
||
emails = extract_emails(args.input_file) | ||
|
||
if not emails: | ||
exit(-1) | ||
|
||
results = run( | ||
BreachChecker().mass_check(emails=emails) | ||
) | ||
|
||
if not write_json_file(args.output_file, results): | ||
console.print('Results:') | ||
console.print(results) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from breach_check.logger import logger | ||
from datetime import datetime | ||
from json import dumps as json_dumps, JSONDecodeError | ||
from os.path import isfile | ||
|
||
|
||
def generate_unique_filename(): | ||
current_time = datetime.now() | ||
timestamp = current_time.strftime( | ||
"%Y%m%d%H%M%S") # YearMonthDayHourMinuteSecond | ||
unique_filename = f"output_{timestamp}.json" | ||
return unique_filename | ||
|
||
|
||
def extract_emails(file_path: str) -> list[str] | None: | ||
if not isfile(file_path): | ||
logger.error(f'Input File with Emails Not Found: {file_path}') | ||
return | ||
|
||
with open(file_path, 'r') as f: | ||
emails = [email.strip() for email in f.read().splitlines()] | ||
|
||
return emails | ||
|
||
|
||
def write_json_file(file_path: str, json_data) -> bool: | ||
if isfile(file_path): | ||
logger.warning(f'{file_path} data will be overwritten') | ||
|
||
try: | ||
json_data = json_dumps(json_data) | ||
except JSONDecodeError: | ||
logger.error('Invalid JSON Data') | ||
return False | ||
except Exception as e: | ||
logger.error(f'Exception: {e}') | ||
return False | ||
|
||
with open(file_path, 'w') as f: | ||
f.write(json_data) | ||
logger.info(f'data written to {file_path} successfully') | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters