mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-17 08:17:35 +02:00
Async
This commit is contained in:
@@ -64,8 +64,8 @@ module.exports = class JeopardyScrape {
|
|||||||
return clues;
|
return clues;
|
||||||
}
|
}
|
||||||
|
|
||||||
importData() {
|
async importData() {
|
||||||
const read = fs.readFileSync(path.join(__dirname, '..', 'jeopardy.json'), { encoding: 'utf8' });
|
const read = await fs.promises.readFile(path.join(__dirname, '..', 'jeopardy.json'), { encoding: 'utf8' });
|
||||||
const file = JSON.parse(read);
|
const file = JSON.parse(read);
|
||||||
if (typeof file !== 'object' || Array.isArray(file)) return null;
|
if (typeof file !== 'object' || Array.isArray(file)) return null;
|
||||||
if (!file.clues || !file.gameIDs || !file.seasons) return null;
|
if (!file.clues || !file.gameIDs || !file.seasons) return null;
|
||||||
@@ -89,7 +89,6 @@ module.exports = class JeopardyScrape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exportData() {
|
exportData() {
|
||||||
if (!this.clues.length) this.importData();
|
|
||||||
const buf = Buffer.from(JSON.stringify({
|
const buf = Buffer.from(JSON.stringify({
|
||||||
clues: this.clues,
|
clues: this.clues,
|
||||||
gameIDs: this.gameIDs,
|
gameIDs: this.gameIDs,
|
||||||
@@ -102,7 +101,7 @@ module.exports = class JeopardyScrape {
|
|||||||
async checkForUpdates() {
|
async checkForUpdates() {
|
||||||
if (!this.imported) {
|
if (!this.imported) {
|
||||||
const fileExists = await checkFileExists(path.join(__dirname, '..', 'jeopardy.json'));
|
const fileExists = await checkFileExists(path.join(__dirname, '..', 'jeopardy.json'));
|
||||||
if (fileExists) this.importData();
|
if (fileExists) await this.importData();
|
||||||
}
|
}
|
||||||
const cluesBefore = this.clues.length;
|
const cluesBefore = this.clues.length;
|
||||||
const latestSeason = this.seasons[this.seasons.length - 1];
|
const latestSeason = this.seasons[this.seasons.length - 1];
|
||||||
|
|||||||
Reference in New Issue
Block a user