Created
August 6, 2014 07:58
-
-
Save Zolomon/f5d0c768084d8a345522 to your computer and use it in GitHub Desktop.
Simulate some terminal output
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 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() |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use
$ python3 repeater.py ~/output.txt 0.05 1.5