75 lines
2.6 KiB
Python
75 lines
2.6 KiB
Python
import json
|
|
import requests
|
|
import time
|
|
import tqdm
|
|
|
|
class Non200StatusCodeError(Exception):
|
|
def __init__(self, status_code, message="Сервер вернул не 200 код"):
|
|
self.status_code = status_code
|
|
self.message = message
|
|
super().__init__(self.message)
|
|
|
|
def __str__(self):
|
|
return f"{self.message}. Код статуса: {self.status_code}"
|
|
|
|
def do_request(name, start, end):
|
|
response = requests.post(
|
|
"https://ulsu.ru/oto/api/production/external/createKtalkMeeting.php",
|
|
data={
|
|
"name": name,
|
|
"desc": "Встреча создана средствами API (Copyright © 2023 Kravenrus), обработка расписания © Kozhilya",
|
|
"startAt": start,
|
|
"endAt": end,
|
|
"stateAnonymous": True,
|
|
"stateSessionHalls": False,
|
|
"stateLobby": False,
|
|
"stateSip": False,
|
|
"stateAutoRecording": True,
|
|
"stateAudioPolicy": False,
|
|
"stateVideoPolicy": False,
|
|
"stateScreenSharePolicy": False,
|
|
"pinCode": False
|
|
},
|
|
headers={ \
|
|
"Referer": "https://ulsu.ru/oto/ktalk/"
|
|
}
|
|
)
|
|
|
|
if response.status_code == 200:
|
|
time.sleep(1)
|
|
data = response.json()
|
|
return f"https://{data['meetingData']['global']['space']}.ktalk.ru/{data['createdMeeting']['roomName']}"
|
|
|
|
else:
|
|
raise Non200StatusCodeError(response.status_code, "Ответ сервера: " + response.text)
|
|
|
|
if __name__ == "__main__":
|
|
lines = []
|
|
|
|
with open("lecture.json", "r", encoding="utf-8") as f:
|
|
lectures = json.load(f)
|
|
|
|
last_auditorium = ""
|
|
last_day_of_week = ""
|
|
|
|
for lecture in tqdm.tqdm(lectures):
|
|
url = do_request(lecture['name'], lecture['start'], lecture['end'])
|
|
|
|
if lecture['auditorium'] != last_auditorium:
|
|
if last_auditorium != "":
|
|
lines.append("\n========================\n")
|
|
lines.append(lecture['auditorium'] + "\n")
|
|
last_auditorium = lecture['auditorium']
|
|
last_day_of_week = ""
|
|
|
|
if lecture['day_of_week'] != last_day_of_week:
|
|
prefix = f" {lecture['day_of_week']} "
|
|
last_day_of_week = lecture['day_of_week']
|
|
else:
|
|
prefix = " " * 6
|
|
|
|
lines.append(f"{prefix} #{lecture['pair_number']} - {lecture['name']}\n")
|
|
lines.append(" " * 12 + url + "\n")
|
|
|
|
with open("result.txt", "w", encoding="utf-8") as f:
|
|
f.writelines(lines) |