Script for Random Name Picker Via Hotkeys

bozniauk

New Member
Hi, I am hoping that someone might be able to help.
I am using OBS as a teacher during this Lockdown, and am searching for a solution to display a random name from one of my chosen classes on my overlay (Linked to a TEXT source that I put on the overlay) when I press a hotkey. Having a number of classes, I wish to assign a hotkey to each class, so that when I press it a random name from that class will appear.
I have each class as txt files with a name on each line.

I have a python code that does the job, but I do not know how to implement it in OBS with hotkeys or assigning the result of the random pick to the TEXT source.

If anyone can help or even write me a quick piece of code, I would greatly appreciate it.

Thanks,
Ben

Python code :

import random

def SevenNMa2():

contents=[]

with open("7NMa2 Names.txt") as rnd:
for line in rnd:
line=line.strip()
contents.append(line)
print ("")
print ("")
print ("random name:", contents[random.randint(0,len(contents)-1)])
print ("")
print ("")
choice()

def TenMa6():

contents=[]

with open("10Ma6 Names.txt") as rnd:
for line in rnd:
line=line.strip()
contents.append(line)
print ("")
print ("")
print ("random name:", contents[random.randint(0,len(contents)-1)])
print ("")
print ("")
choice()

def ElevenMa4():

contents=[]

with open("11Ma4 Names.txt") as rnd:
for line in rnd:
line=line.strip()
contents.append(line)
print ("")
print ("")
print ("random name:", contents[random.randint(0,len(contents)-1)])
print ("")
print ("")
choice()


def ThirteenB():

contents=[]

with open("13B Names.txt") as rnd:
for line in rnd:
line=line.strip()
contents.append(line)
print ("")
print ("")
print ("random name:", contents[random.randint(0,len(contents)-1)])
print ("")
print ("")
choice()



def ThirteenC():

contents=[]

with open("13C Names.txt") as rnd:
for line in rnd:
line=line.strip()
contents.append(line)
print ("")
print ("")
print ("random name:", contents[random.randint(0,len(contents)-1)])
print ("")
print ("")
choice()


def ThirteenFM():

contents=[]

with open("13FM Names.txt") as rnd:
for line in rnd:
line=line.strip()
contents.append(line)
print ("")
print ("")
print ("random name:", contents[random.randint(0,len(contents)-1)])
print ("")
print ("")
choice()



def choice():
chosen= int(input("1 for 7N/Ma2, 2 for 10Ma6, 3 for 11Ma4, 4 for 13B, 5 for 13C, 6 for 13FM "))
if chosen ==1:
SevenNMa2()
if chosen ==2:
TenMa6()
if chosen ==3:
ElevenMa4()
if chosen ==4:
ThirteenB()
if chosen ==5:
ThirteenC()
if chosen ==6:
ThirteenFM()



choice()
 
Top