forked from yachaycode/api-resultados-onpe-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7aa780e
commit 98d9081
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
VISUALIZACION DE RESULTADOS EN TIEMP REAL, ELECCIONES PRESIDENCIALES SEGUNDA VUELTA - AMBITO TODO, PERU 2021 | ||
|
||
![ONPE RESULTADOS](resultados-onpe.png) | ||
|
||
### Requisitos: | ||
- git | ||
- pip3 | ||
- virtualenv | ||
- python3.6.x | ||
- requiests | ||
|
||
### Requisitos S.O: | ||
- Windows, linux o mac. | ||
|
||
### Ejecucion en modo usuario | ||
En windows ejecutar el archivo : | ||
abrir el ejecutable `resultados_segunda_vuelta_onpe.exe` | ||
|
||
En linux y mac ejecutar el archivo: | ||
>> abrir el archivo ejecutable `resultados_segunda_vuelta_onpe` | ||
### Ejecución en modo desarrollador: | ||
|
||
Crear un entorno virtual(opcional) | ||
``` | ||
virtualenv -p python3 env_resultados_onpe && source env_resultados_onpe/bin/activate | ||
``` | ||
Clonar el proyecto: | ||
``` | ||
[email protected]:yachaycode/api-resultados-onpe-2021.git | ||
``` | ||
Instalación de dependencias | ||
``` | ||
pip install -r install requeriments.txt | ||
``` | ||
ejecutar el script | ||
|
||
``` | ||
python resultados_segunda_vuelta_onpe.py | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests==2.19.1 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import requests | ||
import time | ||
from random import randint | ||
|
||
def get_data_api_onpe(): | ||
"""Get data api site ificia onpe 2021""" | ||
response = {} | ||
headers = { | ||
'authority': 'api.resultadossep.eleccionesgenerales2021.pe', | ||
'cache-control': 'max-age=0', | ||
'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="91", "Chromium";v="91"', | ||
'sec-ch-ua-mobile': '?0', | ||
'upgrade-insecure-requests': '1', | ||
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36', | ||
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9', | ||
'sec-fetch-site': 'cross-site', | ||
'sec-fetch-mode': 'navigate', | ||
'sec-fetch-user': '?1', | ||
'sec-fetch-dest': 'document', | ||
'accept-language': 'es-PE,es-US;q=0.9,es-419;q=0.8,es;q=0.7', | ||
'cookie': '_ga=GA1.2.1710160415.1623042816; _gid=GA1.2.1906594453.1623042816', | ||
} | ||
|
||
params = ( | ||
('name', 'param'), | ||
) | ||
try: | ||
response = requests.get('https://api.resultadossep.eleccionesgenerales2021.pe/results/10/000000', headers=headers, params=params).json() | ||
except Exception as e: | ||
print ("The api may not have responded correctly..") | ||
return response | ||
|
||
if __name__ == "__main__": | ||
print (' ') | ||
print ('RESULTADO EN TIEMP REAL, ELECCIONES PRESIDENCIALES, SEGUNDA VUELTA - AMBITO TODO, PERU 2021') | ||
print ('Fuente:https://www.resultadossep.eleccionesgenerales2021.pe/SEP2021/EleccionesPresidenciales/RePres/T') | ||
while True: | ||
data = get_data_api_onpe() | ||
name_peru_libre = data.get('results')[0] | ||
name_fuerza_popular = data.get('results')[1] | ||
# print ('fuerza_popular:',name_fuerza_popular) | ||
# print ('peru_libre:',name_peru_libre) | ||
pause = randint(15*60, 25*60) | ||
dif_votos = (int(name_peru_libre.get('TOTAL_VOTOS').replace(',','')) - int(name_fuerza_popular.get('TOTAL_VOTOS').replace(',', ''))) | ||
print ('\n') | ||
print (name_peru_libre.get('AGRUPACION') , ' ', name_fuerza_popular.get('AGRUPACION')) | ||
print ('------------------------------------- ---------------------------\n') | ||
print ('TOTAL_VOTOS:', name_peru_libre.get('TOTAL_VOTOS') , ' TOTAL_VOTOS:', name_fuerza_popular.get('TOTAL_VOTOS')) | ||
print ('votos emitidos: {}{}:'.format(name_peru_libre.get('POR_EMITIDOS'), '%'), ' votos emitidos: {}{}'.format(name_fuerza_popular.get('POR_EMITIDOS'),'%')) | ||
print ('VOTOS VALIDOS: {}{}'.format(name_peru_libre.get('POR_VALIDOS'),'%' ) , ' VOTOS VALIDOS: {}{}'.format(name_fuerza_popular.get('POR_VALIDOS'),'%')) | ||
print ('DIFERENCIA DE VOTOS PERU LIBRE FRENTE A FUERZA POPULAR:{} VOTOS'.format(dif_votos)) | ||
print ("FECHA DE ACTUALIZACION:{}{}".format(data.get('generals').get('actData').get('FECHA'), ' a las'), data.get('generals').get('actData').get('HORA')) | ||
print ('AVANCE CONTEO:{}%'.format(data.get('generals').get('actData').get('POR_AVANCE'))) | ||
print('Esperando {}min para la proxima consulta automática..'.format(int(pause/60))) | ||
time.sleep(pause) | ||
|
||
|
||
|