instpector icon indicating copy to clipboard operation
instpector copied to clipboard

Issue with Following

Open zykrah opened this issue 5 years ago • 4 comments
trafficstars

from instpector import Instpector, endpoints

class InstaBot():
    def __init__(self, username, password):
        self.username = username
        self.password = password

        self.api = Instpector()
        self.profile_endpoint = endpoints.factory.create("profile", self.api)

    def login(self, two_factor_code=None):
        api = self.api
        api.login(self.username, self.password, two_factor_code)
    
    def logout(self):
        api = self.api
        api.logout()

    def follow(self, user):
        prof_end = self.profile_endpoint
        if isinstance(user, str):
            profile = prof_end.of_user(user)
        else:
            profile = prof_end.of_user(user.username)
        return prof_end.follow(profile)
        print(f"Followed {profile.username}")

    def unfollow(self, user):
        prof_end = self.profile_endpoint
        if isinstance(user, str):
            profile = prof_end.of_user(user)
        else:
            profile = prof_end.of_user(user.username)
        return prof_end.unfollow(profile)
        print(f"Unfollowed {profile.username}")

Above is my code

bot = InstaBot("username", "password")
bot.login()
print(bot.follow("therock")) # Doesnt work, returns/prints False
bot.logout()

Above is what i want to work, but cant get to work

bot = InstaBot("username", "password")
bot.login()
profile = endpoints.factory.create("profile", bot.api)
prof = profile.of_user("therock")
print(profile.follow(prof)) # Does work, returns/prints True
bot.logout()

Above is a way around the issue i made, but it is really inconvenient...

Please help!

zykrah avatar Jun 21 '20 11:06 zykrah

there is an error in my code with unreachable code. The print() in follow() and unfollow(). But it has no relevancy to the issue, just thought i'd point out that i already fixed that issue.

zykrah avatar Jun 21 '20 11:06 zykrah

I can successfully grab a profile using the code using

prof = bot.profile_endpoint.of_user("therock")

however, when i try to follow the profile using

bot.profile_endpoint.follow(prof)

It doesn't work, and returns False (when you print the line above)

zykrah avatar Jun 21 '20 11:06 zykrah

One more thing. I have tested both Followers and Following Endpoints, and have no issues with either so far.

zykrah avatar Jun 21 '20 11:06 zykrah

I seemed to have solve the issue (sorta).

    def profile_endpoint(self):
        return endpoints.factory.create("profile", self.api)

By using the above code, replacing:

self.profile_endpoint = self.endpoints.factory.create("profile", self.api)

and by referring to the endpoint as

bot.profile_endpoint()

Though i dont see why i couldnt use my original code... please correct me if i am wrong!

zykrah avatar Jun 21 '20 12:06 zykrah