New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

public-instagram

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

public-instagram - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

lib/utils/parser/comments.js

0

index.js
'use strict'
exports = module.exports = require('./lib');

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -32,4 +32,77 @@ 'use strict';

}
},
/**
* Returns post's comments from shortcode
* @module Media
* @param {String} _shortcode
* @param {Number} _limit
* @return {Array} comments - Array of the post's comments
*/
comments: async (_shortcode, _limit) => {
var _comments = [];
try {
var response = await Axios.get(defaults.URL_INSTAGRAM_MEDIA_SHORTCODE + _shortcode, {
params: {
__a: 1
}
});
// If all comments are in the media page or it's paginated
if (!response.data.graphql.shortcode_media.edge_media_to_comment.page_info.has_next_page) {
_comments = await utils.parser.comments(response.data.graphql.shortcode_media.edge_media_to_comment.edges);
} else {
var _query_id = await utils.query.comments(_shortcode);
// First request
var response = await Axios.get(defaults.URL_INSTAGRAM_GRAPHQL_QUERY, {
params: {
query_id: _query_id,
variables: {
shortcode: _shortcode,
first: defaults.INSTAGRAM_DEFAULT_FIRST < _limit ? defaults.INSTAGRAM_DEFAULT_FIRST : _limit
}
}
});
_comments = await utils.parser.comments(response.data.data.shortcode_media.edge_media_to_comment.edges);
var token = null;
while (_comments.length < _limit && response.data.data.shortcode_media.edge_media_to_comment.page_info.has_next_page) {
token = response.data.data.shortcode_media.edge_media_to_comment.page_info.end_cursor;
response = await Axios.get(defaults.URL_INSTAGRAM_GRAPHQL_QUERY, {
params: {
query_id: _query_id,
variables: {
shortcode: _shortcode,
first: defaults.INSTAGRAM_DEFAULT_FIRST,
after: token
}
}
});
_comments = _comments.concat(await utils.parser.comments(response.data.data.shortcode_media.edge_media_to_comment.edges));
}
}
if (_comments.length > _limit) {
_comments.splice(_limit, _comments.length);
}
return _comments;
} catch (error) {
return error;
}
}
}

@@ -49,2 +49,44 @@ var

describe('Comments(_shortcode, _limit)', () => {
it('Testing type of return object', async () => {
comments = await Instagram.media.comments('BP-rXUGBPJa', 1000)
Expect(comments).to.be.an('array');
});
it('Testing schema of return object', async () => {
comments = await Instagram.media.comments('BP-rXUGBPJa', 1000)
Expect(comments[0]).to.be.jsonSchema({
type: 'object',
required: ['id', 'text', 'timestamp', 'owner'],
properties: {
id: {
type: 'string'
},
text: {
type: 'string'
},
timestamp: {
type: 'number'
},
owner: {
type: 'object',
required: ['id', 'username', 'image'],
properties: {
id: {
type: 'string'
},
username: {
type: 'string'
},
image: {
type: 'string'
}
}
}
}
});
});
});
});

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ var

@@ -0,0 +0,0 @@ 'use strict';

@@ -15,3 +15,3 @@ var

type: 'object',
required: ['id', 'username', 'name', 'bio', 'followers', 'follows', 'image', 'posts'],
required: ['id', 'username', 'name', 'bio', 'private', 'verified', 'followers', 'follows', 'image', 'posts'],
properties: {

@@ -30,2 +30,8 @@ id: {

},
private: {
type: 'boolean'
},
verified: {
type: 'boolean'
},
followers: {

@@ -32,0 +38,0 @@ type: 'object',

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -37,4 +37,12 @@ 'use strict';

*/
timeline: require('./timeline')
timeline: require('./timeline'),
/**
* Returns the comments of a post
* @module Utils.parser
* @param {String} _response
* @return {Array} Comments - Parsed comments that belong to that post
*/
comments: require('./comments')
};

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -0,0 +0,0 @@ 'use strict';

@@ -13,2 +13,4 @@ 'use strict';

bio: _user.biography,
private: _user.is_private,
verified: _user.is_verified,
followers: {

@@ -15,0 +17,0 @@ count: _user.followed_by.count

@@ -79,4 +79,41 @@ 'use strict';

}
},
/**
* Returns the query_id for the comments in a media page
* @module Utils.query
* @param {String} _shortcode
* @return {Number} Query ID - ID for the query call for searching comments of a given post
*/
comments: async (_shortcode) => {
try {
let query_id;
const browser = await Puppeteer.launch();
const page = await browser.newPage();
await page.setRequestInterceptionEnabled(true);
page.on('request', (request) => {
if (/\.(png|jpg|jpeg|gif|webp)$/i.test(request.url)) {
request.abort();
} else if (request.url.startsWith(defaults.URL_INSTAGRAM_GRAPHQL_QUERY)) {
query_id = request.url.split('=')[1].split('&')[0];
} else {
request.continue();
}
});
await page.goto(defaults.URL_INSTAGRAM_MEDIA_SHORTCODE + _shortcode);
// Click on 'more images'
await page.click('._m3m1c._1s3cd');
browser.close();
return query_id;
} catch (error) {
return error;
}
}
}
{
"name": "public-instagram",
"version": "0.1.1",
"version": "0.2.0",
"description": "Tool to fetch Instagram's public content.",

@@ -9,2 +9,8 @@ "main": "index.js",

},
"keywords": [
"instagram",
"scraper",
"public",
"api"
],
"repository": {

@@ -11,0 +17,0 @@ "type": "git",

@@ -0,0 +0,0 @@ # public-instagram

.npmignore

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc