Getting attendance
This commit is contained in:
parent
f6e4fc27f0
commit
4705f2f524
4 changed files with 55 additions and 46 deletions
|
@ -2,52 +2,32 @@ import requests
|
|||
import json
|
||||
|
||||
def get_attendance(register_id, register_r, oun, s, date):
|
||||
cookies = s
|
||||
if oun != 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458':
|
||||
cookies = {
|
||||
"biezacyRokSzkolny": f"{register_r.json()['data'][0]['DziennikRokSzkolny']}",
|
||||
"idBiezacyDziennik": f"{register_r.json()['data'][0]['IdDziennik']}",
|
||||
"idBiezacyDziennikPrzedszkole": f"{register_r.json()['data'][0]['IdPrzedszkoleDziennik']}",
|
||||
"idBiezacyDziennikWychowankowie": f"{register_r.json()['data'][0]['IdWychowankowieDziennik']}",
|
||||
"idBiezacyUczen": f"{register_r.json()['data'][0]['IdUczen']}"
|
||||
}
|
||||
cookies.update({
|
||||
"biezacyRokSzkolny": f"{register_r['data'][0]['DziennikRokSzkolny']}",
|
||||
"idBiezacyDziennik": f"{register_r['data'][0]['IdDziennik']}",
|
||||
"idBiezacyDziennikPrzedszkole": f"{register_r['data'][0]['IdPrzedszkoleDziennik']}",
|
||||
"idBiezacyDziennikWychowankowie": f"{register_r['data'][0]['IdWychowankowieDziennik']}",
|
||||
"idBiezacyUczen": f"{register_r['data'][0]['IdUczen']}"
|
||||
})
|
||||
else:
|
||||
cookies = {
|
||||
"biezacyRokSzkolny": f"{register_r.json()['data'][0]['DziennikRokSzkolny']}",
|
||||
"idBiezacyDziennik": f"{register_r.json()['data'][0]['IdDziennik']}",
|
||||
"idBiezacyDziennikPrzedszkole": f"{register_r.json()['data'][0]['IdPrzedszkoleDziennik']}",
|
||||
"idBiezacyUczen": f"{register_r.json()['data'][0]['IdUczen']}"
|
||||
cookies.update({
|
||||
"biezacyRokSzkolny": f"{register_r['data'][0]['DziennikRokSzkolny']}",
|
||||
"idBiezacyDziennik": f"{register_r['data'][0]['IdDziennik']}",
|
||||
"idBiezacyDziennikPrzedszkole": f"{register_r['data'][0]['IdPrzedszkoleDziennik']}",
|
||||
"idBiezacyUczen": f"{register_r['data'][0]['IdUczen']}"
|
||||
})
|
||||
|
||||
headers = {
|
||||
'Accept-Encoding': 'gzip, deflate',
|
||||
'Accept': '*/*',
|
||||
'Connection': 'keep-alive',
|
||||
"User-Agent": "Wulkanowy-web :)"
|
||||
}
|
||||
|
||||
attendance_lessons = s.post(oun+'/FrekwencjaStatystykiPrzedmioty.mvc/Get', headers={"User-Agent": "Wulkanowy-web :)"}, cookies=cookies)
|
||||
attendance_lessons = requests.post(oun+'/FrekwencjaStatystykiPrzedmioty.mvc/Get', headers=headers, cookies=cookies)
|
||||
attendance_json_id = attendance_lessons.json()['data'][0]['Id']
|
||||
attendance = s.post(oun+'/Frekwencja.mvc/Get', headers={"User-Agent": "Wulkanowy-web :)"}, cookies=cookies, json={'idTypWpisuFrekwencji': attendance_json_id, 'data': date})
|
||||
attendance = requests.post(oun+'/Frekwencja.mvc/Get', headers=headers, cookies=cookies, json={'idTypWpisuFrekwencji': attendance_json_id, 'data': date})
|
||||
|
||||
return [attendance.json(), attendance_lessons.json()]
|
||||
|
||||
|
||||
def prepare_attendance_for_display(register_id, register_r, oun, s, date):
|
||||
json = get_attendance(register_id, register_r, oun, s, date)
|
||||
attendance = json[0]
|
||||
#attendance_lessons = json[1]
|
||||
i = 0
|
||||
a = 0
|
||||
|
||||
json_attendance = {0: []}
|
||||
|
||||
print(attendance)
|
||||
|
||||
if attendance['data']['Frekwencje'] != []:
|
||||
while True:
|
||||
json_attendance[a].append({'Content': attendance['data']['Frekwencje'][i]['Symbol'],
|
||||
'Lesson': attendance['data']['Frekwencje'][i]['PrzedmiotNazwa']})
|
||||
if attendance['data']['Frekwencje'][i] == attendance['data']['Frekwencje'][-1]:
|
||||
i = 0
|
||||
break
|
||||
if attendance['data']['Frekwencje'][i]['NrDnia'] != attendance['data']['Frekwencje'][i+1]['NrDnia']:
|
||||
a += 1
|
||||
json_attendance.update({a: []})
|
||||
i += 1
|
||||
else:
|
||||
json_attendance[a].append({'Content': 'Brak danych o frekwencji', 'Lesson': ''})
|
||||
|
||||
return json_attendance
|
15
app/views.py
15
app/views.py
|
@ -11,7 +11,7 @@ from .API.grades import get_grades
|
|||
from .API.exams import get_exams
|
||||
from .API.timetable import get_timetable
|
||||
from .API.notes import prepare_notes_for_display
|
||||
from .API.attendance import prepare_attendance_for_display
|
||||
from .API.attendance import get_attendance
|
||||
from .API.messages import get_messages
|
||||
from .API.homeworks import get_homeworks
|
||||
|
||||
|
@ -99,3 +99,16 @@ def homeworks(request, *args, **kwargs):
|
|||
return JsonResponse(homeworks)
|
||||
else:
|
||||
return render(request, 'index.html')
|
||||
|
||||
def attendance(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']
|
||||
attendance = get_attendance(register_id, register_r, oun, s, date)
|
||||
return JsonResponse(attendance, safe=False)
|
||||
else:
|
||||
return render(request, 'index.html')
|
|
@ -1,7 +1,22 @@
|
|||
const attendance_ = document.querySelector('#attendance_');
|
||||
|
||||
myStorage = window.sessionStorage;
|
||||
|
||||
const getAttendance = () => {
|
||||
document.querySelector('#content').innerHTML = 'Here is attendance (in my imagination)';
|
||||
cookies_data = sessionStorage.getItem('cookies_data');
|
||||
csrfcookie_ = sessionStorage.getItem('csrfcookie');
|
||||
fetch(url = '../api/attendance', {
|
||||
method: 'POST',
|
||||
mode: 'cors',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfcookie_
|
||||
},
|
||||
body: cookies_data
|
||||
}).then(response => response.json()).then(data => {
|
||||
console.log(data);
|
||||
})
|
||||
}
|
||||
|
||||
attendance_.addEventListener('click', getAttendance);
|
|
@ -17,7 +17,7 @@ from django.urls import path
|
|||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
|
||||
from app.views import default_view, content_view
|
||||
from app.views import login, grades, timetable, exams, homeworks
|
||||
from app.views import login, grades, timetable, exams, homeworks, attendance
|
||||
|
||||
urlpatterns = [
|
||||
#views
|
||||
|
@ -29,6 +29,7 @@ urlpatterns = [
|
|||
path('api/timetable', timetable, name='timetable'),
|
||||
path('api/exams', exams, name='exams'),
|
||||
path('api/homeworks', homeworks, name='homeworks'),
|
||||
path('api/attendance', attendance, name='attendance'),
|
||||
]
|
||||
|
||||
urlpatterns += staticfiles_urlpatterns()
|
Loading…
Reference in a new issue