Skip to content

Commit

Permalink
Merge pull request #4 from zainuldeen/master
Browse files Browse the repository at this point in the history
Add remove all SS before crawling
  • Loading branch information
Zain-ul-din authored Feb 11, 2024
2 parents bfea1d9 + 8dfc42c commit 1a147e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 🤖');
Expand All @@ -78,7 +81,6 @@ const intro_cli = async () => {
await intro_cli();

var metaData = undefined;

var hasCache = existsSync(CACHE_FILE_NAME);

if (hasCache) {
Expand Down
13 changes: 13 additions & 0 deletions src/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { readdirSync, unlinkSync } from "fs"
import { join } from "path"

/**
Stops the main thread for given time
@param number of seconds
Expand Down Expand Up @@ -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)))
}


0 comments on commit 1a147e4

Please sign in to comment.