# Path: lib/CurrencyManager.py
# _PRICE_REGEX = re.compile('\s*([0-9]+|[0-9]+\.[0-9]+)\s+([a-z\-]+)')
# _OVERRIDE_REGEX = re.compile('\s*([+\-*/]?)\s*(.+)')
# _NUMBER_REGEX = re.compile('[0-9]+(?:\.[0-9]+)?$')
# INVALID_OVERRIDE = "Invalid override price \'{}\' for {}"
# INVALID_OVERRIDE_RATE = "Invalid override rate \'{}\' = {} for {}. Rate must be a positive number"
# INVALID_PRICE = "Invalid price {}"
#     CURRENCY_FNAME = "cfg\\currency.json"
#     CURRENCY_BASE_FNAME = "res\\currency_base.json"
#     CURRENCY_API = [urljoin(POE_NINJA_API, "GetCurrencyOverview?league={}"),
#                     urljoin(POE_NINJA_API, "GetFragmentOverview?league={}")]
#     UPDATE_INTERVAL = 10  # minutes
#     DEFAULT_CONFIDENCE_LEVEL = ConfidenceLevel.Medium.value
#     CHAOS_NAME = 'Chaos Orb'
# class CurrencyManager:
# class CompiledCurrencyManager:
# class CurrencyInfo:
# class CurrencyEncoder(NoIndentEncoder):
#     def __init__(self):
#     def init(self):
#     def load_base(self):
#     def load(self):
#     def save(self):
#     def compile(self, shorts=None, rates=None, overrides=None, last_update=None):
#     def needUpdate(self):
#     def update(self, force_update=False, accept_empty=False):
#             def get_count(currency):
#     def convert(self, amount, short):
#     def isPriceValid(self, price_str):
#     def toDisplayPrice(self, rate):
#     def toWhisper(self, short):
#     def toFull(self, short):
#     def _apply_override(self, key, val, overrides, path=None):
#     def _compile(self, rates, shorts, overrides):
#     def priceFromString(price):
#     def overridePriceFromString(override_price):
#     def isOverridePriceValid(self, override_price):
#     def isPriceRelative(override_price):
#     def compilePrice(self, override_price, base_price=None):
#     def clearCache(cls):
#     def fromCCM(self, ccm):
#     def toCCM(self):
#     def __init__(self, crates, cshorts):
#     def __init__(self):
#     def default(self, o):
# 
# Path: lib/Utility.py
# RE_COMPILED_TYPE = type(re.compile(''))
# POE_NINJA_API = 'http://api.poe.ninja/api/Data/'
#     CONFIG_FNAME = "cfg\\app.ini"
# class MsgType(IntEnum):
# class Messenger:
# class AppException(Exception):
# class CompileException(AppException):
# class AppConfiguration:
# class NoIndent(object):
# class NoIndentEncoder(json.JSONEncoder):
# class ConfidenceLevel(IntEnum):
#     def __init__(self):
#     def send_tmsg(self, msg, log_level=logging.NOTSET, tag=None):
#     def send_msg(self, msg, log_level=logging.NOTSET, timed=False, tag=None):
#     def send_stopped(self):
#     def send_update_id(self, id):
#     def send_object(self, obj):
#     def __init__(self):
#     def load(self):
#     def load_default(self):
#     def _load_settings(self, settings=None):
#     def update(self, cfg):
#     def save(self):
# def getBytesFromURL(url, handle=None, max_attempts=1, connect_timeout=None, timeout=None, gzip=True):
# def getJsonFromURL(url, handle=None, max_attempts=1, gzip=True):
# def getDataFromUrl(url, callback, max_attempts=1):
# def str2bool(val):
# def round_up(num):
# def round_down(num):
# def dround(num, ndigits=2):
# def tmsg(msg):
# def getBaseUrl(url):
# def isAbsoluteUrl(url):
# def logexception():
# def get_verror_msg(verror, data=None):
#     def __init__(self, value):
#     def __init__(self, *args, **kwargs):
#     def default(self, o):
#     def encode(self, o):
# def utc_to_local(utc_dt):
# def namify(text):
# def normalize_id(text):


import logging
from threading import Thread, Event
from lib.CurrencyManager import cm
from lib.Utility import AppException, msgr, logexception



class UpdateThread(Thread):
    def __init__(self, fm, interval):
        Thread.__init__(self)
        self.evt_stop = Event()
        self.fm = fm
        self.interval = interval

    def run(self):
        while not self.evt_stop.wait(self.interval):
            currency_updated = False
            filters_updated = False

            try:
                try:
                    cm.update()
                    # msgr.send_msg("Currency rates updated successfully.", logging.INFO)
                    currency_updated = True
                except AppException as e:
                    msgr.send_msg(e, logging.ERROR)

                try:
                    self.fm.fetchFromAPI()
                    # msgr.send_msg("Filters updated successfully.", logging.INFO)
                    filters_updated = True

