Пример #1
0
def main():
    with get_cursor() as connection:
        database.create_tables(connection)
    while (selection := input(MENU)) != "6":
        try:
            MENU_OPTIONS[selection]()
        except KeyError:
            print("Invalid options")
Пример #2
0
 def get(cls, option_id: int) -> "Option":
     with get_cursor() as connection:
         option = database.get_option(connection, option_id)
         return cls(option[1], option[2], option[0])
Пример #3
0
 def votes(self) -> List[database.Vote]:
     with get_cursor() as connection:
         votes = database.get_votes_for_option(connection, self.id)
         return votes
Пример #4
0
 def vote(self, username: str):
     with get_cursor() as connection:
         vote_timestamp = datetime.datetime.now(tz=pytz.utc).timestamp()
         database.add_poll_vote(connection, username, vote_timestamp,
                                self.id)
Пример #5
0
 def save(self):
     with get_cursor() as connection:
         new_option_id = database.add_option(connection, self.text,
                                             self.poll_id)
         self.id = new_option_id