def menu(): connection = pool.getconn() database.create_tables(connection) pool.putconn(connection) while (selection := input(MENU_PROMPT)) != "6": try: MENU_OPTIONS[selection]() except KeyError: print("Invalid input selected. Please try again.")
def get(cls, option_id: int) -> "Option": connection = pool.getconn() option = database.get_option(connection, option_id) pool.putconn(connection) return cls(option[1], option[2], option[0])
def votes(self) -> List[database.Vote]: connection = pool.getconn() votes = database.get_votes_for_option(connection, self.id) pool.putconn(connection) return votes
def vote(self, username: str): connection = pool.getconn() database.add_poll_vote(connection, username, self.id) pool.putconn(connection)
def save(self): connection = pool.getconn() new_option_id = database.add_option(self.text, self.poll_id) pool.putconn(connection) self.id = new_option_id
def latest(cls) -> "Poll": connection = pool.getconn() poll = database.get_latest_poll() pool.putconn(connection) return cls(poll[1], poll[2], poll[0])
def all(cls) -> List["Poll"]: connection = pool.getconn() polls = database.get_polls(connection) pool.putconn(connection) return [cls(poll[1], poll[2], poll[0]) for poll in polls]
def get(cls, poll_id: int) -> "Poll": connection = pool.getconn() poll = database.get_poll(connection, poll_id) pool.putconn(connection) return cls(poll[1], poll[2], poll[0])
def options(self) -> List[Option]: connection = pool.getconn() options = database.get_poll_options(connection, self.id) pool.putconn(connection) return [Option(option[1], option[2], option[0]) for option in options]
def save(self): connection = pool.getconn() new_poll_id = database.create_poll(connection, self.title, self.owner) pool.putconn(connection) self.id = new_poll_id