Browse Source

Allow running ob-watcher without matplotlib installed

master
Kristaps Kaupe 5 years ago
parent
commit
6d626614cb
No known key found for this signature in database
GPG Key ID: D47B1B4232B55437
  1. 22
      scripts/obwatch/ob-watcher.py

22
scripts/obwatch/ob-watcher.py

@ -19,26 +19,26 @@ from twisted.internet import reactor
from jmbase.support import EXIT_FAILURE from jmbase.support import EXIT_FAILURE
from jmbase import get_log
log = get_log()
try: try:
import matplotlib import matplotlib
except: except:
print("matplotlib not found; do `pip install matplotlib` " log.warning("matplotlib not found, charts will not be available. "
"in the joinmarket virtualenv.") "Do `pip install matplotlib` in the joinmarket virtualenv.")
sys.exit(EXIT_FAILURE)
# https://stackoverflow.com/questions/2801882/generating-a-png-with-matplotlib-when-display-is-undefined if 'matplotlib' in sys.modules:
matplotlib.use('Agg') # https://stackoverflow.com/questions/2801882/generating-a-png-with-matplotlib-when-display-is-undefined
import matplotlib.pyplot as plt matplotlib.use('Agg')
import matplotlib.pyplot as plt
from jmbase import get_log
from jmclient import jm_single, load_program_config, calc_cj_fee, \ from jmclient import jm_single, load_program_config, calc_cj_fee, \
get_irc_mchannels, add_base_options get_irc_mchannels, add_base_options
from jmdaemon import OrderbookWatch, MessageChannelCollection, IRCMessageChannel from jmdaemon import OrderbookWatch, MessageChannelCollection, IRCMessageChannel
#TODO this is only for base58, find a solution for a client without jmbitcoin #TODO this is only for base58, find a solution for a client without jmbitcoin
import jmbitcoin as btc import jmbitcoin as btc
from jmdaemon.protocol import * from jmdaemon.protocol import *
log = get_log()
#Initial state: allow only SW offer types #Initial state: allow only SW offer types
swoffers = list(filter(lambda x: x[0:2] == 'sw', offername_list)) swoffers = list(filter(lambda x: x[0:2] == 'sw', offername_list))
@ -153,6 +153,9 @@ class OrderbookPageRequestHeader(http.server.SimpleHTTPRequestHandler):
return result return result
def create_depth_chart(self, cj_amount, args=None): def create_depth_chart(self, cj_amount, args=None):
if 'matplotlib' not in sys.modules:
return 'matplotlib not installed, charts not available'
if args is None: if args is None:
args = {} args = {}
try: try:
@ -196,6 +199,9 @@ class OrderbookPageRequestHeader(http.server.SimpleHTTPRequestHandler):
return get_graph_html(fig) return get_graph_html(fig)
def create_size_histogram(self, args): def create_size_histogram(self, args):
if 'matplotlib' not in sys.modules:
return 'matplotlib not installed, charts not available'
try: try:
self.taker.dblock.acquire(True) self.taker.dblock.acquire(True)
rows = self.taker.db.execute('SELECT maxsize, ordertype FROM orderbook;').fetchall() rows = self.taker.db.execute('SELECT maxsize, ordertype FROM orderbook;').fetchall()

Loading…
Cancel
Save