diff options
author | makefu <github@syntax-fehler.de> | 2020-03-11 21:26:18 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2020-03-11 21:26:18 +0100 |
commit | f63c4d3b4bbcae173f8ef27f0f62b7d48dace6b1 (patch) | |
tree | 1597c9d787e490b31685887b72bfad308116c8e8 /ebknotify | |
parent | 1ab0949f9d8e97aafafbd347a625fd97eeaa48a3 (diff) |
ebk-raw: init
Diffstat (limited to 'ebknotify')
-rw-r--r-- | ebknotify/raw.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/ebknotify/raw.py b/ebknotify/raw.py new file mode 100644 index 0000000..5e4adfd --- /dev/null +++ b/ebknotify/raw.py @@ -0,0 +1,52 @@ +""" usage: ebk-raw [options] CONFIG URLPATH [PARAMS...] + +options: + --lol=LOL Log Level [Default: INFO] + --method=METHOD HTTP Method to use [Default: GET] + --xml do not try to decode as json but xml instead + +PARAMS are the parameters sent via http method to URLPATH + +examples: + ebk-raw ebk.yml /ads/search-metadata.json + ebk-raw ebk.yml --xml /ads/search-metadata + ebk-raw ebk.yml /ads.json categoryId=216 zipcode=70435 distance=50 distanceUnit=KM +""" +from docopt import docopt +from .client import EbkClient +import yaml +import json +import dateutil +import logging +from .common import set_lol + +log = logging.getLogger('ebk-raw') + +def create_params(cliparams): + kv = {} + for param in cliparams: + k,v = param.split("=",1) + kv[k] = v + return kv + +def main(): + args = docopt(__doc__) + set_lol(args['--lol'],log) + suffix = args['URLPATH'] + + config = yaml.safe_load(open(args['CONFIG'])) + api = EbkClient(config['main']['appid'], + config['main']['apppw'], + config['main']['userid'], + config['main']['userpw'] + ) + params = create_params(args['PARAMS'] or []) + + if args['--method'] == 'GET': + ret = api._http_get(suffix,params) + + if args['--xml']: + import xml.dom.minidom + print(xml.dom.minidom.parseString(ret.content).toprettyxml()) + else: + print(json.dumps(ret.json(),indent=4)) |