From 4e298d749df0f012aabff95ce3657140875d3220 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 6 Jul 2015 00:20:42 +0900 Subject: [PATCH] 1st commit --- README.md | 9 +++++++++ typeprint.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 README.md create mode 100755 typeprint.py diff --git a/README.md b/README.md new file mode 100644 index 0000000..a8d0ae6 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# typeprint.py + +A terrible python script to output the contents of a file as if it were being typed by one of the l33t hack3rs you get in films. I made this because vypr's [typeprint](http://github.com/vypr/typeprint) didn't have an easy way to change the speed of output. + +# Usage + +``` +typeprint.py --ifile --speed <1 - 5> +``` diff --git a/typeprint.py b/typeprint.py new file mode 100755 index 0000000..df5c1d2 --- /dev/null +++ b/typeprint.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +import sys, time, getopt + + +def main(argv): + inputfile = '' + speed = '5' + try: + opts, args = getopt.getopt(argv,"hi:s",["ifile=", "speed="]) + except getopt.GetoptError: + print 'typeprint.py --ifile --speed <1 - 5>' + sys.exit(2) + for opt, arg in opts: + if opt in ("-i", "--ifile"): + inputfile = arg + elif opt in ("-s", "--speed"): + speed = arg + wspeed = 0 + if speed == '1': + wspeed = 0.5 + elif speed == '2': + wspeed = 0.4 + elif speed == '3': + wspeed = 0.3 + elif speed == '4': + wspeed = 0.2 + elif speed == '5': + wspeed = 0.1 + with open(inputfile, "r") as file: + while 1 == 1: + readnum = file.read(1) + time.sleep(wspeed) + sys.stdout.write(readnum) + sys.stdout.flush() + if not readnum: + sys.exit() + + + +main(sys.argv[1:]) + + +