Last active
October 30, 2022 21:59
-
-
Save jjeanjacques10/72fd81fd7899e71994b19f17a6002f30 to your computer and use it in GitHub Desktop.
Script para gerar notificações dos resultados da eleição
This file contains hidden or 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
# Author: Jean Jacques Barros | |
# Github: https://github.com/jjeanjacques10 | |
from time import sleep | |
import requests | |
from win10toast import ToastNotifier | |
LAST_READ = "" | |
def get_data(): | |
url = "https://resultados.tse.jus.br/oficial/ele2022/545/dados-simplificados/br/br-c0001-e000545-r.json" | |
response = requests.get(url) | |
data = response.json() | |
return data | |
def create_message(candidates, status): | |
text = "" | |
for candidate in candidates: | |
name = candidate.get("nm") | |
votes = candidate.get("pvap") | |
text = text + f"{name} - {votes}% \n" | |
text = text + f"\n Seções apuradas: {status}%" | |
toaster=ToastNotifier() | |
toaster.show_toast("Resultados Eleições", text, duration = 50) | |
print(text) | |
def is_recent(data): | |
return data != LAST_READ | |
def main(): | |
while True: | |
results=get_data() | |
if is_recent(results["hg"]): | |
create_message(results["cand"], results["pst"]) | |
LAST_READ=results["hg"] | |
print("Última atualização: ", LAST_READ) | |
sleep(60) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To deixando so uma estrela pq nao trm 1000