Sunday, January 19, 2014

modemspeed.py - See things at 300 baud again!

Sometimes, you just yearn to see things the way they looked online in 1985, you know?  Maybe you don't.  But in case you get into an argument with someone over whether that modem video you posted "looks more like 110 baud than 300 baud" you can whip out this little python script and pipe some unix commands through it to relive the glory days.  When men were men and online-p0rn was ASCII ART.



#!/usr/bin/python2.7

import sys
from time import sleep

def modem(text, speed):
  # Assume speed is in bits/sec, and we're running at 8,N,1
  # So, 10 bits per character.  (1 start, 8 char, 1 stop)
  delay = 1.0 / (speed / 10)  # = seconds per character
  for char in text:
    sys.stdout.write(char)
    sys.stdout.flush()
    sleep(delay)

if __name__ == "__main__":
  if len(sys.argv) > 1:
    baud = int(sys.argv[1])
  else:
    baud = 300
  for ln in sys.stdin:
    modem(ln, baud)