Compare commits
No commits in common. "99a81ba6a00b8656a400ae56d7a18a7c401fd31d" and "23d87618dc8fe0787b346ef22252098f3ecc0d3e" have entirely different histories.
99a81ba6a0
...
23d87618dc
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
pdf
|
pdf
|
||||||
csv
|
csv
|
||||||
pdf.json
|
|
||||||
|
@ -28,16 +28,6 @@ pub fn get_routes() -> Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_pdf_links() -> Result<Vec<String>, reqwest::Error> {
|
async fn get_pdf_links() -> Result<Vec<String>, reqwest::Error> {
|
||||||
if let Ok(metadata) = fs::metadata("pdf.json") {
|
|
||||||
let last_modified = metadata.modified().unwrap();
|
|
||||||
let now = std::time::SystemTime::now();
|
|
||||||
let diff = now.duration_since(last_modified).unwrap().as_secs();
|
|
||||||
if diff < 30 * 60 {
|
|
||||||
let data = fs::read_to_string("pdf.json").unwrap();
|
|
||||||
return Ok(serde_json::from_str(&data).unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let response = reqwest::get("https://cassandroferminervi.edu.it/orario-scolastico/")
|
let response = reqwest::get("https://cassandroferminervi.edu.it/orario-scolastico/")
|
||||||
.await?
|
.await?
|
||||||
.text()
|
.text()
|
||||||
@ -51,9 +41,6 @@ async fn get_pdf_links() -> Result<Vec<String>, reqwest::Error> {
|
|||||||
result.push(element.attr("href").unwrap().to_owned());
|
result.push(element.attr("href").unwrap().to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
let data = serde_json::to_string(&result).unwrap();
|
|
||||||
fs::write("pdf.json", data).unwrap();
|
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,7 +158,12 @@ pub async fn get_class(Query(params): Query<FilterByClassQuery>) -> impl IntoRes
|
|||||||
for record in rdr.records() {
|
for record in rdr.records() {
|
||||||
let record = match record {
|
let record = match record {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
Err(_) => continue,
|
Err(_) => {
|
||||||
|
return (
|
||||||
|
StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
|
Json(json!({ "errore": "Formato non supportato"})),
|
||||||
|
)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
for (i, cell) in record.iter().enumerate() {
|
for (i, cell) in record.iter().enumerate() {
|
||||||
if cell == params.classe {
|
if cell == params.classe {
|
||||||
@ -210,8 +202,6 @@ pub fn get_header(record: &StringRecord) -> Header {
|
|||||||
.position(|x| !x.is_empty())
|
.position(|x| !x.is_empty())
|
||||||
.unwrap_or(record.len());
|
.unwrap_or(record.len());
|
||||||
|
|
||||||
let field = field.replace("ì", "i").replace(" ", "").to_uppercase();
|
|
||||||
|
|
||||||
if field == "DOCENTE" {
|
if field == "DOCENTE" {
|
||||||
docente = i as u8;
|
docente = i as u8;
|
||||||
} else if field == "LUNEDI" {
|
} else if field == "LUNEDI" {
|
||||||
@ -260,7 +250,12 @@ pub async fn get_teachers(Query(params): Query<GetTeachersQuery>) -> impl IntoRe
|
|||||||
for record in rdr.records() {
|
for record in rdr.records() {
|
||||||
let record = match record {
|
let record = match record {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
Err(_) => continue,
|
Err(_) => {
|
||||||
|
return (
|
||||||
|
StatusCode::UNPROCESSABLE_ENTITY,
|
||||||
|
Json(json!({ "errore": "Formato non supportato"})),
|
||||||
|
)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(teacher) = record.get(header.teacher as usize) {
|
if let Some(teacher) = record.get(header.teacher as usize) {
|
||||||
@ -309,10 +304,7 @@ pub async fn get_classes(Query(params): Query<GetClassesQuery>) -> impl IntoResp
|
|||||||
let mut classes: Vec<HashMap<char, HashSet<String>>> = vec![HashMap::new(); 5];
|
let mut classes: Vec<HashMap<char, HashSet<String>>> = vec![HashMap::new(); 5];
|
||||||
|
|
||||||
for record in rdr.records() {
|
for record in rdr.records() {
|
||||||
let record = match record {
|
let record = record.unwrap();
|
||||||
Ok(x) => x,
|
|
||||||
Err(_) => continue,
|
|
||||||
};
|
|
||||||
for (i, cell) in record.iter().enumerate() {
|
for (i, cell) in record.iter().enumerate() {
|
||||||
for (_, range) in header.weekdays.clone() {
|
for (_, range) in header.weekdays.clone() {
|
||||||
if range.contains(&i) && is_valid_class(cell) {
|
if range.contains(&i) && is_valid_class(cell) {
|
||||||
|
@ -54,7 +54,7 @@ function load_classes(id) {
|
|||||||
}
|
}
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
const option = document.createElement("option");
|
const option = document.createElement("option");
|
||||||
option.value = i + 1;
|
option.value = i;
|
||||||
option.text = i + 1;
|
option.text = i + 1;
|
||||||
select.appendChild(option);
|
select.appendChild(option);
|
||||||
}
|
}
|
||||||
@ -71,16 +71,6 @@ function make_teacher_table(id, teacher) {
|
|||||||
fetch(`/api/professore?id=${id}&professore=${teacher}`)
|
fetch(`/api/professore?id=${id}&professore=${teacher}`)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
for (let key in data) {
|
|
||||||
let i = data[key].length - 1;
|
|
||||||
while (i >= 0 && data[key][i] === "") {
|
|
||||||
data[key].pop();
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const columns = Math.max(
|
|
||||||
...Object.values(data).map((vettore) => vettore.length),
|
|
||||||
);
|
|
||||||
let table = document.getElementById("table");
|
let table = document.getElementById("table");
|
||||||
let tbody = document.createElement("tbody");
|
let tbody = document.createElement("tbody");
|
||||||
let week = [
|
let week = [
|
||||||
@ -97,21 +87,12 @@ function make_teacher_table(id, teacher) {
|
|||||||
th.scope = "row";
|
th.scope = "row";
|
||||||
th.textContent = weekday;
|
th.textContent = weekday;
|
||||||
tr.appendChild(th);
|
tr.appendChild(th);
|
||||||
if (data[weekday] != null) {
|
|
||||||
let inserted = 0;
|
|
||||||
data[weekday].forEach((teacher_class) => {
|
data[weekday].forEach((teacher_class) => {
|
||||||
let td = document.createElement("td");
|
let td = document.createElement("td");
|
||||||
td.textContent = teacher_class;
|
td.textContent = teacher_class;
|
||||||
tr.appendChild(td);
|
tr.appendChild(td);
|
||||||
inserted++;
|
|
||||||
});
|
});
|
||||||
while (inserted < columns) {
|
|
||||||
let td = document.createElement("td");
|
|
||||||
tr.appendChild(td);
|
|
||||||
inserted++;
|
|
||||||
}
|
|
||||||
tbody.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
table.appendChild(tbody);
|
table.appendChild(tbody);
|
||||||
document.getElementById("table").removeAttribute("aria-busy");
|
document.getElementById("table").removeAttribute("aria-busy");
|
||||||
@ -126,16 +107,6 @@ function make_student_table(id, student_class) {
|
|||||||
fetch(`/api/classe?id=${id}&classe=${student_class}`)
|
fetch(`/api/classe?id=${id}&classe=${student_class}`)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
for (let key in data) {
|
|
||||||
let i = data[key].length - 1;
|
|
||||||
while (i >= 0 && data[key][i] === "") {
|
|
||||||
data[key].pop();
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const columns = Math.max(
|
|
||||||
...Object.values(data).map((vettore) => vettore.length),
|
|
||||||
);
|
|
||||||
let table = document.getElementById("table");
|
let table = document.getElementById("table");
|
||||||
let tbody = document.createElement("tbody");
|
let tbody = document.createElement("tbody");
|
||||||
let week = [
|
let week = [
|
||||||
@ -152,21 +123,12 @@ function make_student_table(id, student_class) {
|
|||||||
th.scope = "row";
|
th.scope = "row";
|
||||||
th.textContent = weekday;
|
th.textContent = weekday;
|
||||||
tr.appendChild(th);
|
tr.appendChild(th);
|
||||||
if (data[weekday] != null) {
|
|
||||||
let inserted = 0;
|
|
||||||
data[weekday].forEach((student_class) => {
|
data[weekday].forEach((student_class) => {
|
||||||
let td = document.createElement("td");
|
let td = document.createElement("td");
|
||||||
td.textContent = student_class;
|
td.textContent = student_class;
|
||||||
tr.appendChild(td);
|
tr.appendChild(td);
|
||||||
inserted++;
|
|
||||||
});
|
});
|
||||||
while (inserted < columns) {
|
|
||||||
let td = document.createElement("td");
|
|
||||||
tr.appendChild(td);
|
|
||||||
inserted++;
|
|
||||||
}
|
|
||||||
tbody.appendChild(tr);
|
tbody.appendChild(tr);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
table.appendChild(tbody);
|
table.appendChild(tbody);
|
||||||
document.getElementById("table").removeAttribute("aria-busy");
|
document.getElementById("table").removeAttribute("aria-busy");
|
||||||
@ -206,7 +168,7 @@ function load_section() {
|
|||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object.keys(data[year - 1]).forEach((el) => {
|
Object.keys(data[year]).forEach((el) => {
|
||||||
const option = document.createElement("option");
|
const option = document.createElement("option");
|
||||||
option.value = el;
|
option.value = el;
|
||||||
option.text = el;
|
option.text = el;
|
||||||
@ -225,7 +187,7 @@ function load_major() {
|
|||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data[year - 1][section].forEach((el) => {
|
data[year][section].forEach((el) => {
|
||||||
const option = document.createElement("option");
|
const option = document.createElement("option");
|
||||||
option.value = el;
|
option.value = el;
|
||||||
option.text = el;
|
option.text = el;
|
||||||
|
Loading…
Reference in New Issue
Block a user