Exemplo n.º 1
0
class CleanFollows:
    def __init__(self, config_file):
        # Loading the configuration file, it has the access_token, user_id and others configs
        self.config = json.load(config_file)

        # Initializing the Instagram API with our access token
        self.api = InstagramAPI(access_token=self.config["access_token"],
                                client_secret=self.config['client_secret'])

    def run(self):
        while True:
            self.follows()

    def follows(self, next_page=None):
        print "next_page: ", next_page

        try:
            if next_page is None:
                follows, next_ = self.api.user_follows(
                    user_id=self.config['my_user_id'])
            else:
                follows, next_ = self.api.user_follows(
                    user_id=self.config['my_user_id'], with_next_url=next_page)

            for follow in follows:
                var = self.api.user_relationship(user_id=follow.id)
                print var.incoming_status, follow.id

                if var.incoming_status == 'none':
                    self.api.unfollow_user(user_id=follow.id)

                var = self.api.user_relationship(user_id=follow.id)
                print var.outgoing_status, follow.id

            return self.follows(next_)
        except Exception, e:
            print e
            time.sleep(1800)
            return self.follows(next_page)
Exemplo n.º 2
0
class CleanFollows:
    def __init__(self, config_file):
        # Loading the configuration file, it has the access_token, user_id and others configs
        self.config = json.load(config_file)

        # Initializing the Instagram API with our access token
        self.api = InstagramAPI(access_token=self.config["access_token"], client_secret=self.config['client_secret'])

    def run(self):
        while True:
            self.follows()

    def follows(self, next_page=None):
        print "next_page: ", next_page

        try:
            if next_page is None:
                follows, next_ = self.api.user_follows(user_id=self.config['my_user_id'])
            else:
                follows, next_ = self.api.user_follows(user_id=self.config['my_user_id'], with_next_url=next_page)

            for follow in follows:
                var = self.api.user_relationship(user_id=follow.id)
                print var.incoming_status, follow.id

                if var.incoming_status == 'none':
                    self.api.unfollow_user(user_id=follow.id)

                var = self.api.user_relationship(user_id=follow.id)
                print var.outgoing_status, follow.id

            return self.follows(next_)
        except Exception, e:
            print e
            time.sleep(1800)
            return self.follows(next_page)
Exemplo n.º 3
0
    key = str('user-media-%s-%s' % (uid,next_id))
    try:
        data= _user_recent_media(20,user_id=uid,max_id=next_id)
    except Exception,e:
        print e
        return redirect('/')
    next_max_id = ''
    data = data[0]
    if data['pagination'].has_key('next_max_id'):
        next_max_id = data['pagination']['next_max_id']
    callback = request.args.get('jsoncallback','json')  
    if next_id :
        data = _convert(data)
        return callback+"("+json.dumps(data)+')'
    g.subtitle = u'%s 的页面' % user['username']
    isfollowing = False
    isfollower =  False
    #判断是否关注对方
    rtn = None
    if g.user:
        api.access_token = g.user[0]
        try:
            rtn = api.user_relationship(user_id=uid)
            if rtn['data']['outgoing_status'] == 'follows':
                isfollowing = True
            if rtn['data']['incoming_status'] == 'followed_by':
                isfollower = True
        except:
            pass
    return render_template('profile.html',isfollowing=isfollowing,isfollower=isfollower, user=user,uid=id, next=next_max_id,photos=data['data'],isfirst=next_id)
Exemplo n.º 4
0
class Bot:
    def __init__(self, config_file, tags_file):
        # Loading the configuration file, it has the access_token, user_id and others configs
        self.config = json.load(config_file)

        # Loading the tags file, it will be keep up to date while the script is running
        self.tags = json.load(tags_file)

        # Log file to output to html the debugging info about the script
        self.filename = self.config["path"] + self.config[
            "prefix_name"] + time.strftime("%d%m%Y") + ".html"
        self.log_file = open(self.filename, "wb")

        # Initializing the Instagram API with our access token
        self.api = InstagramAPI(access_token=self.config["access_token"],
                                client_secret=self.config['client_secret'])

        # Likes per tag rate
        self.likes_per_tag = math.trunc(
            min(self.config["follows_per_hour"], self.config["likes_per_hour"])
            / len(self.tags["tags"]))

    def save_tags(self):
        j = json.dumps(self.tags, indent=4)
        f = open('tags.json', 'w')
        print >> f, j
        f.close()

    def insta_write(self, to_write):
        if self.filename != self.config["path"] + self.config[
                "prefix_name"] + time.strftime("%d%m%Y") + ".html":
            self.log_file.close()
            self.filename = self.config["path"] + self.config[
                "prefix_name"] + time.strftime("%d%m%Y") + ".html"
            self.log_file = open(self.filename, "wb")

        if isinstance(to_write, list):
            self.log_file.write(''.join(to_write) + "<br/>")
        else:
            self.log_file.write(str(to_write) + "<br/>")
            self.log_file.flush()

    def going_sleep(self, timer):
        sleep = randint(timer, 2 * timer)
        self.insta_write("SLEEP " + str(sleep))
        time.sleep(sleep)

    def like_and_follow(self, media, likes_for_this_tag):
        try:
            var = self.api.user_relationship(user_id=media.user.id)

            if self.config["my_user_id"] != media.user.id:
                self.insta_write("--------------")
                self.insta_write(var)

                if var.outgoing_status == 'none':
                    self.insta_write("LIKE RESULT:")
                    self.insta_write(self.api.like_media(media_id=media.id))

                    self.insta_write("FOLLOW RESULT:")
                    self.insta_write(
                        self.api.follow_user(user_id=media.user.id))

                    likes_for_this_tag -= 1

                    self.going_sleep(self.config["sleep_timer"])
                else:
                    self.going_sleep(self.config["sleep_timer"] / 2)

        except Exception, e:
            self.insta_write(str(e))
            self.insta_write("GOING SLEEP 30 min")
            time.sleep(1800)
            self.like_and_follow(media, likes_for_this_tag)

        return likes_for_this_tag
Exemplo n.º 5
0
	time.sleep(d*random.random()+1)
	calls=calls+1
    except Exception as er:
	err(er)
	print "user info error"
	print user.id
	fails=fails+1
    	continue

    follows=userinfo.counts['follows']*1.0
    followedby=userinfo.counts['followed_by']+1
    follow_ratio=follows/followedby

    if (follow_ratio > followstofollowedratio) :
	try:
		rel = api.user_relationship(user_id=user.id)
		calls=calls+1
		time.sleep(d*random.random()+1)
	except Exception as er:
		err(er)
		fails=fails+1
		print "getting relationships error"
		print user.id
    		continue

	if 	(rel.outgoing_status=='none') :

	        print user

		try :
			api.follow_user(user_id=user.id)
Exemplo n.º 6
0
class DayBot:
    def __init__(self, config_file, tags_file):
        # Loading the configuration file, it has the access_token, user_id and others configs
        self.config = json.load(config_file)

        # Loading the tags file, it will be keep up to date while the script is running
        self.tags = json.load(tags_file)

        # file name to save the logs
        self.filename = self.config["path"] + self.config["prefix_name"] + time.strftime("%d%m%Y") + ".html"
        # Log file to output to html the debugging info about the script
        self.log_file = open(self.filename, "wb")

        # Initializing the Instagram API with our access token
        self.api = InstagramAPI(access_token=self.config["access_token"], client_secret=self.config['client_secret'])

        # Likes per tag rate
        self.likes_per_tag = math.trunc(min(self.config["follows_per_hour"],
                                            self.config["likes_per_hour"]) / len(self.tags["tags"]))

    def log_write(self, to_write):
        if self.filename != self.config["path"] + self.config["prefix_name"] + time.strftime("%d%m%Y") + ".html":
            self.log_file.close()
            self.filename = self.config["path"] + self.config["prefix_name"] + time.strftime("%d%m%Y") + ".html"
            self.log_file = open(self.filename, "wb")

        if isinstance(to_write, list):
            self.log_file.write(''.join(to_write) + "<br/>")
        else:
            self.log_file.write(str(to_write) + "<br/>")
            self.log_file.flush()

    def going_sleep(self, timer):
        sleep = randint(timer, 2 * timer)
        self.log_write("SLEEP " + str(sleep))
        time.sleep(sleep)

    def like_and_follow(self, media, likes_for_this_tag):
        try:
            var = self.api.user_relationship(user_id=media.user.id)

            if self.config["my_user_id"] != media.user.id:
                self.log_write("--------------")
                self.log_write(var)

                if var.outgoing_status == 'none':
                    self.log_write("LIKE RESULT:")
                    self.log_write(self.api.like_media(media_id=media.id))

                    self.log_write("FOLLOW RESULT:")
                    self.log_write(self.api.follow_user(user_id=media.user.id))

                    likes_for_this_tag -= 1

                    self.going_sleep(self.config["sleep_timer"])
                else:
                    self.going_sleep(self.config["sleep_timer"] / 2)

        except Exception, e:
            self.log_write(str(e))
            self.log_write("GOING SLEEP 30 min")
            time.sleep(1800)
            return self.like_and_follow(media, likes_for_this_tag)

        return likes_for_this_tag
