Implement django rest framework && change name 'oun'(xd) to school_url

This commit is contained in:
Pengwius 2021-04-10 12:18:58 +02:00
parent 5dcb6ed72e
commit 7045853679
4 changed files with 67 additions and 44 deletions

View file

@ -41,18 +41,18 @@ def send(url, data, fail, diary_url, symbol, s):
bs = BeautifulSoup(crtr.content, 'html.parser')
for a in bs.find_all('a', title='Uczeń'):
oun = a['href']
school_url = a['href']
break
if diary_url == 'http://cufs.fakelog.cf/':
oun = 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458'
school_url = 'http://uonetplus-uczen.fakelog.cf/powiatwulkanowy/123458'
cookies = get_cookies(symbol, oun, s, diary_url)
cookies = get_cookies(symbol, school_url, s, diary_url)
return cookies
def get_cookies(symbol, oun, s, diary_url):
students = s.post(oun+'/UczenDziennik.mvc/Get')
def get_cookies(symbol, school_url, s, diary_url):
students = s.post(school_url+'/UczenDziennik.mvc/Get')
register_id = students.json()['data'][0]['Okresy'][0]['Id']
now = datetime.datetime.now()
@ -75,7 +75,7 @@ def get_cookies(symbol, oun, s, diary_url):
data = {
'register_id': register_id,
'students': students.json(),
'oun': oun,
'school_url': school_url,
'date': str(date),
'school_year': school_year,
'symbol': symbol,

View file

@ -5,6 +5,7 @@ from django.http import HttpResponse, JsonResponse
from django.shortcuts import render
import json
import requests
from rest_framework.decorators import api_view
from django.core import serializers
from django.shortcuts import redirect
from django.contrib.sessions.models import Session
@ -25,6 +26,7 @@ from .decrypt import decrypt_cookies
import datetime
#API
@api_view(['POST'])
def login(request, *args, **kwargs):
data = json.loads(request.body)
loginName = data['loginName']
@ -53,20 +55,22 @@ def login(request, *args, **kwargs):
data_response = {'success': True, 'data': sender_return}
return JsonResponse(data_response)
@api_view(['POST'])
def grades(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
grades = get_grades(register_id, students, oun, s)
grades = get_grades(register_id, students, school_url, s)
return JsonResponse(grades)
else:
return redirect('../')
@api_view(['POST'])
def timetable(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
@ -74,7 +78,7 @@ def timetable(request, *args, **kwargs):
data = json.loads(data['cookies'])
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
@ -94,11 +98,12 @@ def timetable(request, *args, **kwargs):
date = datetime.date(year, month, day).isoformat()
date = f'{date}T00:00:00'
timetable = get_timetable(register_id, students, oun, s, date)
timetable = get_timetable(register_id, students, school_url, s, date)
return JsonResponse(timetable)
else:
return redirect('../')
@api_view(['POST'])
def exams(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
@ -106,7 +111,7 @@ def exams(request, *args, **kwargs):
data = json.loads(data['cookies'])
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
@ -127,11 +132,12 @@ def exams(request, *args, **kwargs):
date = f'{date}T00:00:00'
school_year = data['data']['school_year']
exams = get_exams(register_id, students, oun, s, date, school_year)
exams = get_exams(register_id, students, school_url, s, date, school_year)
return JsonResponse(exams)
else:
return redirect('../')
@api_view(['POST'])
def homeworks(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
@ -139,7 +145,7 @@ def homeworks(request, *args, **kwargs):
data = json.loads(data['cookies'])
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
@ -160,11 +166,12 @@ def homeworks(request, *args, **kwargs):
date = f'{date}T00:00:00'
school_year = data['data']['school_year']
homeworks = get_homeworks(register_id, students, oun, s, date, school_year)
homeworks = get_homeworks(register_id, students, school_url, s, date, school_year)
return JsonResponse(homeworks)
else:
return redirect('../')
@api_view(['POST'])
def attendance(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
@ -172,7 +179,7 @@ def attendance(request, *args, **kwargs):
data = json.loads(data['cookies'])
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
@ -192,135 +199,144 @@ def attendance(request, *args, **kwargs):
date = datetime.date(year, month, day).isoformat()
date = f'{date}T00:00:00'
attendance = get_attendance(register_id, students, oun, s, date)
attendance = get_attendance(register_id, students, school_url, s, date)
return JsonResponse(attendance, safe=False)
else:
return redirect('../')
@api_view(['POST'])
def notes(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
notes = get_notes(register_id, students, oun, s)
notes = get_notes(register_id, students, school_url, s)
return JsonResponse(notes)
else:
return redirect('../')
@api_view(['POST'])
def registered_devices(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
registered = get_registered_devices(register_id, students, oun, s)
registered = get_registered_devices(register_id, students, school_url, s)
return JsonResponse(registered)
else:
return redirect('../')
@api_view(['POST'])
def register_device_(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
register_data = register_device(register_id, students, oun, s)
register_data = register_device(register_id, students, school_url, s)
return JsonResponse(register_data)
else:
return redirect('../')
@api_view(['POST'])
def received_messages(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
date = data['data']['date']
school_year = data['data']['school_year']
symbol = data['data']['symbol']
received_messages = get_received_messages(register_id, students, oun, s, date, school_year, symbol)
received_messages = get_received_messages(register_id, students, school_url, s, date, school_year, symbol)
return JsonResponse(received_messages)
else:
return redirect('../')
@api_view(['POST'])
def sent_messages(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
date = data['data']['date']
school_year = data['data']['school_year']
symbol = data['data']['symbol']
sent_messages = get_sent_messages(register_id, students, oun, s, date, school_year, symbol)
sent_messages = get_sent_messages(register_id, students, school_url, s, date, school_year, symbol)
return JsonResponse(sent_messages)
else:
return redirect('../')
@api_view(['POST'])
def deleted_messages(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
date = data['data']['date']
school_year = data['data']['school_year']
symbol = data['data']['symbol']
deleted_messages = get_deleted_messages(register_id, students, oun, s, date, school_year, symbol)
deleted_messages = get_deleted_messages(register_id, students, school_url, s, date, school_year, symbol)
return JsonResponse(deleted_messages)
else:
return redirect('../')
@api_view(['POST'])
def recipients(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
date = data['data']['date']
school_year = data['data']['school_year']
symbol = data['data']['symbol']
recipients = get_recipients(register_id, students, oun, s, date, school_year, symbol)
recipients = get_recipients(register_id, students, school_url, s, date, school_year, symbol)
return JsonResponse(recipients)
else:
return redirect('../')
@api_view(['POST'])
def school_data(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
school_data = get_school_data(register_id, students, oun, s)
school_data = get_school_data(register_id, students, school_url, s)
return JsonResponse(school_data)
else:
return redirect('../')
@api_view(['POST'])
def dashboard(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
@ -336,13 +352,14 @@ def dashboard(request, *args, **kwargs):
else:
return redirect('../')
@api_view(['POST'])
def send(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
cookies_data = json.loads(data['cookies_data'])
register_id = cookies_data['data']['register_id']
students = cookies_data['data']['students']
oun = cookies_data['data']['oun']
school_url = cookies_data['data']['school_url']
s = cookies_data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
@ -350,18 +367,19 @@ def send(request, *args, **kwargs):
school_year = cookies_data['data']['school_year']
symbol = cookies_data['data']['symbol']
send_data = {'data': data['data'], 'subject': data['subject'], 'content': data['content']}
send = send_message(register_id, students, oun, s, date, school_year, symbol, send_data)
send = send_message(register_id, students, school_url, s, date, school_year, symbol, send_data)
return JsonResponse(send, safe=False)
else:
return redirect('../')
@api_view(['POST'])
def message_content(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
cookies_data = json.loads(data['cookies_data'])
register_id = cookies_data['data']['register_id']
students = cookies_data['data']['students']
oun = cookies_data['data']['oun']
school_url = cookies_data['data']['school_url']
s = cookies_data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
@ -369,54 +387,58 @@ def message_content(request, *args, **kwargs):
school_year = cookies_data['data']['school_year']
symbol = cookies_data['data']['symbol']
message_id = data['message_id']
content = get_message_content(register_id, students, oun, s, date, school_year, symbol, message_id)
content = get_message_content(register_id, students, school_url, s, date, school_year, symbol, message_id)
return JsonResponse(content, safe=False)
else:
return redirect('../')
@api_view(['POST'])
def student_data(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
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, students, oun, s)
data = get_student_data(register_id, students, school_url, s)
return JsonResponse(data)
else:
return redirect('../')
#STATS
@api_view(['POST'])
def partial(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
partial_stats = get_partial(register_id, students, oun, s)
partial_stats = get_partial(register_id, students, school_url, s)
return JsonResponse(partial_stats)
else:
return redirect('../')
@api_view(['POST'])
def year(request, *args, **kwargs):
if request.session.has_key('is_logged'):
data = json.loads(request.body)
register_id = data['data']['register_id']
students = data['data']['students']
oun = data['data']['oun']
school_url = data['data']['school_url']
s = data['data']['s']
key = bytes(request.session[request.session.session_key], 'utf-8')
s = decrypt_cookies(s, key)
year_stats = get_year(register_id, students, oun, s)
year_stats = get_year(register_id, students, school_url, s)
return JsonResponse(year_stats)
else:
return redirect('../')
@api_view(['GET'])
def log_out(request, *args, **kwargs):
del request.session[request.session.session_key]
del request.session['is_logged']

View file

@ -3,3 +3,4 @@ bs4==0.0.1
Django==3.1.3
requests==2.24.0
cryptography==3.2.1
djangorestframework==3.12.4

View file

@ -39,6 +39,7 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
# My Apps
'app',
@ -109,7 +110,6 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/