-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScoolioAPI.py
194 lines (147 loc) · 6.22 KB
/
ScoolioAPI.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import requests
import certifi
import pandas as pd
from datetime import datetime
token = None
def log(user, password):
global token
url_login = "https://userbridge.services.scoolio.de/v1/login/identifier"
data_login = {
"Identifier": user,
"Secret": password
}
print("Attempting to log in with user:", user)
response_login = requests.post(url_login, json=data_login, verify=certifi.where())
response_data = response_login.json()
print("Login Response Data:", response_data)
token = response_data.get('Result', {}).get('Token')
current_user = response_data.get('User', {}).get('UserID')
print("Current User:", current_user)
def message(message, room):
global token
url_send_message = f"https://chat.services.scoolio.de/v1/rooms/{room}/messages"
message_data = {
"Type": "text",
"Content": message
}
headers = {
"Authorization": f"Bearer {token}",
"Content-Length": str(len(str(message_data))),
"x-scoolio-csrf": "1",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"host": "chat.services.scoolio.de"
}
print("Sending message to room:", room)
print("Message Data:", message_data)
print("Headers:", headers)
try:
rr = requests.post(url_send_message, json=message_data, headers=headers, verify=certifi.where())
print("Response Text:", rr.text)
if rr.status_code != 200:
print("Error in request. Please check the URL, headers, and data.")
except requests.exceptions.RequestException as e:
print("Error sending the request:", e)
def check_last_messages_fine(room, anzahl):
global token
url_last_messages = f"https://chat.services.scoolio.de/v1/rooms/{room}/messages?LastN={anzahl}"
headers = {
"Authorization": f"Bearer {token}",
"x-scoolio-csrf": "1",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"host": "chat.services.scoolio.de"
}
print("Checking last messages in room:", room)
print("Requesting last N messages:", anzahl)
print("URL for last messages:", url_last_messages)
try:
response = requests.get(url_last_messages, headers=headers, verify=certifi.where())
if response.status_code == 200:
data = response.json()
print("Response Data:", data)
messages = data.get('Result', {}).get('Items', [])
# Prepare data for return
message_data = []
for message in messages:
user_id = message['Author']['ID']
user_name = message['Author']['Name']
content = message['Content']
timestamp = datetime.fromtimestamp(message['SentAt']).strftime('%Y-%m-%d %H:%M:%S')
message_data.append({
"UserID": user_id,
"User": user_name,
"Nachricht": content,
"Zeit": timestamp
})
print("Extracted Message:", message_data[-1])
print(message_data)
return message_data
else:
print("Error in request. Please check the URL, headers, and data.")
return None
except requests.exceptions.RequestException as e:
print("Error sending the request:", e)
return None
def check_last_messages(room, anzahl):
global token
url_last_messages = f"https://chat.services.scoolio.de/v1/rooms/{room}/messages?LastN={anzahl}"
headers = {
"Authorization": f"Bearer {token}",
"x-scoolio-csrf": "1",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"host": "chat.services.scoolio.de"
}
try:
response = requests.get(url_last_messages, headers=headers, verify=certifi.where())
if response.status_code == 200:
data = response.json()
messages = data.get('Result', {}).get('Items', [])
if messages:
last_message = messages[0]
content = last_message['Content']
return content # Gib nur den Content zurück
else:
print("Keine Nachrichten gefunden.")
return None
else:
print("Fehler bei der Anfrage. Bitte überprüfe die URL, die Headers und die Daten.")
return None
except requests.exceptions.RequestException as e:
print("Fehler beim Senden der Anfrage:", e)
return None
def check_last_messages_user(room, anzahl):
global token
url_last_messages = f"https://chat.services.scoolio.de/v1/rooms/{room}/messages?LastN={anzahl}"
headers = {
"Authorization": f"Bearer {token}",
"x-scoolio-csrf": "1",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"host": "chat.services.scoolio.de"
}
try:
response = requests.get(url_last_messages, headers=headers, verify=certifi.where())
if response.status_code == 200:
data = response.json()
messages = data.get('Result', {}).get('Items', [])
print(messages)
if messages:
last_message = messages[0]
author_id = last_message.get('Author', {}).get('ID')
print("Extracted Author ID:", author_id)
return author_id # Gib nur die ID des Authors zurück
else:
print("Keine Nachrichten gefunden.")
return None
else:
print("Fehler bei der Anfrage. Bitte überprüfe die URL, die Headers und die Daten.")
return None
except requests.exceptions.RequestException as e:
print("Fehler beim Senden der Anfrage:", e)
return None
# Beispielaufruf
# check_last_messages_user("2b2cf9f2-420a-4b3b-8361-3c1cab7c077c", 1)
# Last messages
# check_last_messages("2b2cf9f2-420a-4b3b-8361-3c1cab7c077c", 100)