# 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 json
import pycurl
import re
import threading
from datetime import datetime, timedelta
from json import JSONEncoder
from urllib.parse import urljoin
from lib.Utility import getJsonFromURL, AppException, config, NoIndent, NoIndentEncoder, logexception, msgr, \
    utc_to_local, CompileException, ConfidenceLevel, POE_NINJA_API
        except AppException:
            raise
        except (KeyError, ValueError) as e:
            raise AppException("Currency update failed. Parsing error: {}".format(e))
        except Exception as e:
            logexception()
            raise AppException("Currency update failed. Unexpected error: {}".format(e))

    def convert(self, amount, short):
        if short in self.cshorts:
            currency = self.cshorts[short]
            if currency == self.CHAOS_NAME:
                return amount
            if currency in self.crates:
                return amount * self.crates[self.cshorts[short]]
        return 0

    def isPriceValid(self, price_str):
        price = CurrencyManager.priceFromString(price_str)
        if price is None:
            return False
        return price[1] in self.cshorts

    def toDisplayPrice(self, rate):
        ex_val = self.convert(1, 'exalted')
        if 0 < ex_val <= rate:
            rate = round(rate / ex_val, 2)
            if rate == int(rate): rate = int(rate)
            price = '{} ex'.format(rate)
        else:

# 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/CurrencyManager.py
import json
import pycurl
import re
import threading
from datetime import datetime, timedelta
from json import JSONEncoder
from urllib.parse import urljoin
from lib.Utility import getJsonFromURL, AppException, config, NoIndent, NoIndentEncoder, logexception, msgr, \
    utc_to_local, CompileException, ConfidenceLevel, POE_NINJA_API

        except AppException:
            raise
        except (KeyError, ValueError) as e:
            raise AppException("Currency update failed. Parsing error: {}".format(e))
        except Exception as e:
            logexception()
            raise AppException("Currency update failed. Unexpected error: {}".format(e))

    def convert(self, amount, short):
        if short in self.cshorts:
            currency = self.cshorts[short]
            if currency == self.CHAOS_NAME:
                return amount
            if currency in self.crates:
                return amount * self.crates[self.cshorts[short]]
        return 0

    def isPriceValid(self, price_str):
        price = CurrencyManager.priceFromString(price_str)
        if price is None:
            return False
        return price[1] in self.cshorts

    def toDisplayPrice(self, rate):
        ex_val = self.convert(1, 'exalted')
        if 0 < ex_val <= rate:
            rate = round(rate / ex_val, 2)
            if rate == int(rate): rate = int(rate)
            price = '{} ex'.format(rate)
        else:

            price = '{:.0f}c'.format(rate)