Skip to content

simple email generator #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/scripts/convert/email_generator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env python3
import sys
from pathlib import Path

__root_dir = Path(__file__).parents[4]
sys.path.append(str(__root_dir))
9 changes: 9 additions & 0 deletions src/scripts/convert/email_generator/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python3
from pprint import pprint
from sys import argv

from src.core.utils.module import run_module
from src.scripts.convert.email_generator.module import Runner

result = run_module(Runner, args=argv, arg_name="username", arg_default="john.doe")
pprint(result, compact=True)
74 changes: 74 additions & 0 deletions src/scripts/convert/email_generator/module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python3

from time import time
from pathlib import Path
from string import punctuation as dividers

from src.core.base.base import BaseRunner
from src.core.utils.response import ScriptResponse


class DefaultValues:
binders = ("-", "_", ".", "")


class EmailGenerator:
def __init__(self, domain_base: str = "settings/domain_base.txt"):
"""
:param domain_base: base of email domains written in translit as text file
"""
with open(Path(__file__).parent.joinpath(domain_base), "r") as domains:
self.__domains = domains.read().splitlines()

@staticmethod
def divide(username: str) -> list:
"""
:param username: username to generate email
:return: login's lexemes
"""
for sym in dividers:
username = username.replace(sym, " ")
return username.split()

def generate(self, username: str) -> list:
"""
:param username: username to generate email
:return: list of person's emails
"""
parts = self.divide(username.lower())
logins = []
for i in range(2):
logins.extend([sym.join(parts) for sym in DefaultValues.binders])
parts.reverse()
emails = set()
for login in logins:
for domain in self.__domains:
emails.add(f"{login}@{domain}")
return list(emails)


class Runner(BaseRunner):
def __init__(self, logger: str = __name__):
super(Runner, self).__init__(logger)

def run(self, *args, **kwargs) -> ScriptResponse.success or ScriptResponse.error:
"""
Main runner function for the script
:param args: args from core runner
:param kwargs: kwargs from core runner
:return: ScriptResponse message
"""
try:
tm = time()
email_gen = EmailGenerator()
username = kwargs.get("username")
if username is None:
raise KeyError("EmailGenerator can't work without username!")
result = email_gen.generate(username)
except Exception as err:
return ScriptResponse.error(message=str(err))
else:
return ScriptResponse.success(
result=result,
message=f"Successfully finished! Got {len(result)} logins, script lasted {(time() - tm):.2f} seconds",
)
17 changes: 17 additions & 0 deletions src/scripts/convert/email_generator/settings/domain_base.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
yandex.ru
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавить:

ya.ru
inbox.ru
list.ru
bk.ru
mail.ru

yandex.com
gmail.com
rocketmail.com
yahoo.com
outlook.com
example.com
aol.com
love.com
icloud.com
inbox.com
mail.com
ya.ru
inbox.ru
list.ru
bk.ru
mail.ru