Refactor Agora into sources

master
Mark Veidemanis 3 years ago
parent 8bec00d825
commit cb15346a78
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -12,13 +12,13 @@ from settings import settings
import util
# Old style classes
from agora import Agora
from transactions import Transactions
from markets import Markets
from money import Money
# New style classes
import sinks
import sources
import ux
init_map = None
@ -80,8 +80,8 @@ class WebApp(util.Base):
if __name__ == "__main__":
init_map = {
"ux": ux.UX(),
"agora": Agora(),
"markets": Markets(),
"sources": sources.Sources(),
"sinks": sinks.Sinks(),
"tx": Transactions(),
"webapp": WebApp(),

@ -60,7 +60,7 @@ class Connection:
# If URL is absolute, then convert it
if url.startswith(self.server):
url = url[len(self.server) :]
url = url[len(self.server) :] # noqa
# If OAuth2
if self.access_token:
@ -140,7 +140,7 @@ class Connection:
if int(response_json.get("error", {}).get("error_code")) == 42:
time.sleep(0.1)
continue
except:
except: # noqa
# No JSONic response, or interrupt, better just give up
pass

@ -0,0 +1,40 @@
# Project imports
# from settings import settings
import util
import sources.agora
# import sources.localbitcoins
class Sources(util.Base):
"""
Class to manage calls to various sources.
"""
def __init__(self):
super().__init__()
self.agora = sources.agora.Agora()
# self.localbitcoins = sources.localbitcoins.LocalBitcoins()
def __irc_started__(self):
self.agora.setup_loop()
# self.localbitcoins.setup_loop()
def __xmerged__(self):
"""
Called when xmerge has been completed in the webapp.
Merge all instances into child classes.
"""
init_map = {
"ux": self.ux,
"agora": self.agora,
"markets": self.markets,
"sinks": self.sinks,
"sources": self,
"tx": self.tx,
"webapp": self.webapp,
"money": self.money,
"irc": self.irc,
"notify": self.notify,
}
util.xmerge_attrs(init_map)

@ -5,7 +5,7 @@ from twisted.internet.threads import deferToThread
# Other library imports
from json import loads
from forex_python.converter import CurrencyRates
from agoradesk_py import AgoraDesk
from lib.agoradesk_py import AgoraDesk
from pycoingecko import CoinGeckoAPI # TODO: remove this import and defer to money
from time import sleep
from pyotp import TOTP
@ -40,7 +40,7 @@ class Agora(util.Base):
# Assets that cheat has been run on
self.cheat_run_on = []
def setup_loop(self):
def setup_loop(self): # TODO:: move to main sources
"""
Set up the LoopingCall to get all active trades and messages.
"""

@ -4,7 +4,7 @@ from json import loads
from copy import deepcopy
from tests.common import fake_public_ads, cg_prices, expected_to_update
from agora import Agora
from sources.agora import Agora
from markets import Markets
from money import Money
import util

@ -1,7 +1,7 @@
from unittest import TestCase
from tests.common import fake_public_ads, expected_to_update
from markets import Markets
from agora import Agora
from sources.agora import Agora
class TestMarkets(TestCase):

@ -29,9 +29,9 @@ class UX(object):
"""
init_map = {
"ux": self,
"agora": self.agora,
"markets": self.markets,
"sinks": self.sinks,
"sources": self.sources,
"tx": self.tx,
"webapp": self.webapp,
"money": self.money,

@ -117,8 +117,8 @@ class IRCBot(irc.IRCClient):
:param channel: channel we joined
:type channel: string
"""
self.agora.setup_loop()
self.sinks.__irc_started__()
self.sources.__irc_started__()
self.log.info(f"Joined channel {channel}")
def privmsg(self, user, channel, msg):

Loading…
Cancel
Save