Skip to content

Instantly share code, notes, and snippets.

@sharegrams
Created October 31, 2019 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharegrams/9dbf5f4dd8c2ceed7cb81a9c0c8f41b4 to your computer and use it in GitHub Desktop.
Save sharegrams/9dbf5f4dd8c2ceed7cb81a9c0c8f41b4 to your computer and use it in GitHub Desktop.
Scoring instagram users based on their following to follower ratio
cd "downloads/#dogfood"
# loop each json file
for i in *.json
do
json_details=$(cat $i)
get_owner_id=$(echo "$json_details" | grep '"id":' | tail -1 | cut -d '"' -f 4)
# add their user id to unique_id database so we dont do the same user
if grep -q "$get_owner_id" "../../unique_users_database"; then
echo "found $get_owner_id in unique_users_database, skipping"
else
echo "didnt find $get_owner_id in database, continuing"
echo "$get_owner_id" >> ../../unique_users_database
# get shortcode from json details
post_shortcode=$(echo "$json_details" | grep '"shortcode"' | cut -d '"' -f 4)
echo "$get_owner_id post shortcode is $post_shortcode"
echo "obtaining their username from instagram.com/p/$post_shortcode"
# download username from their post
get_username=$(curl -s "https://www.instagram.com/p/$post_shortcode/" -H 'User-Agent: Mozilla/5.0 (Android 9.0; Mobile; rv:68.0) Gecko/68.0 Firefox/68.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-CA,en-US;q=0.7,en;q=0.3' --compressed -H 'Upgrade-Insecure-Requests: 1' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' | sed 's/"username":/\n"username":/g' | sed 's/","/\n/g' | grep username | tail -1 | cut -d '"' -f 4)
echo "username obtained from post: @$get_username"
# get their profile data
profile_data=$(curl -s "https://www.instagram.com/$get_username/" -H 'User-Agent: Mozilla/5.0 (Android 9.0; Mobile; rv:68.0) Gecko/68.0 Firefox/68.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' -H 'Accept-Language: en-CA,en-US;q=0.7,en;q=0.3' --compressed -H 'Upgrade-Insecure-Requests: 1' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache')
# get their follow/following count
following=$(echo "$profile_data" | grep edge_follow | sed 's/edge_follow"/\edge_follow"/g' | sed 's/}/\n/g' | grep 'edge_follow"' | cut -d ':' -f 4)
followers=$(echo "$profile_data" | grep edge_followed_by | sed 's/edge_followed_by/\nedge_followed_by/g' | sed 's/}/\n/g' | grep "edge_followed_by" | cut -d ':' -f 3)
echo "following: $following / followers: $followers"
# do math
ratio=$(($following-$followers))
echo "ratio: $ratio"
# does ratio contain negative
if [[ "$ratio" == *"-"* ]]; then
echo "❌ User has more followers than they are following"
else
echo "🔔 User is following more people than they have followers"
# post the good users to an html databse
echo "$ratio+ | $following | $followers | <a href='https://instagram.com/$get_username' target='_blank'>@$get_username</a> | $get_owner_id<br>" >> ../../targets.html
fi
echo "-----------------------"
#sleep 3
# sort the html database based on ratio number
cat ../../targets.html | sort -nr > .tmp
mv .tmp ../../targets.html
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment