From 6d30861c1eac59572fadfb9deec5c9afcf47e283 Mon Sep 17 00:00:00 2001 From: David McMackins II Date: Thu, 27 Aug 2015 21:14:44 -0500 Subject: Change to plugin-based system --- README | 28 ++++++++--- bterfetch | 25 --------- cccfetch | 25 --------- cfetch/__init__.py | 128 ++++++++++++++++++++++++++++++++++++++++++++++ cfetch/plugins/btce.py | 21 ++++++++ cfetch/plugins/bter.py | 25 +++++++++ cfetch/plugins/ccc.py | 28 +++++++++++ coinfetch | 53 +++++++++++++++++-- coinfetch.py | 128 ---------------------------------------------- coinfetchapi.py | 134 ------------------------------------------------- plugins/btc-e.py | 21 -------- plugins/bter.py | 25 --------- plugins/ccc.py | 28 ----------- setup.py | 15 ++++-- 14 files changed, 282 insertions(+), 402 deletions(-) delete mode 100755 bterfetch delete mode 100755 cccfetch create mode 100644 cfetch/__init__.py create mode 100644 cfetch/plugins/btce.py create mode 100644 cfetch/plugins/bter.py create mode 100644 cfetch/plugins/ccc.py delete mode 100644 coinfetch.py delete mode 100644 coinfetchapi.py delete mode 100644 plugins/btc-e.py delete mode 100644 plugins/bter.py delete mode 100644 plugins/ccc.py diff --git a/README b/README index 5037312..b4bc124 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -coinfetch +Coinfetch ========= See [INSTALL](INSTALL) for installation instructions. @@ -36,15 +36,29 @@ Example: `$ coinfetch -a bter usd doge` The above example will be the same as calling `coinfetch usd doge` in version 2.x, which used the BTer API. The default API is BTC-E. +Installing Plugins +------------------ + +Plugins are read from a number of directories. Currently, these are: + +- `cfetch/plugins` located in this source repository and installed to the +system after installation. +- `/usr/share/coinfetch/plugins` on Unix-like operating systems. +- The `.coinfetch/plugins` directory in the user's home directory. + +Any file ending in `.py` will be loaded using Python standard `import` +logic. No functions will be executed by `coinfetch` directly. You must execute +them at the global level if needed. See the default plugins in `cfetch/plugins` +for examples of simple working plugins. + Note ---- -Version 5.x is currently in development. This will change the program from a -static API/CLI to a plugin-based system with an API for external applications -as well as the familiar CLI. The advantage of this new design is to allow -hackers to add new APIs to Coinfetch without having to submit upstream -requests. Officially-supported ticker APIs will stay in this repository to keep -things easy for existing Coinfetch users. +Version 5.x changes the program from a static API/CLI to a plugin-based system +with an API for external applications as well as the familiar CLI. The +advantage of this new design is to allow hackers to add new APIs to Coinfetch +without having to submit upstream requests. Officially-supported ticker APIs +will stay in this repository to keep things easy for existing Coinfetch users. BTer's ticker (as of this update) does not seem to be updating often enough to have accurate data. Version 4.1.x adds the CryptoCoin Charts (ccc) API which diff --git a/bterfetch b/bterfetch deleted file mode 100755 index b272391..0000000 --- a/bterfetch +++ /dev/null @@ -1,25 +0,0 @@ -#! /usr/bin/env python3 -## -## coinfetch - Cryptocurrency price fetcher -## Copyright (C) 2015 Delwink, LLC -## -## This program is free software: you can redistribute it and/or modify -## it under the terms of the GNU Affero General Public License as published by -## the Free Software Foundation, version 3 only. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU Affero General Public License for more details. -## -## You should have received a copy of the GNU Affero General Public License -## along with this program. If not, see . -## - -from sys import argv -from coinfetchapi import * - -try: - coinfetch(['--api=bter'] + argv[1:]) -except UsageException as e: - print_usage(e) diff --git a/cccfetch b/cccfetch deleted file mode 100755 index d0bf3ce..0000000 --- a/cccfetch +++ /dev/null @@ -1,25 +0,0 @@ -#! /usr/bin/env python3 -## -## coinfetch - Cryptocurrency price fetcher -## Copyright (C) 2015 Delwink, LLC -## -## This program is free software: you can redistribute it and/or modify -## it under the terms of the GNU Affero General Public License as published by -## the Free Software Foundation, version 3 only. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU Affero General Public License for more details. -## -## You should have received a copy of the GNU Affero General Public License -## along with this program. If not, see . -## - -from sys import argv -from coinfetchapi import * - -try: - coinfetch(['--api=ccc'] + argv[1:]) -except UsageException as e: - print_usage(e) diff --git a/cfetch/__init__.py b/cfetch/__init__.py new file mode 100644 index 0000000..33c33d2 --- /dev/null +++ b/cfetch/__init__.py @@ -0,0 +1,128 @@ +## +## coinfetch - plugin-based cryptocurrency price converter +## Copyright (C) 2015 Delwink, LLC +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU Affero General Public License as published by +## the Free Software Foundation, version 3 only. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU Affero General Public License for more details. +## +## You should have received a copy of the GNU Affero General Public License +## along with this program. If not, see . +## + +from importlib.machinery import SourceFileLoader +from os import listdir +from os.path import basename, dirname, exists, expanduser, isdir, join, realpath +from requests import get + +__version__ = '5.0.0' + +## A cryptocurrency exchange rate ticker. +class Ticker(): + ## Constructor for this class. + # @param path The URL prefix for this ticker. + # @param kind Which type of exchange rate to fetch. + def __init__(self, path, kind='avg'): + self.path = path + self.kind = kind + + ## Defines how a currency pair is defined in the request URL. + # @param a The first currency. + # @param b The second currency. + # @return A pair string to be used in the request URL. + def get_pair(self, a, b): + return '{}_{}'.format(a, b) + + ## Extracts the exchange rate data from the server response. + # @param response Original response from the ticker server. + # @param The coin pair as a list/tuple. + # @return The data for the selected pair. + def get_pair_data(self, response, pair): + return response.json()[self.get_pair(pair[0], pair[1])] + + ## Calculates the exchange rate between two currencies. + # @param a The first currency. + # @param b The second currency. + # @param amt The number quantity of 'a' currency. + def get_rate(self, a, b, amt=1): + r = get(self.path + self.get_pair(a, b)) + + try: + res = self.get_pair_data(r, (a, b)) + return float(res[self.kind]) * amt + except (KeyError, TypeError): + try: + r = get(self.path + self.get_pair(b, a)) # reverse order + + res = self.get_pair_data(r, (a, b)) + return (float(res[self.kind]) ** -1) * amt + except (KeyError, TypeError) as e: + raise ValueError(str(e)) # currency pair not found + +_INDEX = { + 'description': 0, + 'value': 1 +} + +_PATH = [ + dirname(realpath(__file__)), + '/usr/share/coinfetch', + join(expanduser('~'), '.coinfetch') +] + +_tickers = {} + +## Adds a directory to the configuration path. +# @param path The directory to be added. +def add_to_path(path): + _PATH.append(path) + +## Gets the registered tickers and their descriptions. +# @return A list of tuples containing the ticker name and description. +def get_registered_tickers(): + lst = [] + + for key in _tickers: + lst.append((key, _tickers[key][_INDEX['description']])) + + return lst + +## Gets a particular ticker object. +# @param key Name of the desired ticker. +# @return The Ticker object specified by 'key'. +def get_ticker(key): + return _tickers[key][_INDEX['value']] + +## Registers a new ticker API. +# @param name Name of this ticker. +# @param description A brief description of this ticker. +# @param obj An instance of the ticker's implementation class. +def register_ticker(name, description, obj): + _tickers[name] = (description, obj) + +## Loads a plugin or directory of plugins. +# @param path Path to the plugin file or a directory containing plugins. +def load(path): + if isdir(path): + for f in listdir(path): + if f.endswith('.py'): + load(join(path, f)) + else: + SourceFileLoader('plugin', path).load_module() + +## Loads all default plugins. +def load_default_plugins(): + for d in _PATH: + plugindir = join(d, 'plugins') + if exists(plugindir): + load(plugindir) + +## Clears the list of loaded plugins. +def unload_plugins(): + global _tickers + _tickers = {} diff --git a/cfetch/plugins/btce.py b/cfetch/plugins/btce.py new file mode 100644 index 0000000..e3d6be0 --- /dev/null +++ b/cfetch/plugins/btce.py @@ -0,0 +1,21 @@ +## +## coinfetch-api-btce - BTC-E API plugin for coinfetch +## Copyright (C) 2015 Delwink, LLC +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU Affero General Public License as published by +## the Free Software Foundation, version 3 only. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU Affero General Public License for more details. +## +## You should have received a copy of the GNU Affero General Public License +## along with this program. If not, see . +## + +from cfetch import register_ticker, Ticker + +register_ticker('btce', 'The BTC-E ticker', + Ticker('https://btc-e.com/api/3/ticker/')) diff --git a/cfetch/plugins/bter.py b/cfetch/plugins/bter.py new file mode 100644 index 0000000..8bfbe8a --- /dev/null +++ b/cfetch/plugins/bter.py @@ -0,0 +1,25 @@ +## +## coinfetch-api-bter - BTer API plugin for coinfetch +## Copyright (C) 2015 Delwink, LLC +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU Affero General Public License as published by +## the Free Software Foundation, version 3 only. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU Affero General Public License for more details. +## +## You should have received a copy of the GNU Affero General Public License +## along with this program. If not, see . +## + +from cfetch import register_ticker, Ticker + +class BterTicker(Ticker): + def get_pair_data(self, response, pair=None): + return response.json() + +register_ticker('bter', 'The BTer ticker', + BterTicker('http://data.bter.com/api/1/ticker/')) diff --git a/cfetch/plugins/ccc.py b/cfetch/plugins/ccc.py new file mode 100644 index 0000000..3f9ffde --- /dev/null +++ b/cfetch/plugins/ccc.py @@ -0,0 +1,28 @@ +## +## coinfetch-api-ccc - CryptoCoin Charts API plugin for coinfetch +## Copyright (C) 2015 Delwink, LLC +## +## This program is free software: you can redistribute it and/or modify +## it under the terms of the GNU Affero General Public License as published by +## the Free Software Foundation, version 3 only. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU Affero General Public License for more details. +## +## You should have received a copy of the GNU Affero General Public License +## along with this program. If not, see . +## + +from cfetch import register_ticker, Ticker + +class CccTicker(Ticker): + def __init__(self, path, kind='price'): + super().__init__(path, kind) + + def get_pair_data(self, response, pair=None): + return response.json() + +register_ticker('ccc', 'The CryptoCoin Charts ticker', + CccTicker('http://api.cryptocoincharts.info/tradingPair/')) diff --git a/coinfetch b/coinfetch index c38f7d0..ec9b7fa 100755 --- a/coinfetch +++ b/coinfetch @@ -16,10 +16,53 @@ ## along with this program. If not, see . ## -from sys import argv -from coinfetchapi import * +from argparse import Action, ArgumentParser +from cfetch import __version__, get_ticker, get_registered_tickers +from cfetch import load_default_plugins + +__title__ = 'coinfetch' +__author__ = 'David McMackins II' +__version_info__ = '''{} {} +Copyright (C) 2015 Delwink, LLC +License AGPLv3: GNU AGPL version 3 only . +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. + +Written by {}'''.format(__title__, __version__, __author__) + +class VersionAction(Action): + def __call__(self, parser, values, namespace, option_string): + print(__version_info__) + exit(0) + +cli = ArgumentParser(__title__) + +cli.add_argument('-a', '--api', default='btce', help='uses an API by name') +cli.add_argument('-k', '--kind', help='specifies which kind of rate to get') +cli.add_argument('-v', '--version', action=VersionAction, + help='show version information and exit', nargs=0) + +cli.add_argument('amount', default=1, help='amount of the original currency', + nargs='?', type=int) +cli.add_argument('src', help='currency from which to convert') +cli.add_argument('dest', help='currency to which to convert') + +args = cli.parse_args() + +load_default_plugins() try: - coinfetch(argv[1:]) -except UsageException as e: - print_usage(e) + print('%.8f' %get_ticker(args.api).get_rate(args.src, args.dest, args.amount)) +except KeyError: + print('The API {} is not available. Currently installed APIs:'.format(args.api)) + + tickers = get_registered_tickers() + tickers.sort() + for api, desc in tickers: + print(api + '\t- ' + desc) + + exit(10) +except ValueError: + pair = '/'.join([args.src, args.dest]) + print('The pair {} was not found using the {} API.'.format(pair, args.api)) + exit (11) diff --git a/coinfetch.py b/coinfetch.py deleted file mode 100644 index 1570c28..0000000 --- a/coinfetch.py +++ /dev/null @@ -1,128 +0,0 @@ -## -## coinfetch - plugin-based cryptocurrency price converter -## Copyright (C) 2015 Delwink, LLC -## -## This program is free software: you can redistribute it and/or modify -## it under the terms of the GNU Affero General Public License as published by -## the Free Software Foundation, version 3 only. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU Affero General Public License for more details. -## -## You should have received a copy of the GNU Affero General Public License -## along with this program. If not, see . -## - -from os import listdir -from os.path import dirname, exists, expanduser, isdir, join, realpath -from requests import get - -__version__ = '5.0.0' - -## A cryptocurrency exchange rate ticker. -class Ticker(): - ## Constructor for this class. - # @param path The URL prefix for this ticker. - # @param kind Which type of exchange rate to fetch. - def __init__(self, path, kind='avg'): - self.path = path - self.kind = kind - - ## Defines how a currency pair is defined in the request URL. - # @param a The first currency. - # @param b The second currency. - # @return A pair string to be used in the request URL. - def get_pair(self, a, b): - return '{}_{}'.format(a, b) - - ## Extracts the exchange rate data from the server response. - # @param response Original response from the ticker server. - # @param The coin pair as a list/tuple. - # @return The data for the selected pair. - def get_pair_data(self, response, pair): - return response.json()[self.get_pair(pair[0], pair[1])] - - ## Calculates the exchange rate between two currencies. - # @param a The first currency. - # @param b The second currency. - # @param amt The number quantity of 'a' currency. - def get_rate(self, a, b, amt=1): - r = get(self.path + self.get_pair(a, b)) - - try: - res = self.get_pair_data(r, (a, b)) - return float(res[self.kind]) * amt - except (KeyError, TypeError): - try: - r = get(self.path + self.get_pair(b, a)) # reverse order - - res = self.get_pair_data(r, (a, b)) - return (float(res[self.kind]) ** -1) * amt - except (KeyError, TypeError) as e: - raise ValueError(str(e)) # currency pair not found - -_INDEX = { - 'description': 0, - 'value': 1 -} - -_PATH = [ - dirname(realpath(__file__)), - '/usr/share/coinfetch', - join(expanduser('~'), '.coinfetch') -] - -_tickers = {} - -## Adds a directory to the configuration path. -# @param path The directory to be added. -def add_to_path(path): - _PATH.append(path) - -## Gets the registered tickers and their descriptions. -# @return A list of tuples containing the ticker name and description. -def get_registered_tickers(): - lst = [] - - for key in _tickers: - lst.append((key, _tickers[key][_INDEX['description']])) - - return lst - -## Gets a particular ticker object. -# @param key Name of the desired ticker. -# @return The Ticker object specified by 'key'. -def get_ticker(key): - return _tickers[key][_INDEX['value']] - -## Registers a new ticker API. -# @param name Name of this ticker. -# @param description A brief description of this ticker. -# @param obj An instance of the ticker's implementation class. -def register_ticker(name, description, obj): - _tickers[name] = (description, obj) - -## Loads a plugin or directory of plugins. -# @param path Path to the plugin file or a directory containing plugins. -def load(path): - if isdir(path): - for f in listdir(path): - if f.endswith('.py'): - load(join(path, f)) - else: - with open(path) as plugin: - exec(plugin.read(), globals(), locals()) - -## Loads all default plugins. -def load_default_plugins(): - for d in _PATH: - plugindir = join(d, 'plugins') - if exists(plugindir): - load(plugindir) - -## Clears the list of loaded plugins. -def unload_plugins(): - global _tickers - _tickers = {} diff --git a/coinfetchapi.py b/coinfetchapi.py deleted file mode 100644 index 0ea809f..0000000 --- a/coinfetchapi.py +++ /dev/null @@ -1,134 +0,0 @@ -#! /usr/bin/env python3 -## -## coinfetchapi - API module for coinfetch -## Copyright (C) 2015 Delwink, LLC -## -## This program is free software: you can redistribute it and/or modify -## it under the terms of the GNU Affero General Public License as published by -## the Free Software Foundation, version 3 only. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU Affero General Public License for more details. -## -## You should have received a copy of the GNU Affero General Public License -## along with this program. If not, see . -## - -from requests import get -from getopt import getopt -from sys import stderr - -__version__ = '4.1.1' - -USAGE_INFO = ''' -USAGE: coinfetch [OPTIONS] [AMOUNT] FROM TO - -coinfetch will print the solution for x in the following equation: - - AMOUNT * FROM = x * TO - -OPTIONS: - -h, --help Prints this help message. - -v, --version Outputs version information and exits. - -a, --api=Y Uses the API specified by Y. - -k, --kind=Z Gets the Z kind of exchange rate. - -Supported APIs: - btce BTC-E, the default API. - bter BTer, the legacy API. - ccc CryptoCoin Charts. - -Kinds: - avg Average rate, the default. - high The high rate. - low The low rate. - last The last exchange amount. - -Examples: - coinfetch -k high btc usd # gets the high rate for Bitcoin to USD - coinfetch -a bter usd doge # gets the average Dogecoin to USD conversion -''' - -class UsageException(Exception): - pass - -def print_usage(e): - print(USAGE_INFO) - exit(int(str(e))) - -def _keypair(api, r, pair): - if api in ('btce'): - return r.json()[pair] - elif api in ('bter', 'ccc'): - return r.json() - - raise ValueError('API %s not supported.' %api) - -def get_rate(coin_a, coin_b, amt, api, kind): - if api == 'btce': - url = 'https://btc-e.com/api/3/ticker/' - elif api == 'bter': - url = 'http://data.bter.com/api/1/ticker/' - elif api == 'ccc': - url = 'http://api.cryptocoincharts.info/tradingPair/' - if kind == 'avg': - kind = 'price' - else: - raise ValueError('kind %s not supported with API %s' %(kind, api)) - else: - raise ValueError('API %s not supported.' %api) - - pair = '%s_%s' %(coin_a, coin_b) - - r = get(url + pair) - - try: - res = _keypair(api, r, pair) - return float(res[kind]) * amt - except (KeyError, TypeError): - try: - pair = '%s_%s' %(coin_b, coin_a) - r = get(url + pair) - - res = _keypair(api, r, pair) - return (float(res[kind]) ** -1) * amt - except TypeError as e: - raise ValueError('currency pair not found: %s' %str(e)) - -def coinfetch(args): - api = 'btce' - kind = 'avg' - opts, args = getopt(args, "hva:k:", ['help', 'version', 'api=', 'kind=']) - - for key, value in opts: - if key in ('-h', '--help'): - raise UsageException(0) - elif key in ('-v', '--version'): - print('''coinfetch 4.1.1 -Copyright (C) 2015 Delwink, LLC -License AGPLv3: GNU AGPL version 3 only . -This is free software: you are free to change and redistribute it. -There is NO WARRANTY, to the extent permitted by law. - -Written by David McMackins II''') - exit(0) - elif key in ('-a', '--api'): - api = value - elif key in ('-k', '--kind'): - kind = value - - bump = 1 if len(args) == 3 else 0 - amt = float(args[0]) if len(args) == 3 else 1.0 - - try: - print('%.8f' %get_rate(args[bump], args[1+bump], amt, api, kind)) - except IndexError: - raise UsageException(1) - except KeyError as e: - print('coinfetch: currency pair not found: %s' %str(e), file=stderr) - exit(2) - except ValueError as e: - print('coinfetch: %s' %str(e), file=stderr) - exit(3) diff --git a/plugins/btc-e.py b/plugins/btc-e.py deleted file mode 100644 index fc9b141..0000000 --- a/plugins/btc-e.py +++ /dev/null @@ -1,21 +0,0 @@ -## -## coinfetch-api-btce - BTC-E API plugin for coinfetch -## Copyright (C) 2015 Delwink, LLC -## -## This program is free software: you can redistribute it and/or modify -## it under the terms of the GNU Affero General Public License as published by -## the Free Software Foundation, version 3 only. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU Affero General Public License for more details. -## -## You should have received a copy of the GNU Affero General Public License -## along with this program. If not, see . -## - -from coinfetch import register_ticker, Ticker - -register_ticker('btce', 'The BTC-E ticker', - Ticker('https://btc-e.com/api/3/ticker/')) diff --git a/plugins/bter.py b/plugins/bter.py deleted file mode 100644 index 7a62368..0000000 --- a/plugins/bter.py +++ /dev/null @@ -1,25 +0,0 @@ -## -## coinfetch-api-bter - BTer API plugin for coinfetch -## Copyright (C) 2015 Delwink, LLC -## -## This program is free software: you can redistribute it and/or modify -## it under the terms of the GNU Affero General Public License as published by -## the Free Software Foundation, version 3 only. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU Affero General Public License for more details. -## -## You should have received a copy of the GNU Affero General Public License -## along with this program. If not, see . -## - -from coinfetch import register_ticker, Ticker - -class BterTicker(Ticker): - def get_pair_data(self, response, pair=None): - return response.json() - -register_ticker('bter', 'The BTer ticker', - BterTicker('http://data.bter.com/api/1/ticker/')) diff --git a/plugins/ccc.py b/plugins/ccc.py deleted file mode 100644 index 6da59e4..0000000 --- a/plugins/ccc.py +++ /dev/null @@ -1,28 +0,0 @@ -## -## coinfetch-api-ccc - CryptoCoin Charts API plugin for coinfetch -## Copyright (C) 2015 Delwink, LLC -## -## This program is free software: you can redistribute it and/or modify -## it under the terms of the GNU Affero General Public License as published by -## the Free Software Foundation, version 3 only. -## -## This program is distributed in the hope that it will be useful, -## but WITHOUT ANY WARRANTY; without even the implied warranty of -## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -## GNU Affero General Public License for more details. -## -## You should have received a copy of the GNU Affero General Public License -## along with this program. If not, see . -## - -from coinfetch import register_ticker, Ticker - -class CccTicker(Ticker): - def __init__(self, path, kind='price'): - super().__init__(path, kind) - - def get_pair_data(self, response, pair=None): - return response.json() - -register_ticker('ccc', 'The CryptoCoin Charts ticker', - CccTicker('http://api.cryptocoincharts.info/tradingPair/')) diff --git a/setup.py b/setup.py index ef6ca41..ba7382d 100644 --- a/setup.py +++ b/setup.py @@ -1,22 +1,29 @@ import re +from os.path import dirname, realpath from setuptools import setup version = '' -with open('coinfetchapi.py', 'r') as f: +with open('cfetch/__init__.py', 'r') as f: version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]', f.read(), re.MULTILINE).group(1) setup( name = 'coinfetch', version = version, - scripts = ['coinfetch', 'bterfetch', 'cccfetch'], - py_modules = ['coinfetchapi'], + scripts = ['coinfetch'], + packages = ['cfetch'], + + package_dir = { + 'cfetch': 'cfetch' + }, install_requires = ['requests'], package_data = { - '': ['README'] + '': ['README'], + 'cfetch': ['plugins/*.py'] }, + include_package_data=True, author = 'Delwink, LLC', author_email = 'support@delwink.com', -- cgit v1.2.3