Browse Source
Easier and better because you can pass in everything you need without having to deal with decorators which after a look at are quite complicated to play with.pull/8/head
Luke Murphy
5 years ago
5 changed files with 21 additions and 70 deletions
@ -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 |
|||
|
@ -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'] |
@ -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 |
Loading…
Reference in new issue