Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint for scrapper info created #72

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion django/university/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
path('course_last_year/<int:course_id>/', views.course_last_year),
path('schedule/<int:course_unit_id>/', views.schedule),
path('statistics/', views.data),
path('professors/<int:schedule>/', views.professor)
path('professors/<int:schedule>/', views.professor),
path('info/', views.info)
]

17 changes: 16 additions & 1 deletion django/university/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from university.models import ScheduleProfessor
from university.models import CourseMetadata
from university.models import Statistics
from university.models import Info
from django.http import JsonResponse
from django.core import serializers
from rest_framework.decorators import api_view
Expand Down Expand Up @@ -131,7 +132,6 @@ def data(request):
"""
Returns all the professors of a class of the schedule id
"""

@api_view(["GET"])
def professor(request, schedule):
schedule_professors = list(ScheduleProfessor.objects.filter(schedule=schedule).values())
Expand All @@ -144,3 +144,18 @@ def professor(request, schedule):
'professor_name': professor.professor_name
})
return JsonResponse(professors, safe=False)


"""
Returns the contents of the info table
"""
@api_view(["GET"])
def info(request):
info = Info.objects.first()
if info:
json_data = {
'date': timezone.localtime(info.date).strftime('%Y-%m-%d %H:%M:%S')
}
return JsonResponse(json_data, safe=False)
else:
return JsonResponse({}, safe=False)
15 changes: 12 additions & 3 deletions mysql/sql/00_schema_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ CREATE TABLE `course_metadata` (
`ects` float(4) NOT NULL
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;




-- --------------------------------------------------------
--
-- Table structure for table `schedule`
Expand Down Expand Up @@ -117,8 +114,18 @@ CREATE TABLE `professor` (
`professor_name` varchar(100)
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;

-- --------------------------------------------------------

--
-- Table structure for table `info`
--

CREATE TABLE `info` (
`date` datetime
) ENGINE=InnoDB CHARSET = utf8 COLLATE = utf8_general_ci;

-- --------------------------------------------------------

-- Table structure for table `statistics`
--

Expand Down Expand Up @@ -146,6 +153,8 @@ alter TABLE course_metadata ADD FOREIGN KEY (`course_id`) REFERENCES `course`(`i
alter TABLE schedule ADD PRIMARY KEY (`id`);
alter TABLE schedule ADD FOREIGN KEY (`course_unit_id`) REFERENCES `course_unit`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;

alter TABLE info ADD PRIMARY KEY (`date`);

alter TABLE statistics ADD PRIMARY KEY (`course_unit_id`);

alter TABLE professor ADD PRIMARY KEY (`sigarra_id`);
Expand Down