mirror of
https://github.com/revanced/revanced-polling-api.git
synced 2025-04-29 22:24:26 +02:00
feat: add vote counting script
This commit is contained in:
parent
d28b7e5428
commit
c458c7e095
24
poetry.lock
generated
24
poetry.lock
generated
@ -1664,6 +1664,28 @@ async-timeout = {version = ">=4.0.2", markers = "python_version < \"3.11\""}
|
||||
hiredis = ["hiredis (>=1.0.0)"]
|
||||
ocsp = ["cryptography (>=36.0.1)", "pyopenssl (==20.0.1)", "requests (>=2.26.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "requests"
|
||||
version = "2.28.2"
|
||||
description = "Python HTTP for Humans."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7, <4"
|
||||
files = [
|
||||
{file = "requests-2.28.2-py3-none-any.whl", hash = "sha256:64299f4909223da747622c030b781c0d7811e359c37124b4bd368fb8c6518baa"},
|
||||
{file = "requests-2.28.2.tar.gz", hash = "sha256:98b1b2782e3c6c4904938b84c0eb932721069dfdb9134313beff7c83c2df24bf"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
certifi = ">=2017.4.17"
|
||||
charset-normalizer = ">=2,<4"
|
||||
idna = ">=2.5,<4"
|
||||
urllib3 = ">=1.21.1,<1.27"
|
||||
|
||||
[package.extras]
|
||||
socks = ["PySocks (>=1.5.6,!=1.5.7)"]
|
||||
use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
|
||||
|
||||
[[package]]
|
||||
name = "rfc3986"
|
||||
version = "1.5.0"
|
||||
@ -2250,4 +2272,4 @@ multidict = ">=4.0"
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "fa4ea468abe4711e4c5f1516228d8b11e72e10876c56f42df98e122676edccb3"
|
||||
content-hash = "f4b473705cc1919095b7dbf598ca330ebf33ac4c5056a30d802dd853da82bc0f"
|
||||
|
@ -26,6 +26,7 @@ hiredis = ">=2.0.0"
|
||||
aiofiles = ">=22.1.0"
|
||||
uvicorn = ">=0.18.3"
|
||||
gunicorn = ">=20.1.0"
|
||||
requests = "^2.28.2"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
mypy = ">=0.991"
|
||||
|
28
vote_count.py
Normal file
28
vote_count.py
Normal file
@ -0,0 +1,28 @@
|
||||
import os
|
||||
import redis
|
||||
import requests
|
||||
from pprint import pprint
|
||||
|
||||
db = redis.StrictRedis(
|
||||
host=os.environ["REDIS_URL"], port=os.environ["REDIS_PORT"], db=3
|
||||
)
|
||||
|
||||
votes: dict = {}
|
||||
|
||||
for key in db.scan_iter("*"):
|
||||
ballot = db.json().get(key)["votes"]
|
||||
for entry in ballot:
|
||||
if entry["vote"]:
|
||||
if entry["cid"] in votes:
|
||||
votes[entry["cid"]] += 1
|
||||
else:
|
||||
votes[entry["cid"]] = 1
|
||||
|
||||
raw_votes: str = pprint.pformat(votes)
|
||||
sorted_votes: str = pprint.pformat(
|
||||
dict(sorted(votes.items(), key=lambda item: item[1], reverse=True))
|
||||
)
|
||||
|
||||
with open("votes.txt", "w") as f:
|
||||
f.write(raw_votes)
|
||||
f.write(sorted_votes)
|
Loading…
x
Reference in New Issue
Block a user