def __init__(self, port, baud_rate, terminal=None, reset=False): Connection.__init__(self, terminal) self._port = port self._baud_rate = baud_rate try: self._serial = serial.Serial(None, self._baud_rate, timeout=0, write_timeout=0.2) self._serial.dtr = False self._serial.rts = False self._serial.port = port self._serial.open() if reset: self._serial.rts = True time.sleep(0.1) self._serial.rts = False x = "" while not x.endswith(">>>"): x += self._serial.read().decode('utf-8', errors="ignore") self.send_kill() except (OSError, serial.SerialException) as e: self._serial = None return except Exception as e: return self._reader_thread = Thread(target=self._reader_thread_routine) self._reader_thread.start()
def __init__(self, host, port, terminal, password_prompt): Connection.__init__(self, terminal) self._host = host self._port = port self.s = None self.ws = None if not self._start_connection(): return if not self.handle_password(password_prompt): self._clear() raise PasswordException() self._reader_thread = Thread(target=self._reader_thread_routine) self._reader_thread.start()
def friends(): friends = Connection.friendshipRequest("friends", {}).get("friends") Common.printNotificationText(f"Friends: {len(friends)}") for friend in friends: Common.printNotificationText(friend)
def newIncomingMessages(): chatWith = programLocation.getLocationParameters().get("chatWith") while programLocation.getLocation( ) == "ChatController" and Connection.isSession(): response = Connection.chatRequest("new-incoming-messages", {"chatWith": chatWith}) if response.get("successful"): for messageSet in response.get("newIncomingMessages"): sender = messageSet.get("sender") date = messageSet.get("date") message = messageSet.get("message") Common.printChatLabelText(f"<{sender}> <{date}>: ") Common.printStandartText(message) time.sleep(.1)
def deleteAll(): response = Connection.notificationRequest("delete-all", {}) successful = response.get("successful") message = response.get("message") if successful: Common.printPositiveText(message) else: Common.printNegativeText(message)
def outgoing(): outgoing = Connection.friendshipRequest("outgoing", {}).get("outgoing") Common.printNotificationText( f"Ougoing Friendship Requests: {len(outgoing)}") for username in outgoing: Common.printNotificationText(username)
def incoming(): incoming = Connection.friendshipRequest("incoming", {}).get("incoming") Common.printNotificationText( f"Incoming Friendship Requests: {len(incoming)}") for username in incoming: Common.printNotificationText(username)
def __init__(self, host, port, terminal, password_prompt): Connection.__init__(self, terminal) self._host = host self._port = port self.s = None self.ws = None try: self._start_connection() except Exception as e: self._clear() raise e if not self.handle_password(password_prompt): self._clear() raise PasswordException() self._reader_thread = Thread(target=self._reader_thread_routine) self._reader_thread.start()
def deleteStream(): chatWith = input("Username -> ") response = Connection.chatRequest("delete-stream", {"chatWith": chatWith}) successful = response.get("successful") message = response.get("message") if successful: Common.printPositiveText(message) else: Common.printNegativeText(message)
def ignore(): username = input("Username -> ") response = Connection.friendshipRequest("ignore", {"username": username}) successful = response.get("successful") message = response.get("message") if successful: Common.printPositiveText(message) else: Common.printNegativeText(message)
def resetEmail(): email = input("Email -> ") response = Connection.profileRequest("reset-email", {"email": email}) successful = response.get("successful") message = response.get("message") if successful: Common.printPositiveText(message) else: Common.printNegativeText(message)
def resetPassword(): password = getpass("Password -> ") response = Connection.profileRequest("reset-password", {"password": password}) successful = response.get("successful") message = response.get("message") if successful: Common.printPositiveText(message) else: Common.printNegativeText(message)
def resetUsername(): username = input("Username -> ") response = Connection.profileRequest("reset-username", {"username": username}) successful = response.get("successful") message = response.get("message") if successful: Common.printPositiveText(message) else: Common.printNegativeText(message)
def chat(): chatWith = input("Chat With (Username) -> ") response = Connection.chatRequest("chat-permission", {"chatWith": chatWith}) successful = response.get("successful") message = response.get("message") if successful: chatView.ChatView.view(chatWith) else: Common.printNegativeText(message)
def __init__(self, port, baud_rate, terminal=None, reset=False): Connection.__init__(self, terminal) self._port = port self._baud_rate = baud_rate try: self._serial = serial.Serial(None, self._baud_rate, timeout=0, write_timeout=0.2) self._serial.dtr = False self._serial.rts = False self._serial.port = port self._serial.open() kill_and_wait = not reset if reset: self._serial.rts = True time.sleep(0.1) self._serial.rts = False try: # Give board time to reset (10 seconds should be enough) self.read_to_next_prompt(10) except TimeoutError: # If we still get time out, a script was probably # started automatically and needs to be killed kill_and_wait = True if kill_and_wait: self.send_kill() self.read_to_next_prompt() except (OSError, serial.SerialException) as e: self._serial = None return except Exception as e: return self._reader_thread = Thread(target=self._reader_thread_routine) self._reader_thread.start()
def __sendMessage(message): receiver = programLocation.getLocationParameters().get("chatWith") response = Connection.chatRequest("send-message", { "receiver": receiver, "message": message }) if response.get("successful"): date = datetime.now().strftime("%d/%m/%Y %H:%M:%S") Common.printChatLabelText(f"<You> <{date}>: ") Common.printStandartText(message) else: Common.printNegativeText(response.get("message"))
def read(): response = Connection.notificationRequest("read", {}) notifications = response.get("notifications") Common.printNotificationText("Notifications:\n") for notification in notifications: if notification.get("content") is None: continue notificationId = notification.get("id") date = notification.get("date") content = notification.get("content") Common.printNotificationText( f"id -> {notificationId}\ndate -> {date}\ncontent -> {content}\n" )
def deleteOne(): try: notificationId = int(input("Notification Id -> ")) except ValueError: Common.printNegativeText("Notification id must be integer") return response = Connection.notificationRequest("delete-one", {"id": notificationId}) successful = response.get("successful") message = response.get("message") if successful: Common.printPositiveText(message) else: Common.printNegativeText(message)
def registerForm(): form = RegisterForm() form.fillTheForm() Common.clearTerminal() if form.validation(): response = Connection.registerRequest(form.getData()) successful = response.get("successful") message = response.get("message") if successful: Common.printPositiveText(message) else: Common.printNegativeText(message) else: Common.printNegativeText(form.getValidationMessage()) Common.programSleep()
def stream(): response = Connection.chatRequest("stream", { "chatWith": programLocation.getLocationParameters().get("chatWith") }) successful = response.get("successful") if successful: for messageSet in response.get("stream"): sender = messageSet.get("sender") date = messageSet.get("date") message = messageSet.get("message") if sender == "__session__": Common.printChatLabelText(f"<You> <{date}>: ") Common.printStandartText(message) else: Common.printChatLabelText(f"<{sender}> <{date}>: ") Common.printStandartText(message) else: Common.printNegativeText(response.get("message"))
def loginForm(): form = LoginForm() form.fillTheForm() Common.clearTerminal() if form.validation(): response = Connection.loginRequest(form.getData()) successful = response.get("successful") message = response.get("message") if successful: Common.printPositiveText(message) Common.programSleep() LobbyView.view() else: Common.printNegativeText(message) else: Common.printNegativeText(form.getValidationMessage()) Common.programSleep()
def exitCommand(**kwargs): Connection.sessionClose() exit()
def whoami(): response = Connection.profileRequest("whoami", {}).get("whoami") Common.printNotificationText( f"Username -> {response.get('username')}\nEmail -> {response.get('email')}" )