From 7cded5d5ba08b26d4c47586e3f6ab3b3159b1c14 Mon Sep 17 00:00:00 2001 From: Tomasz Date: Sat, 30 Jan 2021 21:09:11 +0100 Subject: [PATCH] Getting student data - backend & tests --- app/API/student_data.py | 31 +++++++++++++++++++++++++++++++ app/views.py | 15 +++++++++++++++ tests/test_views.py | 4 ++++ wulkanowy/urls.py | 3 ++- 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 app/API/student_data.py diff --git a/app/API/student_data.py b/app/API/student_data.py new file mode 100644 index 0000000..544e254 --- /dev/null +++ b/app/API/student_data.py @@ -0,0 +1,31 @@ +import json +import requests + +def get_student_data(register_id, register_r, oun, s): + cookies = s + if oun != 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458': + 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.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 :)" + } + + student_data = requests.post(f'{oun}/Uczen.mvc/Get', headers=headers, cookies=cookies) + + return student_data.json() \ No newline at end of file diff --git a/app/views.py b/app/views.py index ee14306..920551e 100644 --- a/app/views.py +++ b/app/views.py @@ -19,6 +19,7 @@ from .API.homeworks import get_homeworks from .API.mobile_access import get_registered_devices, register_device from .API.school_data import get_school_data from .API.dashboard import get_dashboard +from .API.student_data import get_student_data from .decrypt import decrypt_cookies #API @@ -300,5 +301,19 @@ def message_content(request, *args, **kwargs): message_id = data['message_id'] content = get_message_content(register_id, register_r, oun, s, date, school_year, symbol, message_id) return JsonResponse(content, safe=False) + else: + return redirect('../') + +def student_data(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'] + key = bytes(request.session[request.session.session_key], 'utf-8') + s = decrypt_cookies(s, key) + data = get_student_data(register_id, register_r, oun, s) + return JsonResponse(data) else: return redirect('../') \ No newline at end of file diff --git a/tests/test_views.py b/tests/test_views.py index e4b94bd..2357a64 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -115,6 +115,10 @@ def get_data_test(client, cookies_data, assertEquals): assertEquals(response.status_code, 200) recipients = response.json()['addressee']['data'] + #STUDENT DATA + response = client.post(reverse('student_data'), content_type='application/xml', data=json.dumps(cookies_data)) + assertEquals(response.status_code, 200) + #SEND MESSAGE for recipient in recipients: send_data = { diff --git a/wulkanowy/urls.py b/wulkanowy/urls.py index 583ba16..93d785c 100644 --- a/wulkanowy/urls.py +++ b/wulkanowy/urls.py @@ -17,7 +17,7 @@ from django.urls import path from django.contrib.staticfiles.urls import staticfiles_urlpatterns from frontend.views import default_view, content_view, account_manager_view -from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data, dashboard, recipients, send, message_content +from app.views import login, grades, timetable, exams, homeworks, attendance, notes, registered_devices, register_device_, received_messages, sent_messages, deleted_messages, school_data, dashboard, recipients, send, message_content, student_data urlpatterns = [ #views @@ -34,6 +34,7 @@ urlpatterns = [ path('api/notes', notes, name='notes'), path('api/school_data', school_data, name='school_data'), path('api/dashboard', dashboard, name='dashboard'), + path('api/student_data', student_data, name='student_data'), #MOBILE ACCESS path('api/mobile/registered', registered_devices, name='registered_devices'), path('api/mobile/register', register_device_, name='register_device'),