Beispiel #1
0
def reels_media_story(self, user_ids, media_id, **kwargs):
    """
    Get multiple users' reel/story media

    :param user_ids: list of user IDs
    :param kwargs:
    :return:
    """
    user_ids = [str(x) for x in user_ids]
    params = {'user_ids': user_ids, 'media_id': media_id}
    params.update(kwargs)

    res = self._call_api('feed/reels_media/', params=params)
    if self.auto_patch:
        for reel_media in res.get('reels_media', []):
            [
                ClientCompatPatch.media(
                    m, drop_incompat_keys=self.drop_incompat_keys)
                for m in reel_media.get('items', [])
            ]
        for _, reel in list(res.get('reels', {}).items()):
            [
                ClientCompatPatch.media(
                    m, drop_incompat_keys=self.drop_incompat_keys)
                for m in reel.get('items', [])
            ]
    return res
Beispiel #2
0
    def test_compat_media(self):
        self.api.auto_patch = False
        results = self.api.media_info(self.test_media_id)
        self.api.auto_patch = True
        media = results.get('items', [])[0]
        media_patched = copy.deepcopy(media)
        ClientCompatPatch.media(media_patched)

        self.assertIsNone(media.get('link'))
        self.assertIsNotNone(media_patched.get('link'))
        self.assertIsNone(media.get('created_time'))
        self.assertIsNotNone(media_patched.get('created_time'))
        self.assertIsNone(media.get('images'))
        self.assertIsNotNone(media_patched.get('images'))
        self.assertIsNone(media.get('type'))
        self.assertIsNotNone(media_patched.get('type'))
        self.assertIsNone(media.get('filter'))
        self.assertIsNotNone(media_patched.get('filter'))
        self.assertIsNone(media.get('user', {}).get('id'))
        self.assertIsNotNone(media_patched.get('user', {}).get('id'))
        self.assertIsNone(media.get('user', {}).get('profile_picture'))
        self.assertIsNotNone(
            media_patched.get('user', {}).get('profile_picture'))
        if media['caption']:
            self.assertIsNone(media.get('caption', {}).get('id'))
            self.assertIsNotNone(media_patched['caption']['id'])
            self.assertIsNone(media.get('caption', {}).get('from'))
            self.assertIsNotNone(media_patched['caption']['from'])
Beispiel #3
0
def ig_login(currentUser):

    device_id = None
    try:
        settings_file = os.path.join(
            current_app.root_path, 'cookies', currentUser['username'])
        if not os.path.isfile(settings_file):
            # settings file does not exist

            # login new
            api = Client(
                currentUser['ig-username'], currentUser['ig-password'],
                on_login=lambda x: onlogin_callback(x, settings_file))
        else:
            with open(settings_file) as file_data:
                cached_settings = json.load(file_data, object_hook=from_json)

            device_id = cached_settings.get('device_id')
            # reuse auth settings
            api = Client(
                currentUser['ig-username'], currentUser['ig-password'],
                settings=cached_settings)

    except (ClientCookieExpiredError, ClientLoginRequiredError) as e:
        print(
            'ClientCookieExpiredError/ClientLoginRequiredError: {0!s}'.format(e))

        # Login expired
        # Do relogin but use default ua, keys and such
        api = Client(
            currentUser['ig-username'], currentUser['ig-password'],
            device_id=device_id,
            on_login=lambda x: onlogin_callback(x, settings_file))

    except ClientLoginError as e:
        print('ClientLoginError {0!s}'.format(e))
        exit(9)
    except ClientError as e:
        print('ClientError {0!s} (Code: {1:d}, Response: {2!s})'.format(
            e.msg, e.code, e.error_response))
        exit(9)
    except Exception as e:
        print('Unexpected Exception: {0!s}'.format(e))
        exit(99)

    # Call the api
    lst = []
    posts = api.feed_timeline()
    items = [item for item in posts.get('feed_items', [])
             if item.get('media_or_ad')]
    tz = pytz.timezone('America/New_York')
    for item in items:
        ClientCompatPatch.media(item['media_or_ad'])
        ig_post = {'Platform': 'Instagram',
                   'Date': convert_time(tz, item['media_or_ad']['taken_at']),
                   'Link': 'https://www.instagram.com/p/' + str(item['media_or_ad']['code'])}
        ig_post_copy = ig_post.copy()
        lst.append(ig_post_copy)
    return lst
Beispiel #4
0
 def test_compat_user_list(self):
     self.api.auto_patch = False
     results = self.api.user_following(self.test_user_id)
     self.api.auto_patch = True
     user = results.get('users', [{}])[0]
     user_patched = copy.deepcopy(user)
     ClientCompatPatch.list_user(user_patched)
     self.assertIsNone(user.get('id'))
     self.assertIsNotNone(user_patched.get('id'))
     self.assertIsNone(user.get('profile_picture'))
     self.assertIsNotNone(user_patched.get('profile_picture'))
Beispiel #5
0
 def test_compat_user(self):
     self.api.auto_patch = False
     results = self.api.user_info(self.test_user_id)
     self.api.auto_patch = True
     user = results.get('user', {})
     user_patched = copy.deepcopy(user)
     ClientCompatPatch.user(user_patched)
     self.assertIsNone(user.get('id'))
     self.assertIsNotNone(user_patched.get('id'))
     self.assertIsNone(user.get('bio'))
     self.assertIsNotNone(user_patched.get('bio'))
     self.assertIsNone(user.get('profile_picture'))
     self.assertIsNotNone(user_patched.get('profile_picture'))
     self.assertIsNone(user.get('website'))
     self.assertIsNotNone(user_patched.get('website'))
Beispiel #6
0
 def test_compat_comment(self):
     self.api.auto_patch = False
     results = self.api.media_comments(self.test_media_id)
     self.api.auto_patch = True
     self.assertGreater(len(results.get('comments', [])), 0,
                        'No items returned.')
     comment = results.get('comments', [{}])[0]
     comment_patched = copy.deepcopy(comment)
     ClientCompatPatch.comment(comment_patched)
     self.assertIsNone(comment.get('id'))
     self.assertIsNotNone(comment_patched.get('id'))
     self.assertIsNone(comment.get('created_time'))
     self.assertIsNotNone(comment_patched.get('created_time'))
     self.assertIsNone(comment.get('from'))
     self.assertIsNotNone(comment_patched.get('from'))
Beispiel #7
0
    def scrape(self):
        api = Client(self.username, self.password)
        results = api.feed_timeline()

        comments_vector = []
        #print(results)

        items = [
            item for item in results.get('feed_items', [])
            if item.get('media_or_ad')
        ]
        for item in items:
            # Manually patch the entity to match the public api as closely as possible, optional
            # To automatically patch entities, initialise the Client with auto_patch=True
            ClientCompatPatch.media(item['media_or_ad'])

            if ('ad_metadata' not in item['media_or_ad'].keys()):

                # print(item['media_or_ad']['code'])
                # print("#####################")

                # print(item['media_or_ad']['caption']['text'])

                media_id = item['media_or_ad']['caption']['media_id']

                comments = api.media_comments(media_id)

                # print("#####################")
                # print(comments)
                for comment in comments['comments']:
                    comment_vector = []
                    comment_vector.append(
                        item['media_or_ad']['caption']['text'])
                    comment_vector.append(comment['text'])
                    # print(comment['text'])
                    comments_vector.append(comment_vector)

        return comments_vector
def login(username, password):
    try:
        api = Client(username, password)
        results = api.feed_timeline()
        items = results.get('items', [])
        for item in items:
            print(item)
            media = ClientCompatPatch.media(item)
            print(media['code'])
    except:
        messagebox.showinfo(
            "Hata",
            "Instagram girişi hatalı lütfen kullanıcı adı şifrenizi kontrol ediniz"
        )
Beispiel #9
0
see = api.autocomplete_user_list()

print(see)
# following = api.user_following('123456','1')
# for user in following:
#     print(user['username'])

results = api.feed_timeline()
items = [
    item for item in results.get('feed_items', []) if item.get('media_or_ad')
]
for item in items:
    # Manually patch the entity to match the public api as closely as possible, optional
    # To automatically patch entities, initialise the Client with auto_patch=True
    ClientCompatPatch.media(item['media_or_ad'])
    print(item['media_or_ad']['code'])

# from instagram_web_api import Client, ClientCompatPatch, ClientError, ClientLoginError
#
# # Without any authentication
# web_api = Client(auto_patch=True, drop_incompat_keys=False)
# user_feed_info = web_api.user_feed('329452045', count=10)
# for post in user_feed_info:
#     print('%s from %s' % (post['link'], post['user']['username']))
#
# # Some endpoints, e.g. user_following are available only after authentication
# authed_web_api = Client(
#     auto_patch=True, authenticate=True,
#     username='******', password='******')
#
Beispiel #10
0
from instagram_private_api import Client, ClientCompatPatch

user_name = input("username\n>")
password = input("password\n>")

api = Client(user_name, password)
results = api.saved_feed(1000)
items = [item for item in results.get('items', []) if item.get('media')]
images = []
for item in items:
    # Manually patch the entity to match the public api as closely as possible, optional
    # To automatically patch entities, initialise the Client with auto_patch=True
    ClientCompatPatch.media(item['media'])
    url = item['media']['images']['standard_resolution']['url']
    images.append(url)
Beispiel #11
0
from instagram_private_api import Client, ClientCompatPatch

user_name = '*****@*****.**'
password = '******'

api = Client(user_name, password)
results = api.feed_timeline()
print(results)
items = results.get('feed_items', [])
for item in items:
    # Manually patch the entity to match the public api as closely as possible, optional
    # To automatically patch entities, initialise the Client with auto_patch=True
    ClientCompatPatch.media(item)
    # print(media['code'])
    print(item)
    story_fieldnames = story_records.columns.astype(str)

    account_que = account_ids
    for account in account_que:
        # Call the api

        results = api.user_reel_media(account)

        if str(results['latest_reel_media']) == 'None':
            print('No stories')
            continue

        items = results['items']
        stories = []
        for item in items:
            story_raw = ClientCompatPatch.media(item)
            story = {
                'story_feed_media':
                story_raw.get('story_feed_media'),
                'story_questions':
                story_raw.get('story_questions'),
                'story_countdowns':
                story_raw.get('story_countdowns'),
                'story_hashtags':
                story_raw.get('story_hashtags'),
                'story_voter_registration_stickers':
                story_raw.get('story_voter_registration_stickers'),
                'story_polls':
                story_raw.get('story_polls'),
                'is_dash_eligible':
                story_raw.get('is_dash_eligible'),