def get_all(cls) -> List["Poll"]: with get_connection() as connection: polls = database.get_polls(connection) return [ cls(title=poll[1], owner=poll[2], _id=poll[0]) for poll in polls ]
def all(cls) -> List["Poll"]: with get_connection() as connection: polls = database.get_polls(connection) return [cls(poll[1], poll[2], poll[0]) for poll in polls] @classmethod def latest(cls) -> "Poll": with get_connection() as connection: poll = database.get_latest_poll(connection) return cls(poll[1], poll[2], poll[0])
def list_open_polls(connection): polls = database.get_polls(connection) for _id, title, owner in polls: print(f"{_id}: {title} (created by {owner})")
def all(cls) -> List["Poll"]: with get_connection() as connection: polls = database.get_polls(connection) return [cls(poll[1], poll[2], poll[0]) for poll in polls]
def all(cls) -> List["Poll"]: connection = create_connection() polls = database.get_polls(connection) connection.close() return [cls(poll[1], poll[2], poll[0]) for poll in polls]
import matplotlib.pyplot as plt import charts import database MENU_PROMPT = "Enter 'q' to quit or anything to chart a new poll." POLL_PROMPT = "Select the poll id to create a pie chart of the vote percentages." def prompt_select_poll(polls): for poll in polls: print(f"{poll[0]}: {poll[1]}") selected_poll = int(input(POLL_PROMPT)) _chart_options_for_poll(selected_poll) def _chart_options_for_poll(poll_id): options = database.get_options(poll_id) figure = charts.create_pie_chart(options) plt.show() while (user_input := input(MENU_PROMPT)) != "q": polls = database.get_polls() prompt_select_poll(polls)
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 list_open_polls(connection): polls = database.get_polls(connection) for poll in polls: print(f"{poll[0]}: {poll[1]} (created by {poll[2]})")