Created
June 4, 2015 08:48
-
-
Save RaD/e4c0c1ecb94b7571dd4d to your computer and use it in GitHub Desktop.
Sends the file to STDOUT in a line by line manner.
This file contains 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 time | |
import sys | |
def read_by_line(input, delay, is_recourse): | |
while True: | |
input.seek(0) | |
for line in input: | |
sys.stdout.write(line) | |
time.sleep(delay/1000.0) | |
if not is_recourse: | |
break | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='Sends a given file to stdout in per line manner.') | |
parser.add_argument('-r', action='store_true', default=False, dest='is_recourse', | |
help='send the file lines again and again.') | |
parser.add_argument('-d', action='store', default=250, dest='delay', type=int, | |
help='delay in milliseconds, by default 250ms.') | |
parser.add_argument('input', type=file, help='source file') | |
args = parser.parse_args() | |
try: | |
read_by_line(args.input, args.delay, args.is_recourse) | |
except KeyboardInterrupt: | |
pass | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment