Last active
May 3, 2016 11:09
-
-
Save kanazux/b0de7b82e2f9d6a0d2c1 to your computer and use it in GitHub Desktop.
Get instagram info - followers, followed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python2.7 | |
# -*- coding: utf-8 -*- | |
# | |
# Autor: Silvio Giunge Silva a.k.a Kanazuchi | |
# <[email protected]> | |
# | |
# URL para gerar o token http://www.pinceladasdaweb.com.br/instagram/access-token/ | |
# Crie um arquivo com o token e user id separados por ; (ponto e virgula) | |
# EX: echo '198754745546.5bdsa1e6.70b4234e28749efs80521a4c21314a2sd9b;suasenha' >> instadata | |
# | |
import os | |
import sys | |
import datetime | |
from urllib2 import urlopen | |
from json import loads as ld | |
from instagram.client import InstagramAPI | |
files = ['/home/kanazuchi/instagram/i_follow', | |
'/home/kanazuchi/instagram/i_follow_not_follow_me', | |
'/home/kanazuchi/instagram/followed_by', | |
'/home/kanazuchi/instagram/i_not_follow_but_follow_me'] | |
if os.path.exists('/home/kanazuchi/instagram/followed_by'): | |
old_followed_by = filter(None, open('/home/kanazuchi/instagram/followed_by', 'r').read().split('\n')[1:]) | |
user_token, user_secret = open('/home/kanazuchi/instagram/instadata', 'r').read().split('\n')[0].split(';') | |
api = InstagramAPI(access_token=user_token, client_secret=user_secret) | |
next_url = api.user_followed_by()[-1] | |
gufb_list = [] | |
error = '' | |
for x in files: | |
if os.path.exists(x): | |
os.unlink(x) | |
for x in api.user_followed_by()[0]: | |
gufb_list.append(x.username) | |
def get_user_followed_by(n_url): | |
global next_url | |
global error | |
try: | |
j_data = ld(urlopen(n_url).read()) | |
[ gufb_list.append(x['username']) for x in j_data['data'] ] | |
next_url = j_data['pagination']['next_url'] | |
except Exception, error: | |
pass | |
while error == '': | |
get_user_followed_by(next_url) | |
print >> open('/home/kanazuchi/instagram/followed_by', 'a'), "\t".join([str(len(set(gufb_list))), 'FOLLOWED BY']) | |
for x in sorted(gufb_list): | |
print >> open('/home/kanazuchi/instagram/followed_by', 'a'), x | |
if old_followed_by: | |
unfollow_me = [ x for x in old_followed_by if x not in gufb_list ] | |
if len(unfollow_me) > 0: | |
print >> open('/home/kanazuchi/instagram/unfollow_me', 'a'), datetime.datetime.now().strftime('%h %d %H:%M:%S') | |
for x in unfollow_me: | |
print >> open('/home/kanazuchi/instagram/unfollow_me', 'a'), x | |
new_follows = [ x for x in gufb_list if x not in old_followed_by ] | |
if len(new_follows) > 0: | |
print >> open('/home/kanazuchi/instagram/new_follows', 'a'), "{}".format(datetime.datetime.now().strftime('%h %d %H:%M:%S')) | |
for x in new_follows: | |
print >> open('/home/kanazuchi/instagram/new_follows', 'a'), x | |
next_url = api.user_follows()[-1] | |
gufs_list = [] | |
for x in api.user_follows()[0]: | |
gufs_list.append(x.username) | |
error = '' | |
def get_user_follows(n_url): | |
global next_url | |
global error | |
try: | |
j_data = ld(urlopen(n_url).read()) | |
[ gufs_list.append(x['username']) for x in j_data['data'] ] | |
next_url = j_data['pagination']['next_url'] | |
except Exception, error: | |
pass | |
while error == '': | |
get_user_follows(next_url) | |
print >> open('/home/kanazuchi/instagram/i_follow', 'a'), "\t".join([str(len(set(gufs_list))), 'I FOLLOW']) | |
for x in sorted(gufs_list): | |
print >> open('/home/kanazuchi/instagram/i_follow', 'a'), x | |
gunfy_list = [ x for x in gufs_list if x not in gufb_list ] | |
print >> open('/home/kanazuchi/instagram/i_follow_not_follow_me', 'a'), "\t".join([str(len(set(gunfy_list))), "I FOLLOW BUT NOT FOLLOW ME"]) | |
for x in sorted(gunfy_list): | |
print >> open('/home/kanazuchi/instagram/i_follow_not_follow_me', 'a'), x | |
guinf_list = [ x for x in gufb_list if x not in gufs_list ] | |
print >> open('/home/kanazuchi/instagram/i_not_follow_but_follow_me', 'a'), "\t".join([str(len(set(guinf_list))), "FOLLOW ME BU I NOT FOLLOW"]) | |
for x in sorted(guinf_list): | |
print >> open('/home/kanazuchi/instagram/i_not_follow_but_follow_me', 'a'), x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment