-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
69 lines (55 loc) · 1.94 KB
/
database.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
58
59
60
61
62
63
64
65
66
67
68
69
import requests
import os
import dotenv
dotenv.load_dotenv()
def create_summary(data: dict):
"""
data : {
"content": str(summary),
"server_id": str(ctx.message.guild.id),
"is_private": True if str(ctx.message.type) == 'private' else False,
"user_id": str(ctx.author.id)
}
stores this data using mongodb on backend server
"""
print("sending data to server")
url = os.getenv("CREATE_SUMMARY_URL")
headers = {"Content-Type": "application/json"}
response = requests.post(url, headers=headers, json=data)
print(response.status_code, response.json())
return response
def get_summaries(id, server_id):
"""
id:str = ctx.author.id
server_id:str = ctx.guild.id
"""
print("getting summaries")
url = os.getenv("GET_SUMMARY_URL")
headers = {"ID": str(id)}
params = {"user_id": str(id), "server_id": str(server_id)}
response = requests.get(url, params=params, headers=headers)
print(response.status_code, response.json())
return response
def update_summary(data):
"""
data : {
"content": str(summary),
"server_id": str(ctx.message.guild.id),
"is_private": True if str(ctx.message.type) == 'private' else False,
"user_id": str(ctx.author.id)
}
updates data on backend server
"""
url = os.getenv("UPDATE_SUMMARY_URL")
headers = {"Content-Type": "application/json"}
response = requests.put(url, headers=headers, json=data)
print(response.status_code, response.json())
return response
def del_summary(summary_id: str, id):
print("deleting summary")
url = os.getenv("DELETE_SUMMARY_URL")
headers = {"ID": str(id)}
request = {"summary_id": str(summary_id)}
response = requests.delete(url, json=request, headers=headers)
print(response.status_code, response.json())
return response