This repository was archived by the owner on Jul 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.py
More file actions
66 lines (57 loc) · 2.09 KB
/
upload.py
File metadata and controls
66 lines (57 loc) · 2.09 KB
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
import parser
from datetime import datetime
import pytz
import json
import requests
import time
import config
import time
api_key = config.API_KEY[0]
headers = {
'X-API-Key': api_key,
'Content-Type': 'application/json'
}
def now_time():
now = datetime.now()
tz = pytz.timezone('Europe/Moscow')
now_moscow = now.astimezone(tz)
current_time = now_moscow.strftime("%H:%M:%S")
current_date = now_moscow.strftime("%Y.%m.%d")
return current_date, current_time
def now_week():
now = datetime.now()
tz = pytz.timezone('Europe/Moscow')
now_moscow = now.astimezone(tz)
week_number = now_moscow.isocalendar()[1]
return week_number
def send_courses():
for complex_name in parser.COMPLEX:
courses = json.loads(parser.get_courses(parser.COMPLEX[complex_name]))
if courses == {}: return
data = {}
data["complex"] = complex_name
response = requests.post('https://timetable.falpin.ru/api/save_groups', json=data, headers=headers)
date, time = now_time()
print(f"{date} {time}: Сохранение групп: {json.loads(response.text)}")
def send_schedule():
data = {}
data["week"] = now_week()
for complex_name in parser.COMPLEX:
courses = json.loads(parser.get_courses(parser.COMPLEX[complex_name]))
if courses == {}: return
for course in courses:
groups = courses[course]
for group in groups:
group_url = groups[group]
schedule = json.loads(parser.get_schedule(group_url))
data[group] = schedule
date, time = now_time()
print(f"[ {date} {time} ] Группа {group} получена...")
response = requests.post('https://timetable.falpin.ru/api/save_schedule', json=data, headers=headers)
date, time = now_time()
print(f"{date} {time}: Сохранение расписания: {json.loads(response.text)}")
while True:
send_courses()
send_schedule()
print("Ожидание следующего запуска через 1 час...")
time.sleep(3600)