-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathrandom_names.py
142 lines (103 loc) · 3.07 KB
/
random_names.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#! python3
# -*- coding: utf-8 -*-
import random
import string
from os.path import dirname, join
script_dir = dirname(__file__)
names_dir = join(script_dir, 'Names')
FirstNames = join(names_dir, 'FirstNames.txt')
MiddleNames = join(names_dir, 'MiddleNames.txt')
LastNames = join(names_dir, 'LastNames.txt')
CountyNames = join(names_dir, 'CountyNames.txt')
PlaceNames = join(names_dir, 'PlaceNames.txt')
StateNames = join(names_dir, 'StateNames.txt')
CountryNames = join(names_dir, 'CountryNames.txt')
CompanyNames = join(names_dir, 'CompanyNames.txt')
def Number(start=0, end=100000):
"""
Returns random integer between range of numbers
"""
return random.randint(start, end)
def UpperChars(NoOfChars=2):
"""
UpperChars(NoOfChars=2) Returns 2 random CAPITAL letters.
"""
_char = ''
for num in range(NoOfChars):
_char += random.choice(string.ascii_uppercase)
return _char
def rawCount(filename):
"""
Function to get Line Count in txt files.
rawcount('C:\A.txt') outputs integer value of count of lines.
"""
with open(filename, 'rb') as f:
lines = 1
buf_size = 1024 * 1024
read_f = f.raw.read
buf = read_f(buf_size)
while buf:
lines += buf.count(b'\n')
buf = read_f(buf_size)
return lines
def randomLine(filename):
"""
Read the given text file and return a random line
"""
num = int(random.uniform(0, rawCount(filename)))
with open(filename, 'r', encoding="UTF-8") as f:
for i, line in enumerate(f, 1):
if i == num:
break
return line.strip('\n')
def First():
return randomLine(FirstNames)
def Last():
return randomLine(LastNames)
def Middle():
return randomLine(MiddleNames)
def States():
return randomLine(StateNames)
def Places():
return randomLine(PlaceNames)
def County():
return randomLine(CountyNames)
def Company():
return randomLine(CompanyNames)
def Country():
_Cc = randomLine(CountryNames)
_Cc = _Cc.split('|')
return _Cc[1]
def CountryCode():
_Cc = randomLine(CountryNames)
_Cc = _Cc.split('|')
return _Cc[0]
def StateCode():
return States().split(', ')[1]
def Full():
"""
Returns a random First Name and Last Name combination
"""
return ' '.join([First(), Last()])
def Address():
"""
Returns a Random address in the Format:
54F - Sauk, Middle, New Mexico, NM, 4292.
"""
_door = str(Number(11, 99))
_zip = str(Number(1000, 9999))
_adrs = ', '.join([Places(), County(), States(), _zip])
_adrs = _door + UpperChars(1) + ' - ' + _adrs + '.'
return _adrs
def ShortAddress():
"""
Returns a Short Random address in the Format:
31 Outagamie, Wisconsin, WI, 8281
"""
_door = str(Number(11, 99))
_zip = str(Number(1000, 9999))
_adrs = ', '.join([County(), States(), _zip])
_adrs = _door + ' ' + _adrs
return _adrs
if __name__ == '__main__':
print(Full(), ' works at ', Company(), ' lives at ', Address(), StateCode(), Country())