forked from stormliucong/eMERGE-Columbia-Data-Sync-Service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_redcap_version.py
39 lines (33 loc) · 1.34 KB
/
get_redcap_version.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
import requests
import json
from pprint import pprint
from datetime import datetime
from io import StringIO
import pandas as pd
def read_api_config(config_file = './api_tokens.json'):
api_token_file = config_file
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
return api_key_local, api_key_r4, cu_local_endpoint, r4_api_endpoint
def get_api_version(api_key_local, api_key_r4, cu_local_endpoint, r4_api_endpoint):
data = {
'token': api_key_local,
'content': 'version'
}
r = requests.post(cu_local_endpoint,data=data)
print('HTTP Status: ' + str(r.status_code))
print('Local redcap version : ' + str(r.content))
data = {
'token': api_key_r4,
'content': 'version'
}
r = requests.post(r4_api_endpoint,data=data)
print('HTTP Status: ' + str(r.status_code))
print('R4 redcap version : ' + str(r.content))
if __name__ == "__main__":
api_key_local, api_key_r4, cu_local_endpoint, r4_api_endpoint = read_api_config()
get_api_version(api_key_local, api_key_r4, cu_local_endpoint, r4_api_endpoint)