new scripts

This commit is contained in:
2021-03-24 11:50:44 -04:00
parent 2af3e608f7
commit 1a2773ac76
5 changed files with 62 additions and 18 deletions

View File

@@ -2,13 +2,23 @@ import sys
from random import randint
check_start = False
start = ''
prefix = ''
num = 1
if len(sys.argv) == 1:
print("ERROR: Please include a filename")
print("Usage: frand <FILENAME> [<INCLUDES>] [n=<NUM>]")
sys.exit(0)
fn = sys.argv[1]
if len(sys.argv) > 2:
start = sys.argv[2]
check_start = True
for i in range(2, len(sys.argv)):
if sys.argv[i].startswith("n="):
num = int(sys.argv[i][2:])
else:
prefix = sys.argv[i]
check_start = True
lines = []
with open(fn) as f:
@@ -16,15 +26,16 @@ with open(fn) as f:
nline = line.replace("\n", "")
lines.append(nline)
if check_start:
line_sub = []
for i in lines:
if i.startswith(start):
line_sub.append(i)
numitems = len(line_sub)
i = randint(0,numitems-1)
print(line_sub[i])
else:
numitems = len(lines)
i = randint(0,numitems-1)
print(lines[i])
for x in range(0, num):
if check_start:
line_sub = []
for i in lines:
if i.startswith(prefix):
line_sub.append(i)
numitems = len(line_sub)
i = randint(0,numitems-1)
print(line_sub[i])
else:
numitems = len(lines)
i = randint(0,numitems-1)
print(lines[i])