Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dutch language added #3

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# newspk
## Description
A basic nodejs based news website (dawn) scraper. You can use this API to fetch latest news in English or Urdu language. It uses node-fetch and jsdom dependencies and hence is a very light-weighted package.
A basic nodejs based news website (dawn) scraper. You can use this API to fetch latest news in English, Dutch or Urdu language. It uses node-fetch and jsdom dependencies and hence is a very light-weighted package.

## REST API
<a href="https://newspk.herokuapp.com">API</a>
Expand All @@ -27,6 +27,8 @@ const newspk = require("newspk");
let limit = 5; // max-allowed: 15, may return unexpected errors on limit violation
let lang = "english"; // for english
// let lang = "urdu"; // for urdu
// let lang = "dutch"; // for dutch


let news = await newspk.news(limit, lang);
console.log(news) // An array of object with properties "title", "thumbnail", "body", "created_at", "unique id"
Expand Down
3 changes: 2 additions & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const newspk = require("newspk");
let limit = 5; // max-allowed: 15
let lang = "english"; // for english
// let lang = "urdu"; // for urdu
// let lang = "dutch"; // for dutch

let news = await newspk.news(limit, lang);
console.log(news) // An array of object with properties "title", "thumbnail", "body", "created_at", "unique id"

})();
})();
8 changes: 6 additions & 2 deletions express/view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<br>
<h1 class="text-primary display-6">Newspk - API</h1>
<p>
A basic nodejs based news website (dawn) scraper. You can use this API to fetch latest news in English or Urdu language. It uses node-fetch and jsdom dependencies and hence is a very light-weighted package.
A basic nodejs based news website (dawn) scraper. You can use this API to fetch latest news in English, Dutch or Urdu language. It uses node-fetch and jsdom dependencies and hence is a very light-weighted package.
</p>
<hr>
<h5 class="text-primary">Usage</h5>
Expand All @@ -35,6 +35,10 @@ <h6>Examples</h6>
<span class="text-success">GET |</span><code>
https://newspk.herokuapp.com/api?lang=english&limit=1
</code>
<br>
<span class="text-success">GET |</span><code>
https://newspk.herokuapp.com/api?lang=english&limit=1
</code>


<hr>
Expand All @@ -52,4 +56,4 @@ <h5 class="text-primary ">NPM Package</h5>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-/bQdsTh/da6pkI1MST/rWKFNjaCP5gBSY4sEBT38Q/9RBh9AH40zEOg7Hlq2THRZ" crossorigin="anonymous"></script>
</body>
</html>
</html>
34 changes: 33 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,41 @@ let exe = async function (no = 5, lang = "urdu") {

};

let exe = async function (no = 5, lang = "dutch") {
if (lang.toLowerCase() == "dutch") {
var response = await fetch('https://www.nu.nl/net-binnen');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello ItsNyoty, that was not much simple. Please go through your code.

} else {
var response = await fetch('https://www.dawn.com/latest-news');

}
const body = await response.text();
const dom = new JSDOM(body);
let a = dom.window.document.getElementsByClassName('story__link');
let b = dom.window.document.getElementsByClassName('media__item');
let created_at = dom.window.document.getElementsByClassName('timeago');
var content = [];
for (let i = 0; i < no; i++) {
let unique_id = b[i].firstChild.href.split('/')[4];
await getnews(b[i].firstChild.href).then((data) => {
content.push({
"title": a[i].innerHTML,
"thumbnail": b[i].firstChild.firstChild.firstChild.src,
"body": data,
"unique_id": unique_id,
"created_at": created_at[i].title
});
})

}

return content;

};


module.exports.news = function (no, lang) {
return new Promise((resolve, reject) => {
let a = exe(no, lang);
resolve(a);
})
}
}