import os
import random
import time

with open("11-0.txt") as gutenberg_alice_in_wonderland:
    alice = gutenberg_alice_in_wonderland.read()

def alice_segment():
    minimum_segment_length = 50
    maximum_segment_length = 250
    end_of_segment = random.randint(maximum_segment_length,
                                    len(alice)-1)
    # i'm not sure if it needs the -1 but i didn't want to
    # fall off the end :P
    length_of_segment = random.randint(minimum_segment_length,
                                       maximum_segment_length)
    beginning_of_segment = end_of_segment - length_of_segment
    return alice[beginning_of_segment:end_of_segment]

while(1):
    new_segment = alice_segment()
    print("\n\n")
    print(new_segment)
    with open("segment_to_transmit", "w") as outfile:
        outfile.write(new_segment)
    os.system("cat segment_to_transmit | bsocial-cli -p alice-again")
    time.sleep(3600)
