-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add task to get ayahs from external api
- Loading branch information
1 parent
4abd883
commit 2205f69
Showing
4 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const getSurahAyahs = async () => { | ||
const fs = require('fs') | ||
|
||
console.log("Task started") | ||
const contentObj = {} | ||
|
||
for (let i = 1; i <= 114; i++) { | ||
const res = await fetch(`https://api.alquran.cloud/v1/surah/${i}`) | ||
const data = await res.json() | ||
|
||
console.log(`Loading: ${i}/114`) | ||
contentObj[i] = { | ||
name: data.data.name, | ||
ayahs: data.data.ayahs, | ||
} | ||
} | ||
|
||
const content = `const surahAyahs = ${JSON.stringify(contentObj)}; | ||
export default surahAyahs;` | ||
|
||
fs.writeFile('./app/api/data/surah-ayahs.js', content, err => { | ||
if (err) { | ||
console.error(err) | ||
} else { | ||
console.log("Success") | ||
} | ||
}) | ||
} | ||
|
||
getSurahAyahs() |