Getting timetable
This commit is contained in:
parent
8c5045d2a8
commit
b39108bf4b
5 changed files with 63 additions and 109 deletions
|
@ -3,109 +3,30 @@ import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
def get_timetable(register_id, register_r, oun, s, date):
|
def get_timetable(register_id, register_r, oun, s, date):
|
||||||
|
cookies = s
|
||||||
if oun != 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458':
|
if oun != 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458':
|
||||||
cookies = {
|
cookies.update({
|
||||||
"biezacyRokSzkolny": f"{register_r.json()['data'][0]['DziennikRokSzkolny']}",
|
"biezacyRokSzkolny": f"{register_r['data'][0]['DziennikRokSzkolny']}",
|
||||||
"idBiezacyDziennik": f"{register_r.json()['data'][0]['IdDziennik']}",
|
"idBiezacyDziennik": f"{register_r['data'][0]['IdDziennik']}",
|
||||||
"idBiezacyDziennikPrzedszkole": f"{register_r.json()['data'][0]['IdPrzedszkoleDziennik']}",
|
"idBiezacyDziennikPrzedszkole": f"{register_r['data'][0]['IdPrzedszkoleDziennik']}",
|
||||||
"idBiezacyDziennikWychowankowie": f"{register_r.json()['data'][0]['IdWychowankowieDziennik']}",
|
"idBiezacyDziennikWychowankowie": f"{register_r['data'][0]['IdWychowankowieDziennik']}",
|
||||||
"idBiezacyUczen": f"{register_r.json()['data'][0]['IdUczen']}"
|
"idBiezacyUczen": f"{register_r['data'][0]['IdUczen']}"
|
||||||
}
|
})
|
||||||
else:
|
else:
|
||||||
cookies = {
|
cookies.update({
|
||||||
"biezacyRokSzkolny": f"{register_r.json()['data'][0]['DziennikRokSzkolny']}",
|
"biezacyRokSzkolny": f"{register_r['data'][0]['DziennikRokSzkolny']}",
|
||||||
"idBiezacyDziennik": f"{register_r.json()['data'][0]['IdDziennik']}",
|
"idBiezacyDziennik": f"{register_r['data'][0]['IdDziennik']}",
|
||||||
"idBiezacyDziennikPrzedszkole": f"{register_r.json()['data'][0]['IdPrzedszkoleDziennik']}",
|
"idBiezacyDziennikPrzedszkole": f"{register_r['data'][0]['IdPrzedszkoleDziennik']}",
|
||||||
"idBiezacyUczen": f"{register_r.json()['data'][0]['IdUczen']}"
|
"idBiezacyUczen": f"{register_r['data'][0]['IdUczen']}"
|
||||||
}
|
})
|
||||||
|
|
||||||
timetable = s.post(oun+'/PlanZajec.mvc/Get', headers={"User-Agent": "Wulkanowy-web :)"}, cookies=cookies, json={'data': date})
|
headers = {
|
||||||
|
'Accept-Encoding': 'gzip, deflate',
|
||||||
|
'Accept': '*/*',
|
||||||
|
'Connection': 'keep-alive',
|
||||||
|
"User-Agent": "Wulkanowy-web :)"
|
||||||
|
}
|
||||||
|
|
||||||
return timetable.json()
|
timetable = requests.post(oun+'/PlanZajec.mvc/Get', headers=headers, cookies=cookies, json={'data': date})
|
||||||
|
|
||||||
|
return timetable.json()
|
||||||
def prepare_timetable_for_display(register_id, register_r, oun, s, date):
|
|
||||||
timetable = get_timetable(register_id, register_r, oun, s, date)
|
|
||||||
|
|
||||||
json_timetable = {'hour': [], 'monday': [], 'tuesday': [], 'wednesday': [], 'thrusday': [], 'friday': [],}
|
|
||||||
|
|
||||||
hour = []
|
|
||||||
monday = []
|
|
||||||
tuesday = []
|
|
||||||
wednesday = []
|
|
||||||
thrusday = []
|
|
||||||
friday = []
|
|
||||||
|
|
||||||
a = 0
|
|
||||||
x = 0
|
|
||||||
i = 0
|
|
||||||
|
|
||||||
while True:
|
|
||||||
for x in range(6):
|
|
||||||
if x == 0:
|
|
||||||
hour.append(timetable['data']['Rows'][a][x])
|
|
||||||
elif x == 1:
|
|
||||||
monday.append(timetable['data']['Rows'][a][x])
|
|
||||||
elif x == 2:
|
|
||||||
tuesday.append(timetable['data']['Rows'][a][x])
|
|
||||||
elif x == 3:
|
|
||||||
wednesday.append(timetable['data']['Rows'][a][x])
|
|
||||||
elif x == 4:
|
|
||||||
thrusday.append(timetable['data']['Rows'][a][x])
|
|
||||||
elif x == 5:
|
|
||||||
friday.append(timetable['data']['Rows'][a][x])
|
|
||||||
if timetable['data']['Rows'][a] == timetable['data']['Rows'][-1]:
|
|
||||||
a = 0
|
|
||||||
break
|
|
||||||
a += 1
|
|
||||||
|
|
||||||
while True:
|
|
||||||
#<--------------HOURS-------------->
|
|
||||||
bs = BeautifulSoup(hour[i], 'html.parser')
|
|
||||||
hour[i] = [str.strip(x) for x in bs.strings if str.strip(x) != '']
|
|
||||||
unwanted_text = [str.strip(x.text) for x in bs.find_all()]
|
|
||||||
set(hour[i]).difference(unwanted_text)
|
|
||||||
|
|
||||||
#<--------------MONDAY-------------->
|
|
||||||
bs = BeautifulSoup(monday[i], 'html.parser')
|
|
||||||
for lesson in bs.find_all('span'):
|
|
||||||
monday[i] = lesson.text
|
|
||||||
break
|
|
||||||
|
|
||||||
#<--------------TUESDAY-------------->
|
|
||||||
bs = BeautifulSoup(tuesday[i], 'html.parser')
|
|
||||||
for lesson in bs.find_all('span'):
|
|
||||||
tuesday[i] = lesson.text
|
|
||||||
break
|
|
||||||
|
|
||||||
#<--------------WEDNESDAY-------------->
|
|
||||||
bs = BeautifulSoup(wednesday[i], 'html.parser')
|
|
||||||
for lesson in bs.find_all('span'):
|
|
||||||
wednesday[i] = lesson.text
|
|
||||||
break
|
|
||||||
|
|
||||||
#<--------------THRUSDAY-------------->
|
|
||||||
bs = BeautifulSoup(thrusday[i], 'html.parser')
|
|
||||||
for lesson in bs.find_all('span'):
|
|
||||||
thrusday[i] = lesson.text
|
|
||||||
break
|
|
||||||
|
|
||||||
#<--------------FRIDAY-------------->
|
|
||||||
bs = BeautifulSoup(friday[i], 'html.parser')
|
|
||||||
for lesson in bs.find_all('span'):
|
|
||||||
friday[i] = lesson.text
|
|
||||||
break
|
|
||||||
|
|
||||||
if hour[i] == hour[-1]:
|
|
||||||
i = 0
|
|
||||||
break
|
|
||||||
i += 1
|
|
||||||
|
|
||||||
json_timetable['hour'] = hour
|
|
||||||
json_timetable['monday'] = monday
|
|
||||||
json_timetable['tuesday'] = tuesday
|
|
||||||
json_timetable['wednesday'] = wednesday
|
|
||||||
json_timetable['thrusday'] = thrusday
|
|
||||||
json_timetable['friday'] = friday
|
|
||||||
|
|
||||||
return json_timetable
|
|
12
app/login.py
12
app/login.py
|
@ -59,11 +59,13 @@ def get_cookies(symbol, oun, s):
|
||||||
if weekday == x:
|
if weekday == x:
|
||||||
now = now - datetime.timedelta(days=x)
|
now = now - datetime.timedelta(days=x)
|
||||||
|
|
||||||
day = str(now.day)
|
day = now.day
|
||||||
month = str(now.month)
|
month = now.month
|
||||||
year = str(now.year)
|
year = now.year
|
||||||
|
|
||||||
date = year+'-'+month+'-'+day
|
date = datetime.date(year, month, day).isoformat()
|
||||||
|
|
||||||
|
date = f'{date}T00:00:00'
|
||||||
|
|
||||||
school_year = register_r.json()['data'][0]['DziennikRokSzkolny']
|
school_year = register_r.json()['data'][0]['DziennikRokSzkolny']
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ def get_cookies(symbol, oun, s):
|
||||||
'register_id': register_id,
|
'register_id': register_id,
|
||||||
'register_r': register_r.json(),
|
'register_r': register_r.json(),
|
||||||
'oun': oun,
|
'oun': oun,
|
||||||
'date': date,
|
'date': str(date),
|
||||||
'school_year': school_year,
|
'school_year': school_year,
|
||||||
'symbol': symbol,
|
'symbol': symbol,
|
||||||
's': s.cookies.get_dict()
|
's': s.cookies.get_dict()
|
||||||
|
|
19
app/views.py
19
app/views.py
|
@ -9,7 +9,7 @@ from django.contrib.sessions.models import Session
|
||||||
from .login import sender
|
from .login import sender
|
||||||
from .API.grades import get_grades
|
from .API.grades import get_grades
|
||||||
from .API.exams import prepare_exams_for_display
|
from .API.exams import prepare_exams_for_display
|
||||||
from .API.timetable import prepare_timetable_for_display
|
from .API.timetable import get_timetable
|
||||||
from .API.notes import prepare_notes_for_display
|
from .API.notes import prepare_notes_for_display
|
||||||
from .API.attendance import prepare_attendance_for_display
|
from .API.attendance import prepare_attendance_for_display
|
||||||
from .API.messages import get_messages
|
from .API.messages import get_messages
|
||||||
|
@ -54,4 +54,19 @@ def grades(request, *args, **kwargs):
|
||||||
oun = data['data']['oun']
|
oun = data['data']['oun']
|
||||||
s = data['data']['s']
|
s = data['data']['s']
|
||||||
grades = get_grades(register_id, register_r, oun, s)
|
grades = get_grades(register_id, register_r, oun, s)
|
||||||
return JsonResponse(grades, safe=False)
|
return JsonResponse(grades, safe=False)
|
||||||
|
else:
|
||||||
|
return render(request, 'index.html')
|
||||||
|
|
||||||
|
def timetable(request, *args, **kwargs):
|
||||||
|
if request.session.has_key('is_logged'):
|
||||||
|
data = json.loads(request.body)
|
||||||
|
register_id = data['data']['register_id']
|
||||||
|
register_r = data['data']['register_r']
|
||||||
|
oun = data['data']['oun']
|
||||||
|
s = data['data']['s']
|
||||||
|
date = data['data']['date']
|
||||||
|
timetable = get_timetable(register_id, register_r, oun, s, date)
|
||||||
|
return JsonResponse(timetable)
|
||||||
|
else:
|
||||||
|
return render(request, 'index.html')
|
|
@ -1,7 +1,22 @@
|
||||||
const timetable_ = document.querySelector('#timetable_');
|
const timetable_ = document.querySelector('#timetable_');
|
||||||
|
|
||||||
|
myStorage = window.sessionStorage;
|
||||||
|
|
||||||
const getTimetable = () => {
|
const getTimetable = () => {
|
||||||
document.querySelector('#content').innerHTML = 'Here is timetable (in my imagination)';
|
document.querySelector('#content').innerHTML = 'Here is timetable (in my imagination)';
|
||||||
|
cookies_data = sessionStorage.getItem('cookies_data');
|
||||||
|
csrfcookie_ = sessionStorage.getItem('csrfcookie');
|
||||||
|
fetch(url = '../api/timetable', {
|
||||||
|
method: 'POST',
|
||||||
|
mode: 'cors',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'X-CSRFToken': csrfcookie_
|
||||||
|
},
|
||||||
|
body: cookies_data
|
||||||
|
}).then(response => response.json()).then(data => {
|
||||||
|
console.log(data)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
timetable_.addEventListener('click', getTimetable);
|
timetable_.addEventListener('click', getTimetable);
|
|
@ -17,7 +17,7 @@ from django.urls import path
|
||||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||||
|
|
||||||
from app.views import default_view, content_view
|
from app.views import default_view, content_view
|
||||||
from app.views import login, grades
|
from app.views import login, grades, timetable
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
#views
|
#views
|
||||||
|
@ -26,6 +26,7 @@ urlpatterns = [
|
||||||
#api
|
#api
|
||||||
path('api/login', login, name='login'),
|
path('api/login', login, name='login'),
|
||||||
path('api/grades', grades, name='grades'),
|
path('api/grades', grades, name='grades'),
|
||||||
|
path('api/timetable', timetable, name='timetable'),
|
||||||
]
|
]
|
||||||
|
|
||||||
urlpatterns += staticfiles_urlpatterns()
|
urlpatterns += staticfiles_urlpatterns()
|
Loading…
Reference in a new issue