-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
40 lines (33 loc) · 932 Bytes
/
utils.py
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
import glob, requests, json
def make_data_request(url, data):
"""
Post textual data and return json
:param url: url to send to
:param data: textual payload
:return: json response
"""
resp = requests.post(url, data=data).json()
return resp
def get_tranql_queries(root_dir):
"""
Returns set of files in root_dir
:param root_dir: path to get files from
:return: list of files
"""
# Remove trailing path sep
root_dir = root_dir.rstrip('/').rstrip('\\')
files = glob.glob(f'{root_dir}/*')
queries = []
for f in files:
with open(f) as stream:
queries.append((f, stream.read()))
return queries
def write_out_response(file_name, data):
"""
Writes json to file
:param file_name: output file name
:param data: to write
:return:
"""
with open(file_name, 'w') as stream:
json.dump(data, stream, indent=2)