add scripts
Signed-off-by: Martin Matous <m@matous.dev>
This commit is contained in:
parent
c6c66648ea
commit
5a4419bb4e
12 changed files with 802 additions and 1 deletions
36
gasquery.py
Executable file
36
gasquery.py
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import json
|
||||
import requests
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
API_KEY = sys.argv[1]
|
||||
BASEFEE_THRESHOLD = int(sys.argv[2])
|
||||
|
||||
def to_gwei(wei: int) -> int:
|
||||
return int(wei/(10**9))
|
||||
|
||||
response = requests.post(
|
||||
url=f'https://eth-mainnet.alchemyapi.io/v2/{API_KEY}',
|
||||
data='{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":0}'
|
||||
)
|
||||
if not response.ok:
|
||||
subprocess.run(['notify-send', 'Gasquery', f'Query returned {response.status_code}: {response.reason}'])
|
||||
print('{"text": "⚠️NaN"}')
|
||||
sys.exit()
|
||||
|
||||
basefee = response.json()['result']
|
||||
basefee = to_gwei(int(basefee, base=16))
|
||||
if basefee <= BASEFEE_THRESHOLD:
|
||||
subprocess.run(['notify-send', 'Gasquery', f'Current basefee is {basefee}'])
|
||||
|
||||
state = 'Idle'
|
||||
if basefee < BASEFEE_THRESHOLD:
|
||||
state = 'Good'
|
||||
elif basefee > 150:
|
||||
state = 'Warning'
|
||||
elif basefee > 200:
|
||||
state = 'Critical'
|
||||
text = '{' + f'"state": "{state}", "text": "⛽ {basefee}"' + '}'
|
||||
print(text)
|
||||
Loading…
Add table
Add a link
Reference in a new issue