-
Notifications
You must be signed in to change notification settings - Fork 0
/
Token.py
52 lines (36 loc) · 1.3 KB
/
Token.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
# -*- coding: utf-8 -*-
"""
Created on Wed May 24 15:58:49 2017
@author: m.leclech
"""
import requests
def getMagicToken():
"""Return the magic token"""
with open("cred/tokenMagic.txt","r") as f:
magicToken = f.readline()
return magicToken
def requestSeanceToken(url, idSeance):
"""Request a token from the server to access a specific seance
Args:
url (string): the url of the server
idSeance (int): the id of the seance
Returns:
the Token needed (string)
"""
seanceToken = requests.get("http://"+url+"/api/seance/"
+str(idSeance)+"/token?token="
+getMagicToken()).text
return seanceToken
def requestGoogleToken(url):
"""Request a token to use with Google API Auth
Args:
url (string): the server you'll ask from
idevaluation.estia.fr or neptune2.estia.fr
Returns:
a token to use Natural Language API
"""
magicToken = getMagicToken()
tokenRequest = requests.get("http://"+url+"/api/googleToken?token="
+magicToken).json()
googleToken = tokenRequest['token']['access_token']
return googleToken