Diff
checker
टेक्स्ट
टेक्स्ट
छवियां
दस्तावेज़
Excel
फ़ोल्डर्स
Legal
Enterprise
डेस्कटॉप
मूल्य
साइन इन करें
Diffchecker डेस्कटॉप डाउनलोड करें
टेक्स्ट की तुलना करें
दो टेक्स्ट फ़ाइलों के बीच अंतर ढूंढें
उपकरण
इतिहास
रियल-टाइम एडिटर
अपरिवर्तित संक्षिप्त करें
लाइन रैप बंद
लेआउट
विभाजित
संयुक्त
परिवर्तन हाइलाइट करें
स्मार्ट
शब्द
अक्षर
सिंटैक्स हाइलाइटिंग
सिंटैक्स चुनें
अनदेखा करें
टेक्स्ट बदलें
पहले अंतर पर जाएँ
इनपुट संपादित करें
Diffchecker Desktop
Diffchecker चलाने का सबसे सुरक्षित तरीका। Diffchecker Desktop ऐप पाएं: आपके diffs कभी आपके कंप्यूटर से बाहर नहीं जाते!
Desktop पाएं
app-separating-code-to-models
बनाया गया
6 वर्ष पहले
Diff कभी समाप्त नहीं होता
साफ़
निर्यात करें
शेयर करें
समझाएं
52 हटाए गए
लाइनें
कुल
हटाया गया
अक्षर
कुल
हटाया गया
इस सुविधा का उपयोग जारी रखने के लिए, अपग्रेड करें
Diff
checker
Pro
मूल्य देखें
102 लाइनें
सभी को कॉपी करें
39 जोड़े गए
लाइनें
कुल
जोड़ा गया
अक्षर
कुल
जोड़ा गया
इस सुविधा का उपयोग जारी रखने के लिए, अपग्रेड करें
Diff
checker
Pro
मूल्य देखें
101 लाइनें
सभी को कॉपी करें
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
import
os
import
random
import psycopg2
import psycopg2
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
from psycopg2.errors import DivisionByZero
from dotenv import load_dotenv
import database
import database
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
from connection_pool import pool
from models.option import Option
from models.poll import Poll
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
DATABASE_PROMPT = "Enter the DATABASE_URI value or leave empty to load from .env file: "
MENU_PROMPT = """-- Menu --
MENU_PROMPT = """-- Menu --
1) Create new poll
1) Create new poll
2) List open polls
2) List open polls
3) Vote on a poll
3) Vote on a poll
4) Show poll votes
4) Show poll votes
5) Select a random winner from a poll option
5) Select a random winner from a poll option
6) Exit
6) Exit
Enter your choice: """
Enter your choice: """
NEW_OPTION_PROMPT = "Enter new option text (or leave empty to stop adding options): "
NEW_OPTION_PROMPT = "Enter new option text (or leave empty to stop adding options): "
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
def prompt_create_poll(
connection
):
def prompt_create_poll(
):
poll_
title = input("Enter poll title: ")
title = input("Enter poll title: ")
poll_
owner = input("Enter poll owner: ")
owner = input("Enter poll owner: ")
options
=
[]
poll
=
Poll(title, owner)
poll.save()
while (new_option := input(NEW_OPTION_PROMPT)):
while (new_option := input(NEW_OPTION_PROMPT)):
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
option
s.append
(new_option)
poll.add_
option
(new_option)
database.create_poll(connection, poll_title, poll_owner, options)
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
def list_open_polls(
connection
):
def list_open_polls(
):
polls = database.get_polls(connection)
for poll in
P
oll
.all()
:
print(f"{poll
.id
}: {poll
.title
} (created by {poll
.owner
})")
for poll in
p
oll
s
:
print(f"{poll
[0]
}: {poll
[1]
} (created by {poll
[2]
})")
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
def prompt_vote_poll(
connection
):
def prompt_vote_poll(
):
poll_id = int(input("Enter poll would you like to vote on: "))
poll_id = int(input("Enter poll would you like to vote on: "))
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
poll_options = database.get_poll_details(connection, poll_id)
_print_poll_options(
Poll.get(
poll_
id).
options)
_print_poll_options(
poll_
options)
option_id = int(input("Enter option you'd like to vote for: "))
option_id = int(input("Enter option you'd like to vote for: "))
username = input("Enter the username you'd like to vote as: ")
username = input("Enter the username you'd like to vote as: ")
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
database.add_poll_vote(connection, username,
option_id)
Option.get(
option_id)
.vote(username)
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
def _print_poll_options(
poll_with_
options):
def _print_poll_options(
options):
for option in
poll_with_
options:
for option in
options:
print(f"{option
[3]
}: {option
[4]
}")
print(f"{option
.id
}: {option
.text
}")
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
def show_poll_votes(
connection
):
def show_poll_votes(
):
poll_id = int(input("Enter poll you would like to see votes for: "))
poll_id = int(input("Enter poll you would like to see votes for: "))
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
poll = Poll.get(poll_id)
options = poll.options
votes_per_option = [len(option.votes) for option in options]
total_votes = sum(votes_per_option)
try:
try:
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
poll_and_votes = database.get_poll_and_vote_results(connection, poll_id)
for option, votes in zip(options, votes_per_option):
except
DivisionByZero
:
percentage = votes / total_votes * 100
percentage = votes / total_votes * 100
print(f"{option.text} for {votes} ({percentage:.2f}% of total)")
except
ZeroDivisionError
:
print("No votes yet cast for this poll.")
print("No votes yet cast for this poll.")
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
else:
for result in poll_and_votes:
print(f"{result[1]} got {result[2]} votes ({result[3]:.2f}% of total)")
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
def randomize_poll_winner(
connection
):
def randomize_poll_winner(
):
poll_id = int(input("Enter poll you'd like to pick a winner for: "))
poll_id = int(input("Enter poll you'd like to pick a winner for: "))
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
poll
_options
=
database
.get
_poll_details(connection,
poll_id)
poll
=
Poll
.get
(
poll_id)
_print_poll_options(poll
_
options)
_print_poll_options(poll
.
options)
option_id = int(input("Enter which is the winning option, we'll pick a random winner from voters: "))
option_id = int(input("Enter which is the winning option, we'll pick a random winner from voters: "))
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
winner =
database.get_
random
_poll_
vote
(connection, option_id
)
votes = Option.get(option_id).votes
winner =
random
.choice(
vote
s
)
print(f"The randomly selected winner is {winner[0]}.")
print(f"The randomly selected winner is {winner[0]}.")
MENU_OPTIONS = {
MENU_OPTIONS = {
"1": prompt_create_poll,
"1": prompt_create_poll,
"2": list_open_polls,
"2": list_open_polls,
"3": prompt_vote_poll,
"3": prompt_vote_poll,
"4": show_poll_votes,
"4": show_poll_votes,
"5": randomize_poll_winner
"5": randomize_poll_winner
}
}
def menu():
def menu():
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
database_uri = input(DATABASE_PROMPT)
connection =
pool.getconn(
)
if not database_uri:
load_dotenv()
database_uri = os.environ["DATABASE_URI"]
connection =
psycopg2.connect(database_uri
)
database.create_tables(connection)
database.create_tables(connection)
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
pool.putconn(connection)
while (selection := input(MENU_PROMPT)) != "6":
while (selection := input(MENU_PROMPT)) != "6":
try:
try:
कॉपी
कॉपी हुआ
कॉपी
कॉपी हुआ
MENU_OPTIONS[selection](
connection
)
MENU_OPTIONS[selection](
)
except KeyError:
except KeyError:
print("Invalid input selected. Please try again.")
print("Invalid input selected. Please try again.")
menu()
menu()
सेव किए गए Diffs
ऑरिजनल टेक्स्ट
फ़ाइल खोलें
import os import psycopg2 from psycopg2.errors import DivisionByZero from dotenv import load_dotenv import database DATABASE_PROMPT = "Enter the DATABASE_URI value or leave empty to load from .env file: " MENU_PROMPT = """-- Menu -- 1) Create new poll 2) List open polls 3) Vote on a poll 4) Show poll votes 5) Select a random winner from a poll option 6) Exit Enter your choice: """ NEW_OPTION_PROMPT = "Enter new option text (or leave empty to stop adding options): " def prompt_create_poll(connection): poll_title = input("Enter poll title: ") poll_owner = input("Enter poll owner: ") options = [] while (new_option := input(NEW_OPTION_PROMPT)): options.append(new_option) database.create_poll(connection, poll_title, poll_owner, options) def list_open_polls(connection): polls = database.get_polls(connection) for poll in polls: print(f"{poll[0]}: {poll[1]} (created by {poll[2]})") def prompt_vote_poll(connection): poll_id = int(input("Enter poll would you like to vote on: ")) poll_options = database.get_poll_details(connection, poll_id) _print_poll_options(poll_options) option_id = int(input("Enter option you'd like to vote for: ")) username = input("Enter the username you'd like to vote as: ") database.add_poll_vote(connection, username, option_id) def _print_poll_options(poll_with_options): for option in poll_with_options: print(f"{option[3]}: {option[4]}") def show_poll_votes(connection): poll_id = int(input("Enter poll you would like to see votes for: ")) try: poll_and_votes = database.get_poll_and_vote_results(connection, poll_id) except DivisionByZero: print("No votes yet cast for this poll.") else: for result in poll_and_votes: print(f"{result[1]} got {result[2]} votes ({result[3]:.2f}% of total)") def randomize_poll_winner(connection): poll_id = int(input("Enter poll you'd like to pick a winner for: ")) poll_options = database.get_poll_details(connection, poll_id) _print_poll_options(poll_options) option_id = int(input("Enter which is the winning option, we'll pick a random winner from voters: ")) winner = database.get_random_poll_vote(connection, option_id) print(f"The randomly selected winner is {winner[0]}.") MENU_OPTIONS = { "1": prompt_create_poll, "2": list_open_polls, "3": prompt_vote_poll, "4": show_poll_votes, "5": randomize_poll_winner } def menu(): database_uri = input(DATABASE_PROMPT) if not database_uri: load_dotenv() database_uri = os.environ["DATABASE_URI"] connection = psycopg2.connect(database_uri) database.create_tables(connection) while (selection := input(MENU_PROMPT)) != "6": try: MENU_OPTIONS[selection](connection) except KeyError: print("Invalid input selected. Please try again.") menu()
परिवर्तित टेक्स्ट
फ़ाइल खोलें
import random import psycopg2 import database from connection_pool import pool from models.option import Option from models.poll import Poll MENU_PROMPT = """-- Menu -- 1) Create new poll 2) List open polls 3) Vote on a poll 4) Show poll votes 5) Select a random winner from a poll option 6) Exit Enter your choice: """ NEW_OPTION_PROMPT = "Enter new option text (or leave empty to stop adding options): " def prompt_create_poll(): title = input("Enter poll title: ") owner = input("Enter poll owner: ") poll = Poll(title, owner) poll.save() while (new_option := input(NEW_OPTION_PROMPT)): poll.add_option(new_option) def list_open_polls(): for poll in Poll.all(): print(f"{poll.id}: {poll.title} (created by {poll.owner})") def prompt_vote_poll(): poll_id = int(input("Enter poll would you like to vote on: ")) _print_poll_options(Poll.get(poll_id).options) option_id = int(input("Enter option you'd like to vote for: ")) username = input("Enter the username you'd like to vote as: ") Option.get(option_id).vote(username) def _print_poll_options(options): for option in options: print(f"{option.id}: {option.text}") def show_poll_votes(): poll_id = int(input("Enter poll you would like to see votes for: ")) poll = Poll.get(poll_id) options = poll.options votes_per_option = [len(option.votes) for option in options] total_votes = sum(votes_per_option) try: for option, votes in zip(options, votes_per_option): percentage = votes / total_votes * 100 percentage = votes / total_votes * 100 print(f"{option.text} for {votes} ({percentage:.2f}% of total)") except ZeroDivisionError: print("No votes yet cast for this poll.") def randomize_poll_winner(): poll_id = int(input("Enter poll you'd like to pick a winner for: ")) poll = Poll.get(poll_id) _print_poll_options(poll.options) option_id = int(input("Enter which is the winning option, we'll pick a random winner from voters: ")) votes = Option.get(option_id).votes winner = random.choice(votes) print(f"The randomly selected winner is {winner[0]}.") MENU_OPTIONS = { "1": prompt_create_poll, "2": list_open_polls, "3": prompt_vote_poll, "4": show_poll_votes, "5": randomize_poll_winner } 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.") menu()
अंतर खोजें