From 92224e9e4e7660872e35a55bbf9d4c2f080a88fa Mon Sep 17 00:00:00 2001 From: "Jules Lasne (jlasne)" Date: Mon, 29 Jan 2018 12:55:14 +0100 Subject: [PATCH 1/4] [CHORE] Added the new CACHE variable --- IntraPy/IntraPy.py | 5 ++++- IntraPy/config.py | 1 + settings.ini.example | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/IntraPy/IntraPy.py b/IntraPy/IntraPy.py index 888152b..35b4705 100644 --- a/IntraPy/IntraPy.py +++ b/IntraPy/IntraPy.py @@ -20,7 +20,7 @@ import json import time import requests -from IntraPy.config import APP_UID, APP_SECRET, TOKEN_FILE +from IntraPy.config import APP_UID, APP_SECRET, TOKEN_FILE, CACHE class IntraPy: @@ -37,9 +37,12 @@ def __init__(self): raise EnvironmentError("APP_SECRET wasn't found in your settings.ini file.") if TOKEN_FILE == "None": raise EnvironmentError("TOKEN_FILE wasn't found in your settings.ini file.") + if CACHE == "None": + print("CACHE variable not found or set to None. No cache will be used") self.app_secret = APP_SECRET self.app_uid = APP_UID self.token_file = TOKEN_FILE + self.cache = CACHE self.app_token = IntraPy.check_app_token(self) def api_request_new_token(self): diff --git a/IntraPy/config.py b/IntraPy/config.py index 705afb8..ded0fac 100644 --- a/IntraPy/config.py +++ b/IntraPy/config.py @@ -27,3 +27,4 @@ APP_UID = config('APP_UID', cast=str, default = None) APP_SECRET = config('APP_SECRET', cast=str, default=None) TOKEN_FILE = config('TOKEN_FILE', cast=str, default=None) +CACHE = config('CACHE', cast=str, default=None) diff --git a/settings.ini.example b/settings.ini.example index e8018f8..9191fa8 100644 --- a/settings.ini.example +++ b/settings.ini.example @@ -1,4 +1,6 @@ [settings] APP_UID=8ngp6jutwr7ge667eqsnqqacppk7wkv2v6hk7rdtvbtzfu82krdeakg3x4rvcra3 APP_SECRET=m5ynvgudum3cmmxksxpkmw3cz96mabfpr9wddujbnwksu3jgqjqa5cux4z6hys2a -TOKEN_FILE=.app_token \ No newline at end of file +TOKEN_FILE=.app_token +CACHE=None +; None for no caching (or remove variable), rcache to use request-cache, and sqlite to use sqlite. \ No newline at end of file From 765094cefe5feb6297e96e3099efbc6a3425a232 Mon Sep 17 00:00:00 2001 From: "Jules Lasne (jlasne)" Date: Mon, 29 Jan 2018 15:04:17 +0100 Subject: [PATCH 2/4] [FEATURE] Added requests-cache possibility --- .gitignore | 1 + IntraPy/IntraPy.py | 53 ++++++++++++++++++++++++++++++++++++-------- IntraPy/config.py | 1 + requirements.txt | 1 + settings.ini.example | 3 ++- setup.py | 1 + 6 files changed, 50 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index ead7ec4..c8552f5 100644 --- a/.gitignore +++ b/.gitignore @@ -107,3 +107,4 @@ settings.ini MANIFEST example.py nosetests +*.sqlite \ No newline at end of file diff --git a/IntraPy/IntraPy.py b/IntraPy/IntraPy.py index 35b4705..e0b1887 100644 --- a/IntraPy/IntraPy.py +++ b/IntraPy/IntraPy.py @@ -20,7 +20,8 @@ import json import time import requests -from IntraPy.config import APP_UID, APP_SECRET, TOKEN_FILE, CACHE +import requests_cache +from IntraPy.config import APP_UID, APP_SECRET, TOKEN_FILE, CACHE, DBNAME class IntraPy: @@ -39,10 +40,15 @@ def __init__(self): raise EnvironmentError("TOKEN_FILE wasn't found in your settings.ini file.") if CACHE == "None": print("CACHE variable not found or set to None. No cache will be used") + if DBNAME == None: + raise EnvironmentError("DBNAME wasn't found in your settings.ini file.") self.app_secret = APP_SECRET self.app_uid = APP_UID self.token_file = TOKEN_FILE self.cache = CACHE + self.db_name = DBNAME + if self.cache == "rcache": + requests_cache.install_cache(self.db_name, backend='sqlite', expire_after=180) self.app_token = IntraPy.check_app_token(self) def api_request_new_token(self): @@ -53,7 +59,11 @@ def api_request_new_token(self): """ d = {'grant_type': 'client_credentials', 'client_id': self.app_uid, 'client_secret': self.app_secret} - r = requests.post("https://api.intra.42.fr/oauth/token", data=d) + if self.cache == "rcache": + with requests_cache.disabled(): + r = requests.post("https://api.intra.42.fr/oauth/token", data=d) + else: + r = requests.post("https://api.intra.42.fr/oauth/token", data=d) print("New access token requested") print(r.json()['access_token']) with open(self.token_file, "w") as file: @@ -69,8 +79,13 @@ def test_token(self): """ self.app_token = IntraPy.get_token_from_file(self) h = {'Authorization': 'Bearer ' + self.app_token} - r = requests.request("GET", - "https://api.intra.42.fr" + "/oauth/token/info", headers=h, allow_redirects=False) + if self.cache == "rcache": + with requests_cache.disabled(): + r = requests.request("GET", "https://api.intra.42.fr" + "/oauth/token/info", headers=h, allow_redirects=False) + else: + r = requests.request("GET", "https://api.intra.42.fr" + "/oauth/token/info", headers=h, allow_redirects=False) + + try: if r.json()['error'] == "invalid_request": return False @@ -204,7 +219,11 @@ def get_uid_from_token(self): :return: Returns the uid in a string form """ - response = self.api_get_single("/oauth/token/info") + if self.cache == "rcache": + with requests_cache.disabled(): + response = self.api_get_single("/oauth/token/info") + else: + response = self.api_get_single("/oauth/token/info") ret = json.loads(response.content) return str(ret["application"]["uid"]) @@ -214,7 +233,11 @@ def get_token_expire_time_in_seconds(self): :return: Return the time in seconds of when the token will expire """ - response = self.api_get_single("/oauth/token/info") + if self.cache == "rcache": + with requests_cache.disabled(): + response = self.api_get_single("/oauth/token/info") + else: + response = self.api_get_single("/oauth/token/info") ret = json.loads(response.content) return str(ret["expires_in_seconds"]) @@ -224,7 +247,11 @@ def get_token_expire_time(self): :return: Returns a string formated in h:m:s """ - response = self.api_get_single("/oauth/token/info") + if self.cache == "rcache": + with requests_cache.disabled(): + response = self.api_get_single("/oauth/token/info") + else: + response = self.api_get_single("/oauth/token/info") ret = json.loads(response.content) m, s = divmod(ret["expires_in_seconds"], 60) h, m = divmod(m, 60) @@ -236,7 +263,11 @@ def get_token_creation_epoch(self): :return: Returns a string containing the epoch creation time """ - response = self.api_get_single("/oauth/token/info") + if self.cache == "rcache": + with requests_cache.disabled(): + response = self.api_get_single("/oauth/token/info") + else: + response = self.api_get_single("/oauth/token/info") ret = json.loads(response.content) return str(ret["created_at"]) @@ -246,6 +277,10 @@ def get_token_creation_date(self): :return: It will return a string in form of `YYYY-MM-DD hh-mm-ss` """ - response = self.api_get_single("/oauth/token/info") + if self.cache == "rcache": + with requests_cache.disabled(): + response = self.api_get_single("/oauth/token/info") + else: + response = self.api_get_single("/oauth/token/info") ret = json.loads(response.content) return str(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ret["created_at"]))) diff --git a/IntraPy/config.py b/IntraPy/config.py index ded0fac..1b5d111 100644 --- a/IntraPy/config.py +++ b/IntraPy/config.py @@ -28,3 +28,4 @@ APP_SECRET = config('APP_SECRET', cast=str, default=None) TOKEN_FILE = config('TOKEN_FILE', cast=str, default=None) CACHE = config('CACHE', cast=str, default=None) +DBNAME = config('DBNAME', cast=str, default=None) diff --git a/requirements.txt b/requirements.txt index 8c8d612..21959c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ requests==2.18.4 +requests-cache python-decouple==3.1 \ No newline at end of file diff --git a/settings.ini.example b/settings.ini.example index 9191fa8..76538a4 100644 --- a/settings.ini.example +++ b/settings.ini.example @@ -3,4 +3,5 @@ APP_UID=8ngp6jutwr7ge667eqsnqqacppk7wkv2v6hk7rdtvbtzfu82krdeakg3x4rvcra3 APP_SECRET=m5ynvgudum3cmmxksxpkmw3cz96mabfpr9wddujbnwksu3jgqjqa5cux4z6hys2a TOKEN_FILE=.app_token CACHE=None -; None for no caching (or remove variable), rcache to use request-cache, and sqlite to use sqlite. \ No newline at end of file +; None for no caching (or remove variable), rcache to use request-cache, and sqlite to use sqlite. +DBNAME=.IntraPy diff --git a/setup.py b/setup.py index 2f9caee..09d1986 100644 --- a/setup.py +++ b/setup.py @@ -13,6 +13,7 @@ 'json', 'requests', 'python-decouple', + 'requests-cache', ], classifiers=[], ) From 8c7de677d6f399477253592d946710b9ffb3ad3b Mon Sep 17 00:00:00 2001 From: "Jules Lasne (jlasne)" Date: Sat, 3 Feb 2018 17:29:21 +0100 Subject: [PATCH 3/4] [STAGE] Staged cache modifications --- IntraPy.db | Bin 0 -> 8192 bytes IntraPy/IntraPy.py | 62 +++++++++++++----- .../accreditation_handler/accreditations.py | 2 +- IntraPy/config.py | 3 +- IntraPy/database.py | 0 settings.ini.example | 5 +- 6 files changed, 53 insertions(+), 19 deletions(-) create mode 100644 IntraPy.db create mode 100644 IntraPy/database.py diff --git a/IntraPy.db b/IntraPy.db new file mode 100644 index 0000000000000000000000000000000000000000..3d248e7b69dd831931b8f2ee733e762225eda2be GIT binary patch literal 8192 zcmeI#F>ljA6aZj5jZ_%gvY@aaoy^io5wU%VZJ1h6C_@*ZQ!%pce9x+dd*|Bcv=ZuI z@#hfyDV{^KbYW|UzNeg%_xy6w`?mMx(@AN86{fimmT~8q|n!o?p$ zZ4*QOzZg5OU;Ns^E_cs5_@N*H5+DH*AOR8}0TLhq5+DH*Ac03C&_8vzCzFZWUs@q6 z$VGns?=gD+d3kiYWT!{(PL^z4XZu}KF$>pr%0R2yl-k~=4YakTOWe2SV z#jp?mab1_#mWjebbEjm7{9xG4w|1U8d)vFa_(eeiBtQZrKmsH{0wh2JBtQa>OQ2tE zJ(<1y`D#2G&y48o`OKQ{pl78n%w`Gmexx3*R;Fum$jp_7CM#9yz13Y+O;fMUO${yP zUsJE{WL4&=_YLctjjYsJ3%Sv1=n0cI5xx_3jeWwFMq?50@76b_-XaKtx$@&!g5o}p z0uG!fkjFj`l0eSI!j}c`NPtvHsCej$NESjxGFB4&IQ4Gu`n&;wn_(s_-X1K1IEv;G q4{yA)?)OJ`de;51{c3dIgU1g$`0;x1wqLpTJ$Ul4gMU~L-uwj(E-OX= literal 0 HcmV?d00001 diff --git a/IntraPy/IntraPy.py b/IntraPy/IntraPy.py index e0b1887..71086b9 100644 --- a/IntraPy/IntraPy.py +++ b/IntraPy/IntraPy.py @@ -21,7 +21,8 @@ import time import requests import requests_cache -from IntraPy.config import APP_UID, APP_SECRET, TOKEN_FILE, CACHE, DBNAME +import sqlite3 +from IntraPy.config import APP_UID, APP_SECRET, TOKEN_FILE, CACHE_TYPE, DBNAME, TABLE_NAME class IntraPy: @@ -38,17 +39,23 @@ def __init__(self): raise EnvironmentError("APP_SECRET wasn't found in your settings.ini file.") if TOKEN_FILE == "None": raise EnvironmentError("TOKEN_FILE wasn't found in your settings.ini file.") - if CACHE == "None": - print("CACHE variable not found or set to None. No cache will be used") - if DBNAME == None: + if CACHE_TYPE == "None": + print("CACHE_TYPE variable not found or set to None. No cache will be used") + if DBNAME == "None": raise EnvironmentError("DBNAME wasn't found in your settings.ini file.") + self.table_name = TABLE_NAME self.app_secret = APP_SECRET self.app_uid = APP_UID self.token_file = TOKEN_FILE - self.cache = CACHE + self.cache_type = CACHE_TYPE self.db_name = DBNAME - if self.cache == "rcache": + if self.cache_type == "rcache": requests_cache.install_cache(self.db_name, backend='sqlite', expire_after=180) + elif self.cache_type == "sqlite": + self.connection = sqlite3.connect(self.db_name) + self.cursor = self.connection.cursor() + self.cursor.execute('CREATE TABLE IF NOT EXISTS ' + self.table_name + ' (url text, endpoint text, response text, last_requested int, expires_after int, expires_at int)') + self.connection.commit() self.app_token = IntraPy.check_app_token(self) def api_request_new_token(self): @@ -59,7 +66,7 @@ def api_request_new_token(self): """ d = {'grant_type': 'client_credentials', 'client_id': self.app_uid, 'client_secret': self.app_secret} - if self.cache == "rcache": + if self.cache_type == "rcache": with requests_cache.disabled(): r = requests.post("https://api.intra.42.fr/oauth/token", data=d) else: @@ -79,7 +86,7 @@ def test_token(self): """ self.app_token = IntraPy.get_token_from_file(self) h = {'Authorization': 'Bearer ' + self.app_token} - if self.cache == "rcache": + if self.cache_type == "rcache": with requests_cache.disabled(): r = requests.request("GET", "https://api.intra.42.fr" + "/oauth/token/info", headers=h, allow_redirects=False) else: @@ -173,8 +180,11 @@ def api_get_single(self, uri: str, methods="GET"): :return: Returns the response object returned by requests.request() """ h = {'Authorization': 'Bearer ' + self.app_token} - response = requests.request(methods, "https://api.intra.42.fr" + - uri, headers=h, allow_redirects=False) + if not self.cache_type == "sqlite": + response = requests.request(methods, "https://api.intra.42.fr" + uri, headers=h, allow_redirects=False) + else: + response = requests.request(methods, "https://api.intra.42.fr" + uri, headers=h, allow_redirects=False) + self.cache_response(response, uri) if response.status_code == 401: self.app_token = IntraPy.check_app_token(self) return IntraPy.api_get_single(self, uri, methods) @@ -183,6 +193,28 @@ def api_get_single(self, uri: str, methods="GET"): return self.api_get_single(uri, methods) return response + def cache_response(self, response, uri: str): + endpoint = uri.split('?')[0] + content = json.dumps(response.content.decode("utf-8")) + last_requested = str(round(time.time())) + expires_after = self.get_expire_time_seconds(endpoint) + expires_at = last_requested + expires_after + values = "'" + uri + "', '" + endpoint + "', '" + content + "', " + last_requested + ", " + expires_after + ", " + expires_at + self.cursor.execute("INSERT INTO " + self.table_name + " VALUES (" + values + ")") + self.connection.commit() + + # @todo: Change the ifs into a dict/list for get_expire_time + # @todo: Add /v2/campus and /v2/cursus in get_expire_time + def get_expire_time_seconds(self, endpoint: str): + if endpoint == "/oauth/token/info": + return "1" # 1 second + if endpoint == "/v2/accreditations": + return "86400" # 1 day + if endpoint == "/v2/achievements": + return "2629746" # 1 month + if endpoint == "/v2/titles": + return "2629746" # 1 month + def get_changeable_parameters(self, args): """ This will create and return the string with the parameter that will @@ -219,7 +251,7 @@ def get_uid_from_token(self): :return: Returns the uid in a string form """ - if self.cache == "rcache": + if self.cache_type == "rcache": with requests_cache.disabled(): response = self.api_get_single("/oauth/token/info") else: @@ -233,7 +265,7 @@ def get_token_expire_time_in_seconds(self): :return: Return the time in seconds of when the token will expire """ - if self.cache == "rcache": + if self.cache_type == "rcache": with requests_cache.disabled(): response = self.api_get_single("/oauth/token/info") else: @@ -247,7 +279,7 @@ def get_token_expire_time(self): :return: Returns a string formated in h:m:s """ - if self.cache == "rcache": + if self.cache_type == "rcache": with requests_cache.disabled(): response = self.api_get_single("/oauth/token/info") else: @@ -263,7 +295,7 @@ def get_token_creation_epoch(self): :return: Returns a string containing the epoch creation time """ - if self.cache == "rcache": + if self.cache_type == "rcache": with requests_cache.disabled(): response = self.api_get_single("/oauth/token/info") else: @@ -277,7 +309,7 @@ def get_token_creation_date(self): :return: It will return a string in form of `YYYY-MM-DD hh-mm-ss` """ - if self.cache == "rcache": + if self.cache_type == "rcache": with requests_cache.disabled(): response = self.api_get_single("/oauth/token/info") else: diff --git a/IntraPy/accreditation_handler/accreditations.py b/IntraPy/accreditation_handler/accreditations.py index 7736c5f..fbbb20c 100644 --- a/IntraPy/accreditation_handler/accreditations.py +++ b/IntraPy/accreditation_handler/accreditations.py @@ -60,7 +60,7 @@ def get_accreditations_by_id(self, accreditation_id: int, pretty=False): :return: Returns a list in json form containing the requested accreditation """ - response = self.api_get_single("/v2/achievements/" + str(accreditation_id), "GET") + response = self.api_get_single("/v2/accreditations/" + str(accreditation_id), "GET") accreditation = json.loads(response.content) if pretty: return json.dumps(accreditation, indent=4, sort_keys=True) diff --git a/IntraPy/config.py b/IntraPy/config.py index 1b5d111..825b5e5 100644 --- a/IntraPy/config.py +++ b/IntraPy/config.py @@ -27,5 +27,6 @@ APP_UID = config('APP_UID', cast=str, default = None) APP_SECRET = config('APP_SECRET', cast=str, default=None) TOKEN_FILE = config('TOKEN_FILE', cast=str, default=None) -CACHE = config('CACHE', cast=str, default=None) +CACHE_TYPE = config('CACHE_TYPE', cast=str, default=None) DBNAME = config('DBNAME', cast=str, default=None) +TABLE_NAME = config('TABLE_NAME', cast=str, default="cache") diff --git a/IntraPy/database.py b/IntraPy/database.py new file mode 100644 index 0000000..e69de29 diff --git a/settings.ini.example b/settings.ini.example index 76538a4..ced1d5a 100644 --- a/settings.ini.example +++ b/settings.ini.example @@ -2,6 +2,7 @@ APP_UID=8ngp6jutwr7ge667eqsnqqacppk7wkv2v6hk7rdtvbtzfu82krdeakg3x4rvcra3 APP_SECRET=m5ynvgudum3cmmxksxpkmw3cz96mabfpr9wddujbnwksu3jgqjqa5cux4z6hys2a TOKEN_FILE=.app_token -CACHE=None +CACHE_TYPE=None ; None for no caching (or remove variable), rcache to use request-cache, and sqlite to use sqlite. -DBNAME=.IntraPy +DBNAME=IntraPy.db +TABLE_NAME=cache \ No newline at end of file From c9a5ae5678d77a39f264a602f1dfbd97dca01afb Mon Sep 17 00:00:00 2001 From: "Jules Lasne (jlasne)" Date: Mon, 5 Feb 2018 07:17:23 +0100 Subject: [PATCH 4/4] [Stage] Staged little corrections --- IntraPy.db | Bin 8192 -> 0 bytes IntraPy/IntraPy.py | 25 ++++++++++++------------- IntraPy/config.py | 8 ++++---- 3 files changed, 16 insertions(+), 17 deletions(-) delete mode 100644 IntraPy.db diff --git a/IntraPy.db b/IntraPy.db deleted file mode 100644 index 3d248e7b69dd831931b8f2ee733e762225eda2be..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8192 zcmeI#F>ljA6aZj5jZ_%gvY@aaoy^io5wU%VZJ1h6C_@*ZQ!%pce9x+dd*|Bcv=ZuI z@#hfyDV{^KbYW|UzNeg%_xy6w`?mMx(@AN86{fimmT~8q|n!o?p$ zZ4*QOzZg5OU;Ns^E_cs5_@N*H5+DH*AOR8}0TLhq5+DH*Ac03C&_8vzCzFZWUs@q6 z$VGns?=gD+d3kiYWT!{(PL^z4XZu}KF$>pr%0R2yl-k~=4YakTOWe2SV z#jp?mab1_#mWjebbEjm7{9xG4w|1U8d)vFa_(eeiBtQZrKmsH{0wh2JBtQa>OQ2tE zJ(<1y`D#2G&y48o`OKQ{pl78n%w`Gmexx3*R;Fum$jp_7CM#9yz13Y+O;fMUO${yP zUsJE{WL4&=_YLctjjYsJ3%Sv1=n0cI5xx_3jeWwFMq?50@76b_-XaKtx$@&!g5o}p z0uG!fkjFj`l0eSI!j}c`NPtvHsCej$NESjxGFB4&IQ4Gu`n&;wn_(s_-X1K1IEv;G q4{yA)?)OJ`de;51{c3dIgU1g$`0;x1wqLpTJ$Ul4gMU~L-uwj(E-OX= diff --git a/IntraPy/IntraPy.py b/IntraPy/IntraPy.py index 71086b9..ee7c130 100644 --- a/IntraPy/IntraPy.py +++ b/IntraPy/IntraPy.py @@ -24,7 +24,6 @@ import sqlite3 from IntraPy.config import APP_UID, APP_SECRET, TOKEN_FILE, CACHE_TYPE, DBNAME, TABLE_NAME - class IntraPy: """ This is the main class for IntraPy. It contains the app_token handling @@ -40,15 +39,14 @@ def __init__(self): if TOKEN_FILE == "None": raise EnvironmentError("TOKEN_FILE wasn't found in your settings.ini file.") if CACHE_TYPE == "None": - print("CACHE_TYPE variable not found or set to None. No cache will be used") - if DBNAME == "None": - raise EnvironmentError("DBNAME wasn't found in your settings.ini file.") + print("CACHE_TYPE variable not found or set to None. No cache method will be used") self.table_name = TABLE_NAME self.app_secret = APP_SECRET self.app_uid = APP_UID self.token_file = TOKEN_FILE self.cache_type = CACHE_TYPE self.db_name = DBNAME + # @todo: Customize the expire_after for rcache if self.cache_type == "rcache": requests_cache.install_cache(self.db_name, backend='sqlite', expire_after=180) elif self.cache_type == "sqlite": @@ -179,12 +177,17 @@ def api_get_single(self, uri: str, methods="GET"): :return: Returns the response object returned by requests.request() """ + response = None h = {'Authorization': 'Bearer ' + self.app_token} - if not self.cache_type == "sqlite": - response = requests.request(methods, "https://api.intra.42.fr" + uri, headers=h, allow_redirects=False) - else: + if self.cache_type == "None": + with requests_cache.disabled(): + response = requests.request(methods, "https://api.intra.42.fr" + uri, headers=h, allow_redirects=False) + elif self.cache_type == "sqlite": + with requests_cache.disabled(): + response = requests.request(methods, "https://api.intra.42.fr" + uri, headers=h, allow_redirects=False) + self.cache_response(response, uri) + elif self.cache_type == "rcache": response = requests.request(methods, "https://api.intra.42.fr" + uri, headers=h, allow_redirects=False) - self.cache_response(response, uri) if response.status_code == 401: self.app_token = IntraPy.check_app_token(self) return IntraPy.api_get_single(self, uri, methods) @@ -251,11 +254,7 @@ def get_uid_from_token(self): :return: Returns the uid in a string form """ - if self.cache_type == "rcache": - with requests_cache.disabled(): - response = self.api_get_single("/oauth/token/info") - else: - response = self.api_get_single("/oauth/token/info") + response = self.api_get_single("/oauth/token/info") ret = json.loads(response.content) return str(ret["application"]["uid"]) diff --git a/IntraPy/config.py b/IntraPy/config.py index 825b5e5..387947e 100644 --- a/IntraPy/config.py +++ b/IntraPy/config.py @@ -24,9 +24,9 @@ APP_SECRET: the app secret given by 42 TOKEN_FILE: The filename you want your token to be stored in """ -APP_UID = config('APP_UID', cast=str, default = None) +APP_UID = config('APP_UID', cast=str, default=None) APP_SECRET = config('APP_SECRET', cast=str, default=None) -TOKEN_FILE = config('TOKEN_FILE', cast=str, default=None) -CACHE_TYPE = config('CACHE_TYPE', cast=str, default=None) -DBNAME = config('DBNAME', cast=str, default=None) +TOKEN_FILE = config('TOKEN_FILE', cast=str, default=".app_token") +CACHE_TYPE = config('CACHE_TYPE', cast=str, default="None") +DBNAME = config('DBNAME', cast=str, default="IntraPy.db") TABLE_NAME = config('TABLE_NAME', cast=str, default="cache")