-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
53 lines (43 loc) · 1.6 KB
/
main.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
from generator import Generator #import the Generator class made before this
import pandas as pd
import sys
import os
"""
To run this file, put in the two required parameters [filename] and [target file size] as the 1st and 2nd argument.
"""
generator = Generator()
filename = sys.argv[1] + '.txt'
target_size = float(sys.argv[2])
generator.generate_file(filename, target_size)
def checkElement(string):
"""This function checks whether a string is an Integer, an Alphabetical String, an Alphanumerical String, or a Real Numbner."""
def isAlphaNumeric(input_string):
spaces_flag = False
if input_string.count(' ') <= 20:
spaces_flag = True
return input_string.strip().isalnum() and spaces_flag
def isAlphabet(input_string):
return input_string.strip().isalpha()
def isReal(input_string):
if "." not in input_string.strip():
return False
else:
return True
def isInteger(input_string):
try:
int(input_string.strip())
return True
except ValueError:
return False
if isInteger(string):
print(string + ' - ' + 'integer')
elif isAlphabet(string):
print(string + ' - ' + 'alphabetical strings')
elif isAlphaNumeric(string):
print(string + ' - ' + 'alphanumeric')
elif isReal(string):
print(string + ' - ' + 'real numbers')
df = pd.read_csv(sys.argv[1]+ '.txt', header=None, dtype=str)
filesize = os.stat(filename).st_size
df.applymap(checkElement)
print('Generated ' + filename + ' of size ' + str(filesize/1000000) +'MB')