-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_json.py
More file actions
43 lines (30 loc) · 1.19 KB
/
get_json.py
File metadata and controls
43 lines (30 loc) · 1.19 KB
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
import requests, urllib
import os, sys
import json
import logging
from json_cli import json_cli
#----------------- Logger import ---------------------------------
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
#------------------Functions--------------------------------------
def load_file(data_file):
with open(data_file) as infile:
return json.load(infile)
PARAMETERS_STRING = "parameters"
URL_STRING = 'url'
SEARCH_TERM_STRING='search_term'
PARAMETERS_FILE = 'get_json.txt'
if __name__ == "__main__":
from simple_parameters import simple_parameters
parser = simple_parameters.SimpleParser(PARAMETERS_FILE )
(options, args) = parser.resolve_parameters(sys.argv)
logger.debug("Input parameters:{}".format(args))
if os.path.isfile(options.file):
data = load_file(str(options.file))
parameters = data[PARAMETERS_STRING]
if args[1:]:
parameters[data[SEARCH_TERM_STRING]] = str(args[1:]).strip('[]\'')
url = data[URL_STRING]
url += urllib.parse.urlencode(parameters)
show_result = json_cli()
show_result.load_data(requests.get(url).json())