-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkv.py
33 lines (22 loc) · 834 Bytes
/
kv.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
import os
import requests
from dotenv import load_dotenv
load_dotenv()
class KV:
def __init__(self) -> None:
self.url = os.getenv("KV_REST_API_URL")
token = os.getenv("KV_REST_API_TOKEN")
print(self.url)
if not (self.url and token):
raise Exception(
"Both KV_REST_API_URL and KV_REST_API_TOKEN are required in .env file!"
)
self.headers = {"Authorization": f"Bearer {token}"}
def get(self, key):
get_url = f"{self.url}/get/{key}"
response = requests.get(url=get_url, headers=self.headers)
return response.json()["result"]
def set(self, key, value):
set_url = f"{self.url}/set/{key}/{value}"
response = requests.get(url=set_url, headers=self.headers)
return response.json()["result"]