Skip to content

Instantly share code, notes, and snippets.

@Sasquire
Created February 14, 2020 17:03
Show Gist options
  • Save Sasquire/5a5e5606575b57c3e1d3479fb455b754 to your computer and use it in GitHub Desktop.
Save Sasquire/5a5e5606575b57c3e1d3479fb455b754 to your computer and use it in GitHub Desktop.
This is a quick program that can be used to identify users based on two or more posts from their favorites.
const request = require('request');
async function find_users(id){
const options = {
url: `https://e621.net/favorite/list_users.json?id=${id}`,
headers: {
'User-Agent': 'Identify users from favorites/v1.0'
}
};
return new Promise((resolve, reject) => {
request(options, (err, headers, response) => {
if(err || headers.statusCode != 200){
reject();
} else {
const r = JSON.parse(response)
.favorited_users
.split(',');
resolve(new Set(r));
}
});
});
}
function set_intersection(a, b){
return new Set([...a].filter(e => b.has(e)));
}
async function main(){
const ids = process.argv.slice(2).map(e => parseInt(e, 10));
if(ids.length == 0){
return console.log('No post_ids given');
}
let all_users = await find_users(ids[0]);
for(const post_id of ids.slice(1)){
const new_users = await find_users(post_id);
all_users = set_intersection(all_users, new_users);
}
console.log(all_users);
return all_users;
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment