Skip to content

Instantly share code, notes, and snippets.

@r17x
Created October 30, 2018 07:43
Show Gist options
  • Save r17x/bfb5bc988860ffd9eef74e14a806b1cb to your computer and use it in GitHub Desktop.
Save r17x/bfb5bc988860ffd9eef74e14a806b1cb to your computer and use it in GitHub Desktop.
from InstagramAPI import InstagramAPI as IG
from pprint import PrettyPrinter
from getpass import getpass
from random import randint
import time

pp =  PrettyPrinter(indent=2)

api = IG(
        raw_input('username: '),
        getpass('password: ')
)

api.login()

TARGET = {
    'username': '',
    'media': '',
    'media_like': [],
}

TARGET['username'] = raw_input('username target: ')

api.searchUsername(TARGET['username'])

TARGET['user_data'] = api.LastJson['user']

# pp.pprint(TARGET['user_data'])
print('Okay! i want check {0} post.\n'.format(
    TARGET['username']
))

api.getUserFeed(str(TARGET['user_data']['pk']))

media = TARGET['media'] = api.LastJson['items']

print('Total Post @{0}: {1} post.'.format(
    TARGET['username'],
    len(TARGET['media'])
))

print('Like Alllllllll guys')

for item in media:
    pp.pprint(item['caption'] or 'no caption')

    if item['has_liked']:
        print('Udah ke like ini')
    else:
        hasLiked = api.like(item['id'])
        if hasLiked:
            print('Berhasil di like')
            TARGET['media_like'].append(item['id'])
            time.sleep(randint(100,150))
@amansingh9097
Copy link

@ri7nz the code

media = TARGET['media'] = api.LastJson['items']

print('Total Post @{0}: {1} post.'.format(
    TARGET['username'],
    len(TARGET['media'])
))

only grabs 18 posts and not all the posts ! Is there any other way to get all the posts of a user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment