Skip to content

Commit 1768e94

Browse files
committed
preserve scraping paths
1 parent 5195986 commit 1768e94

File tree

6 files changed

+378
-316
lines changed

6 files changed

+378
-316
lines changed

functions/src/types/entities.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export interface FirebaseData extends Record<string, any> {
1616
updatedByRef?: DocumentReference<UserData>;
1717
}
1818

19+
/**
20+
* Scraped with info
21+
*/
22+
export type ScrapedWith = [eSIALevel, eSIAPlace, uSIAFaculty?, uSIAProgram?, eSIATypology?];
23+
1924
/**
2025
* Firebase log
2126
*
@@ -245,4 +250,9 @@ export interface CourseData extends FirebaseData {
245250
scrapedAt?: Timestamp;
246251
/** @automated Last scrape date with errors */
247252
scrapedWithErrorsAt?: Timestamp;
253+
/**
254+
* Scrapper was able to get the course with this info
255+
* @automation
256+
*/
257+
lastScrapedWith?: ScrapedWith;
248258
}

pages/administrar/cursos.vue

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,12 @@
7474
middleware: ["can-develop"],
7575
});
7676
77-
function mapCourse({
78-
updatedAt,
79-
createdAt,
80-
scrapedAt,
81-
scrapedWithErrorsAt,
82-
updatedBy,
83-
createdBy,
84-
...course
85-
}: Course) {
77+
function mapCourse(course: Course) {
8678
return {
79+
id: course.id,
8780
code: course.code,
88-
updatedAt,
89-
scrapedAt,
90-
updatedBy,
81+
scrapedAt: course.scrapedAt,
82+
updatedBy: course.updatedBy,
9183
course,
9284
logs: 1,
9385
};

pages/cursos/[courseId].vue

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<div v-if="withScrapingErrors" class="flx --flxColumn --flx-center --width-100">
2727
<XamuBoxMessage :theme="eColors.DANGER">
2828
<div class="txt --txtAlign-center">
29-
<p>Nos ha sido imposible obtener datos de este curso.</p>
29+
<p>Lo sentimos, nos ha sido imposible obtener datos de este curso.</p>
3030
<p class="--txtSize-sm">
3131
Aunque el curso esta reportado, su información parece ser inadecuada
3232
y no nos permite encontrarlo en el SIA.
@@ -94,7 +94,8 @@
9494
class="flx --flxColumn --flx-start-stretch --maxWidth-440"
9595
>
9696
<div class="txt">
97-
<p>
97+
<p>¡Gracias por ayudarnos a mejorar!</p>
98+
<p class="--txtSize-sm">
9899
*Idealmente, los datos deben coincidir con los
99100
mismos pasos que seguirías para buscar el curso
100101
en el SIA.
@@ -269,7 +270,6 @@
269270
import type { EnrolledGroup } from "~/functions/src/types/entities";
270271
import type { CourseValues } from "~/resources/types/values";
271272
import { resolveSnapshotDefaults } from "~/resources/utils/firestore";
272-
import { eSIALevel, eSIAPlace } from "~/functions/src/types/SIA";
273273
274274
import { TableTeachersList, TableEnroll, TableWeek } from "#components";
275275
@@ -592,24 +592,11 @@
592592
593593
scraping.value = true;
594594
595-
const {
596-
code = "",
597-
level = eSIALevel.PREGRADO,
598-
place = eSIAPlace.BOGOTÁ,
599-
faculty,
600-
faculties = [faculty],
601-
programs = [],
602-
typologies = [],
603-
} = firebaseCourse;
595+
const { code = "" } = firebaseCourse;
604596
605597
try {
606598
// Scrape from old SIA. Do not refetch from hydration
607599
await useFetchQuery<boolean>("/api/groups/scrape", {
608-
level,
609-
place,
610-
faculties,
611-
programs,
612-
typologies,
613600
code,
614601
});
615602
} catch (err) {
@@ -655,14 +642,18 @@
655642
});
656643
}
657644
645+
const firebaseCourse: Course = resolveSnapshotDefaults(
646+
snapshot.ref.path,
647+
snapshot.data()
648+
);
658649
const {
659-
createdByRef,
660-
updatedByRef,
650+
name,
651+
description,
652+
alternativeNames = [name],
653+
updatedAt,
661654
scrapedAt,
662655
scrapedWithErrorsAt,
663-
...firebaseCourse
664-
}: Course = resolveSnapshotDefaults(snapshot.ref.path, snapshot.data());
665-
const { name, description, alternativeNames = [name], updatedAt } = firebaseCourse;
656+
} = firebaseCourse;
666657
667658
// Update with hydration conditionally
668659
if (course.value?.updatedAt !== updatedAt) {

resources/types/scraping.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import type { ScrapedWith } from "~/functions/src/types/entities";
12
import type { Group } from "./entities";
23

34
export interface ScrapedCourse {
45
groups?: Group[];
56
name: string;
67
code: string;
78
description: string;
9+
lastScrapedWith: ScrapedWith;
810
}

resources/utils/promises.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ export function TimedPromise<T>(executor: tPromiseExecutor<T>, fallback?: T, tim
1616
if (fallback) {
1717
console.warn("Timed out with fallback");
1818

19-
return resolve(fallback);
19+
resolve(fallback);
20+
} else {
21+
reject("Timed out");
2022
}
21-
22-
reject("Timed out");
2323
}, timeoutSeconds * 1000);
2424
}),
2525
]);

0 commit comments

Comments
 (0)