# Path: lib/CurrencyManager.py
# _PRICE_REGEX = re.compile('\s*([0-9]+|[0-9]+\.[0-9]+)\s+([a-z\-]+)')
# _OVERRIDE_REGEX = re.compile('\s*([+\-*/]?)\s*(.+)')
# _NUMBER_REGEX = re.compile('[0-9]+(?:\.[0-9]+)?$')
# INVALID_OVERRIDE = "Invalid override price \'{}\' for {}"
# INVALID_OVERRIDE_RATE = "Invalid override rate \'{}\' = {} for {}. Rate must be a positive number"
# INVALID_PRICE = "Invalid price {}"
#     CURRENCY_FNAME = "cfg\\currency.json"
#     CURRENCY_BASE_FNAME = "res\\currency_base.json"
#     CURRENCY_API = [urljoin(POE_NINJA_API, "GetCurrencyOverview?league={}"),
#                     urljoin(POE_NINJA_API, "GetFragmentOverview?league={}")]
#     UPDATE_INTERVAL = 10  # minutes
#     DEFAULT_CONFIDENCE_LEVEL = ConfidenceLevel.Medium.value
#     CHAOS_NAME = 'Chaos Orb'
# class CurrencyManager:
# class CompiledCurrencyManager:
# class CurrencyInfo:
# class CurrencyEncoder(NoIndentEncoder):
#     def __init__(self):
#     def init(self):
#     def load_base(self):
#     def load(self):
#     def save(self):
#     def compile(self, shorts=None, rates=None, overrides=None, last_update=None):
#     def needUpdate(self):
#     def update(self, force_update=False, accept_empty=False):
#             def get_count(currency):
#     def convert(self, amount, short):
#     def isPriceValid(self, price_str):
#     def toDisplayPrice(self, rate):
#     def toWhisper(self, short):
#     def toFull(self, short):
#     def _apply_override(self, key, val, overrides, path=None):
#     def _compile(self, rates, shorts, overrides):
#     def priceFromString(price):
#     def overridePriceFromString(override_price):
#     def isOverridePriceValid(self, override_price):
#     def isPriceRelative(override_price):
#     def compilePrice(self, override_price, base_price=None):
#     def clearCache(cls):
#     def fromCCM(self, ccm):
#     def toCCM(self):
#     def __init__(self, crates, cshorts):
#     def __init__(self):
#     def default(self, o):
# 
# Path: lib/Utility.py
# RE_COMPILED_TYPE = type(re.compile(''))
# POE_NINJA_API = 'http://api.poe.ninja/api/Data/'
#     CONFIG_FNAME = "cfg\\app.ini"
# class MsgType(IntEnum):
# class Messenger:
# class AppException(Exception):
# class CompileException(AppException):
# class AppConfiguration:
# class NoIndent(object):
# class NoIndentEncoder(json.JSONEncoder):
# class ConfidenceLevel(IntEnum):
#     def __init__(self):
#     def send_tmsg(self, msg, log_level=logging.NOTSET, tag=None):
#     def send_msg(self, msg, log_level=logging.NOTSET, timed=False, tag=None):
#     def send_stopped(self):
#     def send_update_id(self, id):
#     def send_object(self, obj):
#     def __init__(self):
#     def load(self):
#     def load_default(self):
#     def _load_settings(self, settings=None):
#     def update(self, cfg):
#     def save(self):
# def getBytesFromURL(url, handle=None, max_attempts=1, connect_timeout=None, timeout=None, gzip=True):
# def getJsonFromURL(url, handle=None, max_attempts=1, gzip=True):
# def getDataFromUrl(url, callback, max_attempts=1):
# def str2bool(val):
# def round_up(num):
# def round_down(num):
# def dround(num, ndigits=2):
# def tmsg(msg):
# def getBaseUrl(url):
# def isAbsoluteUrl(url):
# def logexception():
# def get_verror_msg(verror, data=None):
#     def __init__(self, value):
#     def __init__(self, *args, **kwargs):
#     def default(self, o):
#     def encode(self, o):
# def utc_to_local(utc_dt):
# def namify(text):
# def normalize_id(text):


# Path: lib/UpdateThread.py
import logging
from threading import Thread, Event
from lib.CurrencyManager import cm
from lib.Utility import AppException, msgr, logexception




class UpdateThread(Thread):
    def __init__(self, fm, interval):
        Thread.__init__(self)
        self.evt_stop = Event()
        self.fm = fm
        self.interval = interval

    def run(self):
        while not self.evt_stop.wait(self.interval):
            currency_updated = False
            filters_updated = False

            try:
                try:
                    cm.update()
                    # msgr.send_msg("Currency rates updated successfully.", logging.INFO)
                    currency_updated = True
                except AppException as e:
                    msgr.send_msg(e, logging.ERROR)

                try:
                    self.fm.fetchFromAPI()
                    # msgr.send_msg("Filters updated successfully.", logging.INFO)
                    filters_updated = True

                except AppException as e: