Skip to content

Instantly share code, notes, and snippets.

@se7enack
Created February 10, 2025 22:15
Show Gist options
  • Select an option

  • Save se7enack/1da58c8abf6caae726f672d0ad59496a to your computer and use it in GitHub Desktop.

Select an option

Save se7enack/1da58c8abf6caae726f672d0ad59496a to your computer and use it in GitHub Desktop.

Revisions

  1. se7enack created this gist Feb 10, 2025.
    50 changes: 50 additions & 0 deletions py-trivia.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,50 @@
    #!/usr/bin/env python3

    import csv
    from random import randrange
    import time
    import pyttsx3


    def countdown(t):
    while t:
    mins, secs = divmod(t, 60)
    timer = '{:02d}:{:02d}'.format(mins, secs)
    print(timer, end="\r")
    time.sleep(1)
    t -= 1


    def game():
    rowz = 0
    rowcount = 0
    for row in open("trivia.csv"):
    rowcount += 1
    with open("trivia.csv", "r") as f:
    reader = csv.reader(f)
    header = next(reader)
    for row in reader:
    z = len(row[0])
    if rowz == randrange(rowcount):
    return row


    count = 0
    while count <= 5:
    x = None
    while x is None:
    try:
    engine = pyttsx3.init(driverName='nsss')
    x = game()
    print(f"\n\n{x[0]}")
    engine.say(x[0])
    engine.runAndWait()
    countdown(int(7))
    print(f"{x[1]}\n")
    engine.say(x[1])
    engine.runAndWait()
    count += 1
    time.sleep(2)
    except:
    pass

    6,207 changes: 6,207 additions & 0 deletions trivia.csv
    6,207 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.