forked from stormliucong/eMERGE-Columbia-Data-Sync-Service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta_data_export.py
43 lines (35 loc) · 1.2 KB
/
meta_data_export.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
40
41
42
import requests
import json
from pprint import pprint
from datetime import datetime
import pandas as pd
from io import StringIO
api_token_file = './api_tokens.json'
with open(api_token_file,'r') as f:
api_conf = json.load(f)
api_key_local = api_conf['api_key_local'] # API token for local
api_key_r4 = api_conf['api_key_r4'] # API token for R4.
cu_local_endpoint = api_conf['local_endpoint'] # local api endpoint
r4_api_endpoint = api_conf['r4_api_endpoint'] # R4 api endpoint
# save the data dictionary
with open(f'metadata-{datetime.now().strftime("%Y%m%d-%H%M%S")}.csv', 'w') as f:
# R4 Data dictionary export
# local Data dictionary export
data = {
'token': api_key_local,
'content': 'metadata',
'format': 'csv',
'returnFormat': 'csv'
}
r = requests.post(cu_local_endpoint,data=data)
print('HTTP Status: ' + str(r.status_code))
f.write(r.text)
data = {
'token': api_key_r4,
'content': 'metadata',
'format': 'csv',
'returnFormat': 'csv'
}
r = requests.post(r4_api_endpoint,data=data)
print('HTTP Status: ' + str(r.status_code))
f.write('\n'.join(r.text.split('\n')[2:])) # skip head and record_id row.