Example #1
0
import asyncio
import re
from decimal import Decimal, InvalidOperation

import requests

from obrbot import hook
from obrbot.util.dictionaries import CaseInsensitiveDict

plugin_info = {
    "plugin_category": "channel-specific",
    "command_category_name": "DogeStorm"
}

url = "http://coinmill.com/frame.js"
currency_rates = CaseInsensitiveDict()
currency_units = CaseInsensitiveDict(
)  # this will be ignored, at least for now


@asyncio.coroutine
@hook.on_start()
def load_rates():
    regex = re.compile(r"var currency_data=\'([0-9a-zA-Z,\.\|\-]+)\';")
    response = requests.get(url)
    match = regex.match(response.text)
    if not match:
        raise ValueError("Unmatched data: {} Please update!".format(
            response.text))
    data = match.group(1)
    assert isinstance(data, str)  # for pycharm