-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi-mwe.py
57 lines (46 loc) · 1.35 KB
/
api-mwe.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import json
import os
import requests
from decouple import config
if not os.path.exists("settings.ini"):
with open('settings.ini', 'w') as f:
f.write(
"""[settings]
password=unsecured
baseurl=http://127.0.0.1:8092
"""
)
baseUrl = config('baseurl')
r = requests.post(
url=f'{baseUrl}/api/user_auth/',
data=dict(
username=config('username'),
password=config('password'),
),
)
token = json.loads(r.content.decode())["token"]
print(f"Token is {token[:4]}{'*'*(len(token)-7)}{token[-3:]}")
headers = {'Authorization': f'Token {token}'}
r = requests.get(f'{baseUrl}/api/licence/', headers=headers)
print(json.dumps(json.loads(r.content.decode()), indent=4))
r = requests.post(
url=f'{baseUrl}/api/service/',
data=dict(
comments="my comment",
training="Recurrent",
mentoring=True,
collaboration="both",
prestation="Custom",
team=f"{baseUrl}/api/team/ATGC/",
domain=f"{baseUrl}/api/servicedomain/Transcriptomique/",
analysis=f"{baseUrl}/api/kindofanalysis/RNAseq/",
category=f"{baseUrl}/api/servicecategory/Data analysis/",
communities=[
f"{baseUrl}/api/lifesciencecommunity/Human/",
f"{baseUrl}/api/lifesciencecommunity/Plants/",
],
),
headers=headers,
)
print(r.content)