feat: bin -> .local/bin, vcs_info untracked
This commit is contained in:
parent
af14629939
commit
7c98658d24
30 changed files with 31 additions and 46 deletions
51
.local/bin/crypto
Executable file
51
.local/bin/crypto
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import http.client as http
|
||||
import json
|
||||
|
||||
# curl -sS https://api.coingecko.com/api/v3/coins/list
|
||||
COINS = [
|
||||
# [id, symbol]
|
||||
["monero", "XMR"],
|
||||
["bitcoin", "BTC"],
|
||||
["ordinals", "ORDI"],
|
||||
]
|
||||
CURRENCY = "usd"
|
||||
FORMAT = "{coin}=${price:.0f}"
|
||||
|
||||
|
||||
def get_btc_fees() -> str:
|
||||
url = "mempool.space"
|
||||
path = "/api/v1/fees/mempool-blocks"
|
||||
|
||||
client = http.HTTPSConnection(url)
|
||||
client.request("GET", path)
|
||||
|
||||
# https://mempool.space/docs/api/rest#get-mempool-blocks-fees
|
||||
response = json.loads(client.getresponse().read())
|
||||
return f"{int(response[0]['medianFee'])} sat/vB"
|
||||
|
||||
|
||||
def get_coins_values() -> str:
|
||||
ids = ",".join([coin[0] for coin in COINS])
|
||||
url = "api.coingecko.com"
|
||||
path = f"/api/v3/simple/price?ids={ids}&vs_currencies={CURRENCY}"
|
||||
|
||||
client = http.HTTPSConnection(url)
|
||||
client.request("GET", path)
|
||||
|
||||
# https://www.coingecko.com/api/documentation
|
||||
prices = json.loads(client.getresponse().read())
|
||||
|
||||
return " ".join(
|
||||
FORMAT.format(coin=coin[1], price=prices[coin[0]][CURRENCY])
|
||||
for coin in COINS
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
print(f"{get_btc_fees()} {get_coins_values()}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue