Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.