diff --git a/README.md b/README.md index d386d9c..90732c1 100644 --- a/README.md +++ b/README.md @@ -123,18 +123,15 @@ The settings are placed in a file called `.etherpump/settings.json` and are used Library API Example ------------------- -Etherpump can be used as a library: +Etherpump can be used as a library. -```python -from etherpump.api import magicword +All commands can be imported and run programmatically. -@magicword('__VARIA_PUB_CLUB__') -def do_things_with_the_pad_contents(pads): - print(pads['my-pad-name']['html']) +```python +>>> from etherpump.api import pull +>>> pull(['--all', '--publish-opt-in', '--publish', '__PUB_CLUB__']) ``` -This is still a work in progress. - Subcommands ---------- diff --git a/etherpump/__init__.py b/etherpump/__init__.py index 2b2d78e..36f26e1 100644 --- a/etherpump/__init__.py +++ b/etherpump/__init__.py @@ -2,4 +2,4 @@ import os DATAPATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "data") -__VERSION__ = '0.0.6' +__VERSION__ = '0.0.7' diff --git a/etherpump/api/__init__.py b/etherpump/api/__init__.py index efb7cde..0c06b93 100644 --- a/etherpump/api/__init__.py +++ b/etherpump/api/__init__.py @@ -1 +1,15 @@ -from etherpump.api.magicword import magicword # noqa +from etherpump.commands.creatediffhtml import main as creatediffhtml # noqa +from etherpump.commands.deletepad import main as deletepad # noqa +from etherpump.commands.dumpcsv import main as dumpcsv # noqa +from etherpump.commands.gethtml import main as gethtml # noqa +from etherpump.commands.gettext import main as gettext # noqa +from etherpump.commands.index import main as index # noqa +from etherpump.commands.init import main as init # noqa +from etherpump.commands.list import main as list # noqa +from etherpump.commands.listauthors import main as listauthors # noqa +from etherpump.commands.publication import main as publication # noqa +from etherpump.commands.pull import main as pull # noqa +from etherpump.commands.revisionscount import main as revisionscount # noqa +from etherpump.commands.sethtml import main as sethtml # noqa +from etherpump.commands.settext import main as settext # noqa +from etherpump.commands.showmeta import main as showmeta # noqa diff --git a/etherpump/api/_utils.py b/etherpump/api/_utils.py deleted file mode 100644 index eb3e026..0000000 --- a/etherpump/api/_utils.py +++ /dev/null @@ -1,23 +0,0 @@ -"""Utilities for API functions.""" - -from pathlib import Path -from urllib.parse import urlencode - -from etherpump.commands.common import getjson, loadpadinfo -from etherpump.commands.init import main - - -def ensure_init(): - """Ensure etherpump has already been init'd.""" - try: - main([]) - except SystemExit: - pass - - -def get_pad_ids(): - """Retrieve all available pad ids.""" - info = loadpadinfo(Path('.etherpump/settings.json')) - data = {'apikey': info['apikey']} - url = info['localapiurl'] + 'listAllPads?' + urlencode(data) - return getjson(url)['data']['padIDs'] diff --git a/etherpump/api/magicword.py b/etherpump/api/magicword.py deleted file mode 100644 index 8be20e6..0000000 --- a/etherpump/api/magicword.py +++ /dev/null @@ -1,37 +0,0 @@ -"""API for programming against pads marked with __MAGIC_WORDS__.""" - -__all__ = ['magicword'] - -import json -from pathlib import Path - -from etherpump.api._utils import ensure_init, get_pad_ids -from etherpump.commands.pull import main as pull - - -def magicword(word): - """Decorator for handling magic words.""" - - ensure_init() - pull(['--all', '--publish-opt-in', '--publish', word]) - - pads = {} - for pad_id in get_pad_ids(): - pads[pad_id] = {} - try: - pads[pad_id]['html'] = open(Path(f'./p/{pad_id}.raw.html')).read() - pads[pad_id]['txt'] = open(Path(f'./p/{pad_id}.raw.txt')).read() - pads[pad_id]['meta'] = json.loads( - open(Path(f'./p/{pad_id}.meta.json')).read() - ) - pads[pad_id]['dhtml'] = open(Path(f'./p/{pad_id}.raw.dhtml')).read() - except FileNotFoundError: - pass - - def wrap(userfunc): - def wrappedf(*args): - userfunc(pads) - - return wrappedf - - return wrap