From e4b7eaa67cdd6982dae8d32e52aa8c4bcdc56677 Mon Sep 17 00:00:00 2001 From: zainuldeen <104352655+zainuldeen@users.noreply.github.com> Date: Sun, 11 Feb 2024 18:57:27 +0000 Subject: [PATCH 1/2] removed: all ss before crawling --- src/index.ts | 6 ++++-- src/lib/util.ts | 13 +++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 44e554448..70ffcef9e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import dotenv from 'dotenv'; dotenv.config(); import { intro, outro, spinner, select } from '@clack/prompts'; -import { delay, replaceAll, sleep } from './lib/util'; +import { delay, replaceAll, sleep, clearFolder } from './lib/util'; import { scrapeMetaData } from './scrapper/meta_data'; import { write_metadata, writeTimetableData, calculateTeachersTimetable, calculatePastTimetableInputOptions, calculateRoomsTimeTable } from './lib/firebase'; @@ -65,6 +65,9 @@ else if(option as CLI_OPTIONS == CLI_OPTIONS.rooms_timetable) if ((option as CLI_OPTIONS) != CLI_OPTIONS.crawler) process.exit(0) +// removes all screen shots +clearFolder("/dist") + /// INTRO intro('Welcome to LGU Timetable Crawler 🤖'); @@ -78,7 +81,6 @@ const intro_cli = async () => { await intro_cli(); var metaData = undefined; - var hasCache = existsSync(CACHE_FILE_NAME); if (hasCache) { diff --git a/src/lib/util.ts b/src/lib/util.ts index b36eb701e..83bfa7e55 100644 --- a/src/lib/util.ts +++ b/src/lib/util.ts @@ -1,3 +1,6 @@ +import { readdirSync, unlinkSync } from "fs" +import { join } from "path" + /** Stops the main thread for given time @param number of seconds @@ -43,3 +46,13 @@ export function shouldExcludeStr(str: string | undefined) { return typeof str !== 'string' || str.length == 0 || potentialInvalidFlags.filter(flag => str.toLocaleLowerCase().includes(flag)).length > 0 } + +/** + * removes all files from the given folder path + * @param string path of folder + */ +export function clearFolder(folderPath: string) { + readdirSync(folderPath).forEach(file=> unlinkSync(join (folderPath, file))) +} + + From 8dfc42cba1e000a393626cc2e50a24f4187b62d9 Mon Sep 17 00:00:00 2001 From: zainuldeen <104352655+zainuldeen@users.noreply.github.com> Date: Sun, 11 Feb 2024 18:59:00 +0000 Subject: [PATCH 2/2] added: relative path --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 70ffcef9e..774bc0dab 100644 --- a/src/index.ts +++ b/src/index.ts @@ -66,7 +66,7 @@ if ((option as CLI_OPTIONS) != CLI_OPTIONS.crawler) process.exit(0) // removes all screen shots -clearFolder("/dist") +clearFolder("./dist") /// INTRO