working crypto channel
This commit is contained in:
parent
14fbc7f827
commit
a472c4dc06
8
gecko.py
8
gecko.py
|
@ -37,12 +37,12 @@ class GeckoAPI:
|
|||
|
||||
return self.api.get_coins_list()
|
||||
|
||||
def getSymbol(self, symbol, curr="EUR", decimal=2):
|
||||
def getSymbol(self, symbol_id, curr="EUR", decimal=2):
|
||||
"""
|
||||
|
||||
"""
|
||||
|
||||
matching = [x for x in self.coinlist if x["symbol"] == symbol.lower()]
|
||||
matching = [x for x in self.coinlist if x["id"] == symbol_id.lower()]
|
||||
if len(matching) == 1:
|
||||
resp_dict = self.api.get_price(ids=matching[0]["id"], vs_currencies=curr.lower())
|
||||
price = resp_dict[matching[0]["id"]][curr.lower()]
|
||||
|
@ -51,7 +51,9 @@ class GeckoAPI:
|
|||
price = f"{price:.{decimal}f}"
|
||||
return price
|
||||
else:
|
||||
return "No unique coin found"
|
||||
print(matching)
|
||||
# No unique coin found
|
||||
return "Not found"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
39
myTS3.py
39
myTS3.py
|
@ -10,9 +10,9 @@ __status__ = "Development"
|
|||
|
||||
# Default
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
from functools import partial
|
||||
|
||||
# Custom
|
||||
import ts3
|
||||
|
@ -43,6 +43,7 @@ class TSbot:
|
|||
self.myid = None
|
||||
self.running = True
|
||||
self.intro = "<Keep this chat open to use commands>"
|
||||
self.last_crypto_update = time.time() - 1800
|
||||
|
||||
self.pipeOut(f"Trying to connect to: {self.host}:{self.port}")
|
||||
|
||||
|
@ -94,17 +95,6 @@ class TSbot:
|
|||
# Subscribe to channel movement events
|
||||
# self.bot.servernotifyregister(event="channel", id_=0)
|
||||
|
||||
"""
|
||||
# Start the timer for auto-updating crypto channels
|
||||
channelname = f"{'[cspacerBTC]Bitcoin:':<33}" + f"{self.gecko.getSymbol('BTC', decimal=0):>5}€"
|
||||
btc_timer = util.maketimer(60, partial(self.editChannelname, 200, channelname))
|
||||
btc_timer.start()
|
||||
sleep(10)
|
||||
channelname = f"{'[cspacerETH]Ethereum:':<30}" + f"{self.gecko.getSymbol('ETH', decimal=0):>5}€"
|
||||
eth_timer = util.maketimer(60, partial(self.editChannelname, 201, channelname))
|
||||
eth_timer.start()
|
||||
"""
|
||||
|
||||
time.sleep(5) # This can be removed if the Query Client is Whitelisted
|
||||
# Notify connected admins
|
||||
self.notifyAdmin()
|
||||
|
@ -115,6 +105,13 @@ class TSbot:
|
|||
self.pipeOut(f"Waiting for a new Event...")
|
||||
self.bot.version()
|
||||
|
||||
# Auto-update crypto price channels every 30 minutes
|
||||
if self.last_crypto_update + 1800 < time.time():
|
||||
self.last_crypto_update = time.time()
|
||||
|
||||
self.lookupcommand(".btc", self.myid)
|
||||
self.lookupcommand(".dot", self.myid)
|
||||
|
||||
try:
|
||||
# This method blocks, but we must sent the keepalive message at
|
||||
# least once in 5 minutes to avoid the sever side idle client
|
||||
|
@ -281,13 +278,19 @@ class TSbot:
|
|||
"""
|
||||
Using a channel-id you can set the name of the given channel.
|
||||
This will fail if the channel name is already in use.
|
||||
This will fail if the given channel name is > 40 bytes.
|
||||
"""
|
||||
|
||||
# Check name for bytes
|
||||
n = len(name)
|
||||
if n > 40:
|
||||
self.pipeOut(f"Can't change channelname to {name} as [{n}] exceeds the max bytes of 40.")
|
||||
return
|
||||
|
||||
try:
|
||||
self.bot.channeledit(cid=cid, channel_name=name)
|
||||
except Exception as e:
|
||||
self.pipeOut(e, lvl="error")
|
||||
pass
|
||||
|
||||
def list(self, what, invkr_id):
|
||||
"""
|
||||
|
@ -373,15 +376,17 @@ class TSbot:
|
|||
cid = self.createChannel("Test")
|
||||
self.bot.sendtextmessage(targetmode=1, target=invkr_id, msg=cid)
|
||||
|
||||
elif command == ".btc":
|
||||
channelname = f"{'[cspacerBTC]Bitcoin:':<33}" + f"{self.gecko.getSymbol('BTC', decimal=0):>5}€"
|
||||
elif command == ".btc" or command == ".eth":
|
||||
channelname = f"[cspacerC1]BTC: {self.gecko.getSymbol('Bitcoin', decimal=0)} | " \
|
||||
f"ETH: {self.gecko.getSymbol('ethereum', decimal=0)}"
|
||||
try:
|
||||
self.editChannelname(200, channelname)
|
||||
except ts3.query.TS3QueryError:
|
||||
pass
|
||||
|
||||
elif command == ".eth":
|
||||
channelname = f"{'[cspacerETH]Ethereum:':<30}" + f"{self.gecko.getSymbol('ETH', decimal=0):>5}€"
|
||||
elif command == ".dot" or command == ".ada":
|
||||
channelname = f"[cspacerC2]DOT: {self.gecko.getSymbol('polkadot', decimal=2)} | " \
|
||||
f"ADA: {self.gecko.getSymbol('cardano', decimal=2)}"
|
||||
try:
|
||||
self.editChannelname(201, channelname)
|
||||
except ts3.query.TS3QueryError:
|
||||
|
|
2
util.py
2
util.py
|
@ -38,7 +38,7 @@ def setupLogger():
|
|||
"""
|
||||
log = logging.getLogger()
|
||||
now = date.today().strftime("%Y-%m-%d")
|
||||
handler = logging.FileHandler(f"myTS3_{now}_{__version__}.log", encoding="utf-8")
|
||||
handler = logging.FileHandler(f"myTS3_{now}.log", encoding="utf-8")
|
||||
logformat = logging.Formatter("%(asctime)s %(levelname)7s %(message)s", "%d-%m-%Y %H:%M:%S")
|
||||
handler.setFormatter(logformat)
|
||||
log.addHandler(handler)
|
||||
|
|
Loading…
Reference in New Issue