From 588c76e2016d1d72e5b50c460834ffa454c3c18f Mon Sep 17 00:00:00 2001 From: sujal-ops-cyber <67121014+sujal-ops-cyber@users.noreply.github.com> Date: Tue, 15 Jun 2021 15:18:31 +0530 Subject: [PATCH] :tada: Added FetchPerson function --- README.md | 30 ++++++++++++++++++++++++++++++ package.json | 4 ++-- src/mdl.js | 19 +++++++++++++++++++ test/test.js | 6 ++++++ 4 files changed, 57 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7622742..76f3aa0 100644 --- a/README.md +++ b/README.md @@ -147,6 +147,36 @@ mdl.FetchQuery("61371-vincenzo").then((data) => { +
+FetchPerson example + +```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" +} +``` + +
+ ## Contributing 🤝 - **Contributions, issues and feature requests are welcome!** diff --git a/package.json b/package.json index cf21f72..ded43b1 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" diff --git a/src/mdl.js b/src/mdl.js index 173b01c..17075c5 100644 --- a/src/mdl.js +++ b/src/mdl.js @@ -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); + } + }, }; \ No newline at end of file diff --git a/test/test.js b/test/test.js index 15e5c03..323449a 100644 --- a/test/test.js +++ b/test/test.js @@ -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); }); \ No newline at end of file