Last active
December 10, 2023 11:11
-
-
Save arynyklas/85a01456604a6f8f4f26460fa3fe204f to your computer and use it in GitHub Desktop.
@whale's live wins
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
from httpx import Client, ReadTimeout | |
from itertools import cycle | |
from collections import deque | |
from math import modf | |
from time import sleep | |
BOT_TOKEN: str = "..." | |
CHAT_ID: int = -100 | |
PROXIES: list[str] = [ | |
"..." | |
] | |
TIMEOUT: float = 1 | |
http_clients_cycle = cycle([ | |
Client( | |
proxies = proxy | |
) | |
for proxy in PROXIES | |
]) | |
tg_http_client: Client = Client() | |
displayed_data: deque = deque( | |
maxlen = 25 | |
) | |
TELEGRAM_SEND_MESSAGE_URL: str = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" | |
def pretty_amount(amount: float) -> str: | |
if not amount: | |
return "0" | |
frac: float | |
whole: float | |
frac, whole = modf(amount) | |
if frac > 0: | |
return str(amount).replace(".", ",", 1) | |
return str(int(whole)) | |
def parse(send_message: bool) -> None: | |
try: | |
response_data: list[dict] = next(http_clients_cycle).post( | |
url = "https://api.crashgame247.io/users/hall-of-fame/live" | |
).json()["live"] | |
except ReadTimeout: | |
return parse( | |
send_message = send_message | |
) | |
for item_data in response_data[::-1]: | |
if item_data in displayed_data: | |
continue | |
if send_message: | |
tg_http_client.post( | |
url = TELEGRAM_SEND_MESSAGE_URL, | |
json = { | |
"chat_id": CHAT_ID, | |
"text": f"""<i>{item_data["username"]}</i> => <b>{pretty_amount(int(item_data["amount"]) / 100000)} {item_data["currency"]}</b> in <i>{item_data["game"].strip()}</i>""", | |
"parse_mode": "HTML" | |
} | |
) | |
displayed_data.append(item_data) | |
parse( | |
send_message = False | |
) | |
while True: | |
parse( | |
send_message = True | |
) | |
sleep(TIMEOUT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment