initial commit

This commit is contained in:
luxick
2015-07-23 21:19:56 +02:00
commit 3aed036132
12 changed files with 94515 additions and 0 deletions

45
names/__init__.py Normal file
View File

@@ -0,0 +1,45 @@
from __future__ import unicode_literals
from os.path import abspath, join, dirname
import random
__title__ = 'names'
__version__ = '0.3.0.post1'
__author__ = 'Trey Hunner'
__license__ = 'MIT'
full_path = lambda filename: abspath(join(dirname(__file__), filename))
FILES = {
'first:male': full_path('dist.male.first'),
'first:female': full_path('dist.female.first'),
'last': full_path('dist.all.last'),
}
def get_name(filename):
selected = random.random() * 90
with open(filename) as name_file:
for line in name_file:
name, _, cummulative, _ = line.split()
if float(cummulative) > selected:
return name
return "" # Return empty string if file is empty
def get_first_name(gender=None):
if gender is None:
gender = random.choice(('male', 'female'))
if gender not in ('male', 'female'):
raise ValueError("Only 'male' and 'female' are supported as gender")
return get_name(FILES['first:%s' % gender]).capitalize()
def get_last_name():
return get_name(FILES['last']).capitalize()
def get_full_name(gender=None):
return "{0} {1}".format(get_first_name(gender), get_last_name())

BIN
names/__init__.pyc Normal file

Binary file not shown.

88799
names/dist.all.last Normal file

File diff suppressed because it is too large Load Diff

4275
names/dist.female.first Normal file

File diff suppressed because it is too large Load Diff

1219
names/dist.male.first Normal file

File diff suppressed because it is too large Load Diff

10
names/main.py Normal file
View File

@@ -0,0 +1,10 @@
from __future__ import print_function
from names import get_full_name
def main():
print(get_full_name())
if __name__ == "__main__":
main()