Skip to content

Instantly share code, notes, and snippets.

@miltonlab
Last active July 21, 2021 03:47
Show Gist options
  • Save miltonlab/11236095 to your computer and use it in GitHub Desktop.
Save miltonlab/11236095 to your computer and use it in GitHub Desktop.
Generador de direcciones de correo electrónico a partir de nombres y apellidos
# -*- coding: utf-8 -*-
"""
@file : gen_emails.py
@author : Milton Labanda
@date : 24-04-2014
@description: : Un Generador de nombres de usuario para emails a partir de nombres y apellidos
"""
import itertools
import unicodedata
def gen_email(firstname, lastname, dominio='email.com'):
# Cambiando a ASCII
firstname = unicodedata.normalize('NFKD', unicode(firstname))
firstname = firstname.encode('ascii', 'ignore').lower()
lastname = unicodedata.normalize('NFKD', unicode(lastname))
lastname = lastname.encode('ascii', 'ignore').lower()
firstnames = firstname.split()
lastnames = lastname.split()
# Combinaciones finitas de nombres y apellidos
g = ('%s@%s' % ('.'.join(l), dominio) for l in (
[firstnames[0]] + [lastnames[0]],
firstnames + [lastnames[0]],
[firstnames[0]] + lastnames,
firstnames + lastnames
)
)
for i in g:
yield i
# Combinaciones con numeros
g2 = ('%s.%s.%s@%s' % (firstnames[0], lastnames[0], i+1, dominio)
for i in itertools.count())
for i2 in g2:
yield i2
# Run example:
# In [12]: h=gen_emails.gen_email('juan carlos', 'perez torres', 'unl.edu.ec')
# In [13]: h.next(); h.next(); h.next(); h.next(); h.next(); h.next()
# Out[13]: 'juan.perez@unl.edu.ec'
# Out[13]: 'juan.carlos.perez@unl.edu.ec'
# Out[13]: 'juan.perez.torres@unl.edu.ec'
# Out[13]: 'juan.carlos.perez.torres@unl.edu.ec'
# Out[13]: 'juan.perez.0@unl.edu.ec'
# Out[13]: 'juan.perez.1@unl.edu.ec'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment