Created
April 11, 2021 15:15
-
-
Save dpricha89/30693cbe15435e840e0eefd7026f4128 to your computer and use it in GitHub Desktop.
Generate large file of log lines
This file contains hidden or 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
import string | |
import random | |
import os | |
class HashGenerator: | |
def __init__(self, length): | |
print(dir(string)) | |
self.characters = string.ascii_letters + string.digits | |
self.length = length | |
def nextKey(self, l, k=''): | |
if len(k) == l: | |
yield k | |
elif len(k) < l: | |
for char in self.characters: | |
for key in self.nextKey(l, k + char): | |
yield key | |
def gen(self, filename): | |
with open(filename, 'a+')\ | |
as hash_file: | |
keys = 0 | |
for key in self.nextKey(self.length): | |
for _ in range(random.randint(1, 6)): | |
keys += 1 | |
hash_file.write(key + '\n') | |
print('keys generated', keys) | |
generator = HashGenerator(3) | |
while os.stat('/Users/drichards/grabbag/test_mocking.py/hash_keys.txt').st_size < 8189988000: | |
print('current size', os.stat( | |
'/Users/drichards/grabbag/test_mocking.py/hash_keys.txt').st_size) | |
generator.gen('/Users/drichards/grabbag/test_mocking.py/hash_keys.txt') | |
while os.stat('/Users/drichards/grabbag/test_mocking.py/hash_keys_small.txt').st_size < 89988000: | |
print('current size', os.stat( | |
'/Users/drichards/grabbag/test_mocking.py/hash_keys_small.txt').st_size) | |
generator.gen('/Users/drichards/grabbag/test_mocking.py/hash_keys_small.txt') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment