Skip to content

Commit

Permalink
🎉 Added FetchPerson function
Browse files Browse the repository at this point in the history
  • Loading branch information
sujalgoel committed Jun 15, 2021
1 parent 183fd12 commit 588c76e
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,36 @@ mdl.FetchQuery("61371-vincenzo").then((data) => {

</details>

<details>
<summary>FetchPerson example</summary>

```js
const { mdl } = require("mdl-scraper");

mdl.FetchPerson("5647-bong-joon-ho").then((data) => {
console.log(data);
});
```

### Example Response

```json
{
"name":"Bong Joon Ho",
"about":"`Bong Joon Ho Name: Bong Joon Ho Native name: 봉준호 Nationality: South Korean Gender: Male Born: September 14, 1969 Age: 51 Bong Joon-ho is a South Korean film director and screenwriter. Bong in general is known as being a director who takes a great interest in film genres, while simultaneously trying to move beyond genre's usual boundaries. Also known for the pure craft and finished quality of his works, Korean film industry insiders have nicknamed him \"Bong Tae-il,\" which, pronounced in Korean, sounds similar to the word \"detail\". Though he displays a fascination for strong subject matter, at the same time, his films are filled with (often black) humor and sudden mood shifts, making for an emotional roller coaster ride. The fact that he is able to combine all these contrasting elements into such a smooth whole is Bong's particular strength as a filmmaker. In 2019, director, Bong Joon-ho won the Cannes Palm d'Or (Grand Prize) for his movie Parasite. This is the first Korean film to ever win the award.`",
"profile":"https://i.mydramalist.com/dWLK5_5c.jpg",
"first_name":"Joon Ho",
"family_name":"Bong",
"native_name":"봉준호",
"nationality":"South Korean",
"gender":"Male",
"born":"September 14, 1969",
"age":"51"
}
```

</details>

## Contributing 🤝

- **Contributions, issues and feature requests are welcome!**
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mdl-scraper",
"version": "1.0.2",
"version": "1.0.3",
"description": "A npm package for scraping data from mydramalist",
"main": "index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"k-drama",
"kdrama"
],
"homepage": "https://github.com/sujalgoel/mdl-scraper",
"homepage": "https://github.com/sujalgoel/mdl-scraper#readme",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/sujalgoel/mdl-scraper/issues"
Expand Down
19 changes: 19 additions & 0 deletions src/mdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,23 @@ module.exports = {
throw new Error(e);
}
},
async FetchPerson(query) {
try {
const $ = await fetchhtml(`${BASE_URL}/people/${query}`);
const profile = {};
const container = $('div[class="app-body"]');
profile.name = container.find('h1[class="film-title m-b-0"]').text().trim();
profile.about = container.find('div[class="col-sm-8 col-lg-12 col-md-12"]').text().trim().replace(/\n/g, '');
profile.profile = fetchPoster(container);
const details = {};
container.find('ul[class="list m-b-0"]').find('li').each((i, e) => {
const title = $(e).find('b').text().trim();
details[title.replace(':', '').replace(/\s/g, '_').toLowerCase()] = $(e).text().replace(title + ' ', '').trim();
});
const data = Object.assign({}, profile, details);
return data;
} catch (e) {
throw new Error(e);
}
},
};
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ mdl.FetchQuery('696359-people-living-alone')
.then((data) => {
console.log('FetchQuery Example:');
console.log(data);
});

mdl.FetchPerson('5647-bong-joon-ho')
.then((data) => {
console.log('FetchPerson Example:');
console.log(data);
});

0 comments on commit 588c76e

Please sign in to comment.