blob: 36fb6a503d91add542252ac4e651230951aaccd0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
""" usage: ebk-raw [options] URLPATH [PARAMS...]
options:
--lol=LOL Log Level [Default: INFO]
--method=METHOD HTTP Method to use [Default: GET]
--config=FILE Path to config file [Default: ~/.config/ebk-notify/ebk.yml]
--xml do not try to decode as json but xml instead
PARAMS are the parameters sent via http method to URLPATH
examples:
ebk-raw /ads/search-metadata.json
ebk-raw --xml /ads/search-metadata
ebk-raw /ads.json categoryId=216 zipcode=70435 distance=50 distanceUnit=KM
"""
from docopt import docopt
from .client import EbkClient
import json
import dateutil
import logging
from .common import set_lol,load_config
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 = load_config(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))
|