Skip to content

Instantly share code, notes, and snippets.

@indrora
Created March 26, 2015 08:18
Show Gist options
  • Save indrora/2e2f67936cbb2dd85fc7 to your computer and use it in GitHub Desktop.
Save indrora/2e2f67936cbb2dd85fc7 to your computer and use it in GitHub Desktop.
Rolotext: like a rolodex, but for a text file. Spinnnnn. Works with xscreensaver.
#!/usr/bin/env python3
# Placed under WTFPL. Get out of my face.
# usage:
# rolotext.py <textfile>
#
# Reads a file, starting from a random point in the file.
# Simulates a dilout connection as well, by having a varied
# character printout.
# Eats a little entropy.
import sys
import random
import time
if len(sys.argv) != 2:
print("I take one argument.")
sys.exit(1)
# Read the input file.
ff = open(sys.argv[1], "r")
lines = ff.readlines()
ff.close()
now = random.randint(0, len(lines)-1)
end = now-1
if(end < 0 ):
end = 0
now = 1
while now != end:
line = lines[now]
sys.stdout.write(line)
now = ( now + 1 ) % (len(lines))
sys.stdout.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment