Refactor Agora into sources
This commit is contained in:
parent
8bec00d825
commit
cb15346a78
|
@ -12,13 +12,13 @@ from settings import settings
|
||||||
import util
|
import util
|
||||||
|
|
||||||
# Old style classes
|
# Old style classes
|
||||||
from agora import Agora
|
|
||||||
from transactions import Transactions
|
from transactions import Transactions
|
||||||
from markets import Markets
|
from markets import Markets
|
||||||
from money import Money
|
from money import Money
|
||||||
|
|
||||||
# New style classes
|
# New style classes
|
||||||
import sinks
|
import sinks
|
||||||
|
import sources
|
||||||
import ux
|
import ux
|
||||||
|
|
||||||
init_map = None
|
init_map = None
|
||||||
|
@ -80,8 +80,8 @@ class WebApp(util.Base):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
init_map = {
|
init_map = {
|
||||||
"ux": ux.UX(),
|
"ux": ux.UX(),
|
||||||
"agora": Agora(),
|
|
||||||
"markets": Markets(),
|
"markets": Markets(),
|
||||||
|
"sources": sources.Sources(),
|
||||||
"sinks": sinks.Sinks(),
|
"sinks": sinks.Sinks(),
|
||||||
"tx": Transactions(),
|
"tx": Transactions(),
|
||||||
"webapp": WebApp(),
|
"webapp": WebApp(),
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Connection:
|
||||||
|
|
||||||
# If URL is absolute, then convert it
|
# If URL is absolute, then convert it
|
||||||
if url.startswith(self.server):
|
if url.startswith(self.server):
|
||||||
url = url[len(self.server) :]
|
url = url[len(self.server) :] # noqa
|
||||||
|
|
||||||
# If OAuth2
|
# If OAuth2
|
||||||
if self.access_token:
|
if self.access_token:
|
||||||
|
@ -140,7 +140,7 @@ class Connection:
|
||||||
if int(response_json.get("error", {}).get("error_code")) == 42:
|
if int(response_json.get("error", {}).get("error_code")) == 42:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
continue
|
continue
|
||||||
except:
|
except: # noqa
|
||||||
# No JSONic response, or interrupt, better just give up
|
# No JSONic response, or interrupt, better just give up
|
||||||
pass
|
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
|
# Other library imports
|
||||||
from json import loads
|
from json import loads
|
||||||
from forex_python.converter import CurrencyRates
|
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 pycoingecko import CoinGeckoAPI # TODO: remove this import and defer to money
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from pyotp import TOTP
|
from pyotp import TOTP
|
||||||
|
@ -40,7 +40,7 @@ class Agora(util.Base):
|
||||||
# Assets that cheat has been run on
|
# Assets that cheat has been run on
|
||||||
self.cheat_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.
|
Set up the LoopingCall to get all active trades and messages.
|
||||||
"""
|
"""
|
|
@ -4,7 +4,7 @@ from json import loads
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
from tests.common import fake_public_ads, cg_prices, expected_to_update
|
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 markets import Markets
|
||||||
from money import Money
|
from money import Money
|
||||||
import util
|
import util
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from tests.common import fake_public_ads, expected_to_update
|
from tests.common import fake_public_ads, expected_to_update
|
||||||
from markets import Markets
|
from markets import Markets
|
||||||
from agora import Agora
|
from sources.agora import Agora
|
||||||
|
|
||||||
|
|
||||||
class TestMarkets(TestCase):
|
class TestMarkets(TestCase):
|
||||||
|
|
|
@ -29,9 +29,9 @@ class UX(object):
|
||||||
"""
|
"""
|
||||||
init_map = {
|
init_map = {
|
||||||
"ux": self,
|
"ux": self,
|
||||||
"agora": self.agora,
|
|
||||||
"markets": self.markets,
|
"markets": self.markets,
|
||||||
"sinks": self.sinks,
|
"sinks": self.sinks,
|
||||||
|
"sources": self.sources,
|
||||||
"tx": self.tx,
|
"tx": self.tx,
|
||||||
"webapp": self.webapp,
|
"webapp": self.webapp,
|
||||||
"money": self.money,
|
"money": self.money,
|
||||||
|
|
|
@ -117,8 +117,8 @@ class IRCBot(irc.IRCClient):
|
||||||
:param channel: channel we joined
|
:param channel: channel we joined
|
||||||
:type channel: string
|
:type channel: string
|
||||||
"""
|
"""
|
||||||
self.agora.setup_loop()
|
|
||||||
self.sinks.__irc_started__()
|
self.sinks.__irc_started__()
|
||||||
|
self.sources.__irc_started__()
|
||||||
self.log.info(f"Joined channel {channel}")
|
self.log.info(f"Joined channel {channel}")
|
||||||
|
|
||||||
def privmsg(self, user, channel, msg):
|
def privmsg(self, user, channel, msg):
|
||||||
|
|
Loading…
Reference in New Issue