Skip to content

Commit

Permalink
Add task to get ayahs from external api
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed0saber committed May 8, 2024
1 parent 4abd883 commit 2205f69
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ npm run dev
npm run test
```

8. Get surahs data when needed:

```
npm run get:surahs
```

## Usage

To subscribe to the daily email service and receive Quranic verses, simply submit your email address on subscription page.
Expand Down
2 changes: 2 additions & 0 deletions app/api/data/surah-ayahs.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"test": "jest"
"test": "jest",
"get:surahs": "node tasks/get-surah-ayahs.js"
},
"dependencies": {
"mongodb": "^6.3.0",
Expand Down
30 changes: 30 additions & 0 deletions tasks/get-surah-ayahs.js
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()

0 comments on commit 2205f69

Please sign in to comment.