0

I am working on a project/installation that will be run on a 7" screen. At the moment the project selects a sentence from a txt file and then prints it out using a 'typewriter effect'. I am doing this using the command line on a raspberry pi (console login ctrl-alt-f1 not LXTerminal)

Using textwrapper the sentence will split over as many lines needed.


#Loop 
while True:

    #ntlk tokenizer
    tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')

    #my code takes text file
    forTweet = text  

    #breaks into sentences 
    tok = tokenizer.tokenize(forTweet); 

    #selects random sentence 
    newTok = random.choice(tok) 

    #makes sure sentence is less than 280 characters 
    newTok = random.choice([x for x in tok if len(x)<280])

    #text wrap to make sure words do not split on 
    str2 = textwrap.fill(newTok, 128)

    #Gets length of newTOk  
    lenghtnewTok = len(newTok) 

    #Keeps text on screen for 5 seoncds 
    sleep(5)

    # initialise clearing screen  
    stdscr = curses.initscr()  
    # Clear the screen
    stdscr.clear()  
    #keep screen clear for 2 seconds
    sleep(2)

    #This is typewrite effect 
    words = str2.replace('\n', '\r\n')
    for char in words:
        sleep(0.1)
        sys.stdout.write(char)
        sys.stdout.flush()

However, what I would now like to acheive is that instead of printing 1 sentence, the script will:

1.select one sentence, print using typewriter effect.

2.Wait two seconds, skip a line and then print another sentence.

3.Keep doing this until it reaches bottom of screen and then clear all sentences and start again from the top.

Any suggestions would be great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.