Exemplo n.º 7
0
def loop_printer(ine):
    for i in ine:
        if type(i) == list:
            loop_printer(i)
        elif type(i) == dict:
            print(i)
            loop_printer(i)
        else:
            print('OLOLOLO', i)


loop_printer(line['data'])
#line = ' '.join(line['data'])
#line = simplejson.loads(line)
#print(len(line['data']), type(line['data']), line['data'])

#print(api.user_follows(user_id2))
#print(api.user_followed_by(user_id2))
print(api.user(user_id))
#print(api.user_media_feed())
#print(api.user_liked_media())
print(api.user_search('jogryn'))  #works
print(api.user_relationship(user_id2))  #works

print(line['data'][0]['images'])

recent_media, next_ = api.user_recent_media()
photos = []
for media in recent_media:
    photos.append('<img src="%s"/>' % media.images['thumbnail'].url)
client_id = "da4a3124488840f582305f64b3557548"
client_secret = "e7dce52052b842fb909ac0c24b467afb"
access_token = "1147536024.bec82b4.fb48b565d9ad4fe09f64f63d64d4f664"
INDICO_API_KEY = '61cdd30af4bbdfe5a21b92689a872234'

api = InstagramAPI(access_token=access_token, client_secret=client_secret)
indicoio.config.api_key = INDICO_API_KEY

following, next = api.user_follows(user_id="self", count=10)
#print next
#temp, max_tag=next.split('max_tag_id=')
#max_tag = str(max_tag)

usernames = []
for f in following:
	isPrivate = api.user_relationship(user_id=f.id).target_user_is_private
	if isPrivate == False:
		usernames.append(f.id)
print len(usernames)

new_usernames = usernames[:]
for user in usernames:
	length = len(usernames)
	if length > 100000:
		break
	else:
		isPrivate = api.user_relationship(user_id=user).target_user_is_private
		if isPrivate == False:
			following, next = api.user_follows(user_id=user, count=100)
			for f in following:
				isPrivate2 = api.user_relationship(user_id=f.id).target_user_is_private
Exemplo n.º 9
0
fo = open(filename, "r+")
line = fo.read();
#print "Read String is : ", line
fo.close()

i=int(line)

if i>100 :         
	access_token = "211585314.e1b377f.d45639f8eb394f2fa0ee3a8176311562"
	api = InstagramAPI(access_token=access_token)

	for page,next in api.user_follows( user_id = 211585314, as_generator = True ):
		for follower in page:
			try:
				rel = api.user_relationship(user_id=follower.id)
				print follower
				if rel.incoming_status =='none' : 
	            			api.unfollow_user(user_id=follower.id)
	            			print 'removed'
		                	
			except:
				print 'api error'
				api.unfollow_user(user_id=follower.id)
			time.sleep(4*random.random())	
	os.remove(filename)
#	i=0
#	fo = open(filename, "wb")
#	fo.write(str(i));
#	fo.close()