Spaces:
Sleeping
Sleeping
File size: 2,423 Bytes
0a11439 f6d203c 0a11439 e06dbcc 31c27d6 7b78e0a e06dbcc f6d203c 922efad f6d203c 7e29ab6 0a11439 5174200 30fed6f 922efad 30fed6f 922efad 30fed6f 5174200 5ba67c4 7a0b9db 5ba67c4 7a0b9db 922efad 7a0b9db 5ba67c4 b7680eb f6d203c 5ba67c4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
import streamlit as st
import sqlite3
# Lista de candidatos
candidatos = [
"Javier Milei",
"Patricia Bullrich",
"Sergio Massa",
"Juan Schiaretti",
"Myriam Bregman",
"Votos en blanco / impugnados"
]
# Conexi贸n a la base de datos
conn = sqlite3.connect('resultados.db')
c = conn.cursor()
# Crear tabla si no existe
c.execute('''CREATE TABLE IF NOT EXISTS resultados
(nombre text, milei real, bullrich real, massa real, schiaretti real, bregman real, blanco real)''')
# Diccionario para almacenar las votaciones
votaciones = {}
st.title("Elecciones Presidenciales 2023")
# Funci贸n para validar votante
def validar_votante(nombre):
return nombre in votaciones
# Secci贸n principal
nombre_votante = st.text_input("Ingrese su nombre")
if nombre_votante:
if not validar_votante(nombre_votante):
# Secci贸n de votaci贸n
porcentajes = {}
total = 0
for candidato in candidatos:
porcentaje = st.number_input(f"Porcentaje de votos para {candidato}", min_value=0, max_value=100)
porcentajes[candidato] = porcentaje
total += porcentaje
if total == 100:
confirmado = st.button("Votar")
if confirmado:
# Guardar resultados en la base de datos
c.execute('INSERT INTO resultados VALUES (?, ?, ?, ?, ?, ?, ?)',
(nombre_votante, porcentajes["Javier Milei"], porcentajes["Patricia Bullrich"],
porcentajes["Sergio Massa"], porcentajes["Juan Schiaretti"], porcentajes["Myriam Bregman"], porcentajes["Votos en blanco / impugnados"]))
conn.commit()
votaciones[nombre_votante] = porcentajes
st.write(f"Gracias {nombre_votante}!")
# Verificar si el votante ya vot贸
if nombre_votante in votaciones:
st.write(f"Gracias {nombre_votante}, ya votaste")
# Mostrar resultados
if st.button("Resultados"):
# Leer resultados desde la base de datos
c.execute('SELECT * FROM resultados')
resultados = c.fetchall()
st.write("Resultados actuales:")
for resultado in resultados:
st.write(f'{resultado[0]}:')
for i, candidato in enumerate(candidatos):
st.write(f'{candidato}: {resultado[i + 1]}%')
# Bot贸n para volver
if st.button("< Volver"):
st.empty()
# Cerrar conexi贸n a la base de datos
conn.close()
|