start of refactor to objects
This commit is contained in:
Binary file not shown.
BIN
modules/__pycache__/utils.cpython-313.pyc
Normal file
BIN
modules/__pycache__/utils.cpython-313.pyc
Normal file
Binary file not shown.
@@ -17,7 +17,7 @@ private_key = os.getenv("ASTER_API_PRIVATE_KEY")
|
||||
_last_ms = 0
|
||||
_i = 0
|
||||
|
||||
def post_authenticated_url(req: dict) -> dict:
|
||||
async def post_authenticated_url(req: dict) -> dict:
|
||||
typed_data = {
|
||||
"types": {
|
||||
"EIP712Domain": [
|
||||
@@ -71,7 +71,7 @@ def post_authenticated_url(req: dict) -> dict:
|
||||
)
|
||||
return Account.sign_message(message, private_key=private_key)
|
||||
|
||||
def send_by_url(req):
|
||||
async def send_by_url(req):
|
||||
my_dict = req['params'].copy()
|
||||
url = host + req['url']
|
||||
method = req['method']
|
||||
@@ -105,4 +105,4 @@ def post_authenticated_url(req: dict) -> dict:
|
||||
# print(res.status_code, res.text)
|
||||
return res.json()
|
||||
|
||||
return send_by_url(req=req)
|
||||
return await send_by_url(req=req)
|
||||
|
||||
28
modules/utils.py
Normal file
28
modules/utils.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import logging
|
||||
from dotenv import load_dotenv
|
||||
import requests
|
||||
import os
|
||||
|
||||
load_dotenv()
|
||||
|
||||
def upsert_list_of_dicts_by_id(list_of_dicts, new_dict, id='id', seq_check_field: str | None = None):
|
||||
for index, item in enumerate(list_of_dicts):
|
||||
if item.get(id) == new_dict.get(id):
|
||||
if seq_check_field is not None:
|
||||
if item.get(seq_check_field) > new_dict.get(seq_check_field):
|
||||
logging.info('Skipping out of sequence msg')
|
||||
return list_of_dicts
|
||||
list_of_dicts[index] = new_dict
|
||||
return list_of_dicts
|
||||
|
||||
list_of_dicts.append(new_dict)
|
||||
return list_of_dicts
|
||||
|
||||
def send_tg_alert(msg: str):
|
||||
token = os.getenv("TG_TOKEN")
|
||||
chat_id = os.getenv("TG_ALERTS_CHAT_ID")
|
||||
|
||||
url = f'https://api.telegram.org/bot{token}/sendMessage?chat_id={chat_id}'
|
||||
response = requests.post(url, json={'text': str(str(msg)[:250])}, timeout=10)
|
||||
|
||||
return response.json()
|
||||
Reference in New Issue
Block a user