-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_calls.py
106 lines (93 loc) · 2.55 KB
/
api_calls.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import requests
import json
import os
from helpers import crypto
from cryptography.fernet import Fernet
from dotenv import load_dotenv
load_dotenv()
API_URL = os.environ['API_URL']
HEADERS = {
'content-type': 'application/json; charset=utf-8'
}
def update_username(chat_id, new_username):
payload = {
'username': crypto.encrypt(new_username),
}
requests.post(
'{}/chat/update_username/{}'.format(API_URL, chat_id),
data=json.dumps(payload),
headers=HEADERS
)
def update_webwork_password(chat_id, new_password):
payload = {
'webwork_password': crypto.encrypt(new_password),
}
requests.post(
'{}/chat/update_webwork_password/{}'.format(API_URL, chat_id),
data=json.dumps(payload),
headers=HEADERS
)
def update_main_password(chat_id, new_password):
payload = {
'main_password': crypto.encrypt(new_password),
}
requests.post(
'{}/chat/update_main_password/{}'.format(API_URL, chat_id),
data=json.dumps(payload),
headers=HEADERS
)
def get_chat_info(chat_id):
chat_info = requests.get(
'{}/chat/{}'.format(API_URL, chat_id)
)
chat_info = json.loads(chat_info.text)
return crypto.process_chat(chat_info)
def get_all_chats_info():
result = requests.get(
'{}/chat/all_chats'.format(API_URL)
)
result = json.loads(result.text)
chats = result['chats']
for i in range(0, len(chats)):
chats[i] = crypto.process_chat(chats[i])
return chats
def update_webworks_for_chat(chat_id, new_webworks):
payload = {
'new_webworks': crypto.encrypt(json.dumps(new_webworks))
}
requests.put(
'{}/chat/update_webworks/{}'.format(API_URL, chat_id),
data=json.dumps(payload),
headers=HEADERS
)
def update_schedule_for_chat(chat_id, new_schedule):
payload = {
'new_schedule': crypto.encrypt(json.dumps(new_schedule))
}
requests.put(
'{}/chat/update_schedule/{}'.format(API_URL, chat_id),
data=json.dumps(payload),
headers=HEADERS
)
def disable_notify_grades_for_chat(chat_id):
requests.put(
'{}/chat/disable_notify_grades/{}'.format(API_URL, chat_id)
)
def update_grades_for_chat(chat_id, new_grades):
payload = {
'new_grades': crypto.encrypt(json.dumps(new_grades))
}
requests.put(
'{}/chat/update_grades/{}'.format(API_URL, chat_id),
data=json.dumps(payload),
headers=HEADERS
)
def update_schedule_notify_minutes(chat_id, new_minutes):
payload = {
'schedule_notify_minutes': new_minutes
}
requests.post(
'{}/chat/update_schedule_notify_minutes/{}'.format(API_URL, chat_id),
data=json.dumps(payload),
headers=HEADERS
)