Skip to content

Instantly share code, notes, and snippets.

@Zolomon
Created August 6, 2014 07:58
Show Gist options
  • Select an option

  • Save Zolomon/f5d0c768084d8a345522 to your computer and use it in GitHub Desktop.

Select an option

Save Zolomon/f5d0c768084d8a345522 to your computer and use it in GitHub Desktop.
Simulate some terminal output
import argparse
import random
import time
class Repeater(object):
def __init__(self, filename, minTimeToNextLine, maxTimeToNextLine):
self.filename = filename
self.minTime = minTimeToNextLine
self.maxTime = maxTimeToNextLine
def run(self):
lines = open(self.filename, 'r').read()
while True:
for line in lines.split('\n'):
print(line)
sleepFor = random.uniform(self.minTime, self.maxTime)
time.sleep(sleepFor)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Simulate work")
parser.add_argument("filename", type=str, help="The file to output")
parser.add_argument("minTimeToNextLine", type=float, help="Minimum time to wait until next line is output")
parser.add_argument("maxTimeToNextLine", type=float, help="Maximum time to wait until next line is output")
result = parser.parse_args()
repeater = Repeater(result.filename, result.minTimeToNextLine, result.maxTimeToNextLine)
repeater.run()
@Zolomon
Copy link
Author

Zolomon commented Aug 6, 2014

How to use

$ python3 repeater.py ~/output.txt 0.05 1.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment