1st commit

This commit is contained in:
Harvey Tindall 2015-07-06 00:20:42 +09:00
commit 4e298d749d
2 changed files with 53 additions and 0 deletions

9
README.md Normal file
View File

@ -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 <input file> --speed <1 - 5>
```

44
typeprint.py Executable file
View File

@ -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 <inputfile> --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:])