From 2296d53cad0cea5fcc69253f48dd6d0714af21c5 Mon Sep 17 00:00:00 2001 From: KrKOo Date: Mon, 14 Mar 2022 15:20:35 +0100 Subject: [PATCH] Backend API added --- .editorconfig | 10 +++++++ main.js => extension/main.js | 48 +++++++++---------------------- extension/manifest.json | 13 +++++++++ manifest.json | 13 --------- server/.gitignore | 55 ++++++++++++++++++++++++++++++++++++ server/Procfile | 1 + server/Scrapper/__init__.py | 0 server/Scrapper/scrapper.py | 36 +++++++++++++++++++++++ server/requirements.txt | 21 ++++++++++++++ server/server.py | 28 ++++++++++++++++++ 10 files changed, 178 insertions(+), 47 deletions(-) create mode 100644 .editorconfig rename main.js => extension/main.js (67%) create mode 100644 extension/manifest.json delete mode 100644 manifest.json create mode 100644 server/.gitignore create mode 100644 server/Procfile create mode 100644 server/Scrapper/__init__.py create mode 100644 server/Scrapper/scrapper.py create mode 100644 server/requirements.txt create mode 100644 server/server.py diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1a32399 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +end_of_line = lf +max_line_length = off diff --git a/main.js b/extension/main.js similarity index 67% rename from main.js rename to extension/main.js index bc31163..c067427 100644 --- a/main.js +++ b/extension/main.js @@ -1,5 +1,3 @@ - - // Returns the ISO week of the date. Date.prototype.getWeek = function () { var date = new Date(this.getTime()); @@ -13,25 +11,11 @@ Date.prototype.getWeek = function () { - 3 + (week1.getDay() + 6) % 7) / 7); } -const getCoursePage = (course) => { - return fetch(`https://www.fit.vut.cz/study/course/${course}/.cs`) - .then(response => response.text()) - .then(html => { - const parser = new DOMParser(); - const doc = parser.parseFromString(html, 'text/html'); - return doc; - }) -} - const getLectureTitles = (course) => { - return getCoursePage(course) - .then(page => { - const planList = page.querySelectorAll('.b-detail__content ol li') - let lectureTitles = [] - planList.forEach(planElement => { - lectureTitles.push(planElement.innerText); - }) - return lectureTitles; + return fetch(`https://fitscrap.herokuapp.com/lecture-titles/${course}`) + .then(response => response.json()) + .catch(e => { + console.error(e); }) } @@ -56,10 +40,10 @@ const getDateFromLectureString = (str) => { } const insertLectureNumbering = async (course) => { + const lectureTitles = await getLectureTitles(course) || []; - const lectureTitles = await getLectureTitles(course); - - const lectureList = document.querySelector("ul"); + // get the last