Beispiel #1
0
def scrape_all_followers():
    """
    Look at my timeline and collect posts
    Strip out hash tags and save them as objects
    """
    api = InstagramAPI(settings.INSTAGRAM_USERNAME,
                       settings.INSTAGRAM_PASSWORD)
    api.timelineFeed()
    result = api.LastJson

    if result['status'] != 'ok':
        pass

    items = result['items']

    for item in items:
        user = item['user']
        # Grab the user and update their avatar
        i = InstagramPerson.objects.get_or_create(
            username=user['username'],
            real_name=user['full_name'])[0]
        i.avatar = user['profile_pic_url']
        i.save()
        # Save the post
        text = item['caption']['text']
        post = InstagramPost.objects.get_or_create(content=text)[0]

        create_post_cache(post, i.instagrampostcache_set)

        for word in text.split():
            if word[0] == '#':
                InstagramHashtag.objects.get_or_create(
                    original_post=post, content=word)
Beispiel #2
0
def scrape_follower(person):
    api = InstagramAPI(settings.INSTAGRAM_USERNAME,
                       settings.INSTAGRAM_PASSWORD)
    api.login()
    api.getUserFeed(person.username_id)
    result = api.LastJson

    posts = result['items']
    for post in posts:
        caption = post['caption']['text']
        post = person.instagrampost_set.create(content=caption)

        create_post_cache(post, person.instagrampostcache_set)
Beispiel #3
0
def follow_my_instagram_followers():
    api = InstagramAPI(settings.INSTAGRAM_USERNAME,
                       settings.INSTAGRAM_PASSWORD)
    api.login()

    followers = InstagramPerson.objects.all()

    for follower in followers:
        try:
            api.follow(str(follower.username_id))
        except AttributeError as e:
            print e
            return False
Beispiel #4
0
def refresh_and_return_me_from_instagram():
    api = InstagramAPI(settings.INSTAGRAM_USERNAME,
                       settings.INSTAGRAM_PASSWORD)
    api.login(force=True)
    api.getProfileData()
    result = api.LastJson
    me = InstagramPerson.objects.get_or_create(
        username=settings.INSTAGRAM_USERNAME,
        first_name='Tom',
        last_name='Craig',
        real_name=result['user']['full_name'],
        avatar=str(result['user']['hd_profile_pic_versions'][0]['url'])
    )

    return me
Beispiel #5
0
def refresh_instagram_followers():
    api = InstagramAPI(settings.INSTAGRAM_USERNAME,
                       settings.INSTAGRAM_PASSWORD)
    api.login()
    api.getSelfUserFollowers()
    result = api.LastJson

    for user in result['users']:
        person = None
        try:
            person = InstagramPerson.objects.get(
                username=user['username'],
                username_id=user['pk'],
                real_name=user['full_name'])
        except:
            person = InstagramPerson.objects.create(
                username=user['username'],
                username_id=user['pk'],
                real_name=user['full_name'])

        person.avatar = user['profile_pic_url']
        person.save()
Beispiel #6
0
import os, sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "eros.settings")

from django.conf import settings
from integrations.helpers.InstagramAPI.InstagramAPI import InstagramAPI
from integrations.models.instagram import InstagramPerson

api = InstagramAPI("*****@*****.**", settings.INSTAGRAM_PASSWORD)
print settings.INSTAGRAM_USERNAME
print settings.INSTAGRAM_PASSWORD

api.login()

print InstagramPerson.objects.filter(username=settings.INSTAGRAM_USERNAME)
# api.getProfileData()
# result = api.LastJson