Skip to content

Commit

Permalink
Add class types of questions, and the best points for the best answers.
Browse files Browse the repository at this point in the history
  • Loading branch information
hansputera committed Jun 27, 2021
1 parent 72d8f18 commit 5f11c44
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/src/config.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export declare const graphql_query = "query SearchQuery($query: String!, $first: Int!, $after: ID) {\n questionSearch(query: $query, first: $first, after: $after) {\n count\n edges {\n node {\n databaseId\n content\n points\n created\n lastActivity\n attachments {\n url\n }\n author {\n databaseId\n nick\n points\n gender\n description\n isDeleted\n avatar {\n url\n }\n category\n clientType\n rank {\n databaseId\n name\n }\n receivedThanks\n bestAnswersCount\n helpedUsersCount\n }\n isAuthorsFirstQuestion\n canBeAnswered\n pointsForAnswer\n pointsForBestAnswer\n answers {\n nodes {\n databaseId\n content\n points\n isBest\n created\n rating\n ratesCount\n thanksCount\n attachments {\n url\n }\n author {\n databaseId\n nick\n points\n gender\n description\n isDeleted\n avatar {\n url\n }\n category\n clientType\n rank {\n databaseId\n name\n }\n receivedThanks\n bestAnswersCount\n helpedUsersCount\n }\n }\n }\n }\n }\n }\n }";
export declare const graphql_query = "query SearchQuery($query: String!, $first: Int!, $after: ID) {\n questionSearch(query: $query, first: $first, after: $after) {\n count\n edges {\n node {\n databaseId\n content\n points\n created\n lastActivity\n subject {\n name\n slug\n }\n grade {\n name\n slug\n }\n attachments {\n url\n }\n author {\n databaseId\n nick\n points\n gender\n description\n isDeleted\n avatar {\n url\n }\n category\n clientType\n rank {\n databaseId\n name\n }\n receivedThanks\n bestAnswersCount\n helpedUsersCount\n }\n isAuthorsFirstQuestion\n canBeAnswered\n pointsForAnswer\n pointsForBestAnswer\n answers {\n nodes {\n databaseId\n content\n points\n isBest\n created\n rating\n ratesCount\n thanksCount\n attachments {\n url\n }\n author {\n databaseId\n nick\n points\n gender\n description\n isDeleted\n avatar {\n url\n }\n category\n clientType\n rank {\n databaseId\n name\n }\n receivedThanks\n bestAnswersCount\n helpedUsersCount\n }\n }\n }\n }\n }\n }\n }";
export declare const baseURLs: {
id: string;
us: string;
Expand Down
2 changes: 1 addition & 1 deletion dist/src/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions dist/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Brainly {
attachments: obj.node.attachments.map(attach => attach.url),
author: obj.node.author ? {
id: obj.node.author.databaseId,
avatar_url: obj.node.author.avatar ? obj.node.author.avatar.thumbnailUrl : undefined,
avatar_url: obj.node.author.avatar ? obj.node.author.avatar.url : undefined,
deleted: obj.node.author.isDeleted,
url: `${this.getBaseURL(language)}/app/profile/${obj.node.author.databaseId}`,
rank: obj.node.author.rank.name,
Expand All @@ -61,9 +61,12 @@ class Brainly {
} : undefined,
points: {
points: obj.node.points,
forBest: obj.node.pointsForBest
forBest: obj.node.pointsForBestAnswer
},
grade: obj.node.grade.name,
education: obj.node.subject.name,
created: obj.node.created,
can_be_answered: obj.node.canBeAnswered,
url: `${this.getBaseURL(language)}/${util_1.default.resolveWorkName(language.toLowerCase())}/${obj.node.databaseId}`
};
const answers = obj.node.answers.nodes.map(answerObj => ({
Expand All @@ -77,7 +80,7 @@ class Brainly {
id: answerObj.author.databaseId,
username: answerObj.author.nick,
gender: answerObj.author.gender,
avatar_url: answerObj.author.avatar ? answerObj.author.avatar.thumbnailUrl : undefined,
avatar_url: answerObj.author.avatar ? answerObj.author.avatar.url : undefined,
deleted: answerObj.author.isDeleted,
url: `${this.getBaseURL(language.toLowerCase())}/app/profile/${answerObj.author.databaseId}`,
description: answerObj.author.description,
Expand Down
2 changes: 1 addition & 1 deletion dist/src/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const index_1 = __importDefault(require("../../index"));
it("should return information about question and answer", (done) => {
const brain = new index_1.default("id");
brain.search("ru", "Pythagoras").then((results) => {
console.log(results[0].answers);
console.log(results[0].question);
expect(results).toBeDefined();
done();
}).catch(done);
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "brainly-scraper-v2",
"version": "2.0.1",
"version": "2.0.2",
"description": "A library that makes it easy to retrieve data from brainly sites.",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -28,5 +28,8 @@
"repository": {
"url": "https://github.com/hansputera/brainly-scraper-languages"
},
"readme": "https://github.com/hansputera/brainly-scraper-languages/blob/master/README.md"
"readme": "https://github.com/hansputera/brainly-scraper-languages/blob/master/README.md",
"maintainers": [
"hansputera"
]
}
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const graphql_query = "query SearchQuery($query: String!, $first: Int!, $after: ID) {\n questionSearch(query: $query, first: $first, after: $after) {\n count\n edges {\n node {\n databaseId\n content\n points\n created\n lastActivity\n attachments {\n url\n }\n author {\n databaseId\n nick\n points\n gender\n description\n isDeleted\n avatar {\n url\n }\n category\n clientType\n rank {\n databaseId\n name\n }\n receivedThanks\n bestAnswersCount\n helpedUsersCount\n }\n isAuthorsFirstQuestion\n canBeAnswered\n pointsForAnswer\n pointsForBestAnswer\n answers {\n nodes {\n databaseId\n content\n points\n isBest\n created\n rating\n ratesCount\n thanksCount\n attachments {\n url\n }\n author {\n databaseId\n nick\n points\n gender\n description\n isDeleted\n avatar {\n url\n }\n category\n clientType\n rank {\n databaseId\n name\n }\n receivedThanks\n bestAnswersCount\n helpedUsersCount\n }\n }\n }\n }\n }\n }\n }";
export const graphql_query = "query SearchQuery($query: String!, $first: Int!, $after: ID) {\n questionSearch(query: $query, first: $first, after: $after) {\n count\n edges {\n node {\n databaseId\n content\n points\n created\n lastActivity\n subject {\n name\n slug\n }\n grade {\n name\n slug\n }\n attachments {\n url\n }\n author {\n databaseId\n nick\n points\n gender\n description\n isDeleted\n avatar {\n url\n }\n category\n clientType\n rank {\n databaseId\n name\n }\n receivedThanks\n bestAnswersCount\n helpedUsersCount\n }\n isAuthorsFirstQuestion\n canBeAnswered\n pointsForAnswer\n pointsForBestAnswer\n answers {\n nodes {\n databaseId\n content\n points\n isBest\n created\n rating\n ratesCount\n thanksCount\n attachments {\n url\n }\n author {\n databaseId\n nick\n points\n gender\n description\n isDeleted\n avatar {\n url\n }\n category\n clientType\n rank {\n databaseId\n name\n }\n receivedThanks\n bestAnswersCount\n helpedUsersCount\n }\n }\n }\n }\n }\n }\n }";
export const baseURLs = {
id: "https://brainly.co.id",
us: "https://brainly.com",
Expand Down

0 comments on commit 5f11c44

Please sign in to comment.