This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from InstagramAPI import InstagramAPI | |
from tqdm import tqdm | |
import pandas as pd | |
api = InstagramAPI("username", "password") | |
api.login() # login |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#first let's figure out who I am | |
api.getSelfUsernameInfo() | |
result = api.LastJson | |
user_id = result['user']['pk'] # my own personal user id | |
me = result['user']['full_name'] # my own personal username | |
api.getSelfUsersFollowing() | |
result = api.LastJson | |
follow_relationships = [] | |
for user in tqdm(result['users']): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df = pd.DataFrame(follow_relationships, | |
columns=['src_id','dst_id', 'src_name', 'dst_name']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import graphistry | |
graphistry.register(key='Email pygraphistry@graphistry.com for an API key!') | |
graphistry.bind(source='src_name', destination='dst_name').edges(df).plot() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from IPython.display import Image, display | |
import networkx as nx | |
import numpy as np | |
import time | |
import datetime | |
#get all users that I am directly following | |
api.getSelfUsersFollowing() | |
result = api.LastJson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#get my info | |
api.getSelfUsernameInfo() | |
result = api.LastJson | |
user_id = result['user']['pk'] # my own personal user id | |
me = result['user']['full_name'] # my own personal username | |
#get photos that I've liked | |
api.getLikedMedia() | |
result = api.LastJson | |
users = [item['user'] for item in result['items']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def find_hastags(text): | |
return re.findall(r'#(\w+)', text) | |
hashtags = [] | |
#photos that I've recently liked | |
api.getLikedMedia() | |
result = api.LastJson | |
for r in tqdm(result['items']): | |
if r['caption'] is not None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index(['adventure', 'climbing_pictures_of_Instagram', 'love', 'optoutside', | |
'mtb', 'mountains', 'sunset', 'skiuphill', 'earnyourturns', 'colorado'], | |
dtype='object') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interest_dict = {} | |
for tag in top_hashtags.index: | |
api.getHashtagFeed(tag) | |
result = api.LastJson | |
interest_dict[tag] = result | |
urls = [] | |
num_likes = [] | |
tags = [] | |
for tag in interest_dict.keys(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
images_top_tags = [] | |
for tag in top_tags.index: | |
img = Image(top_tags.loc[tag]['urls'], format='jpeg') | |
display(img) | |
print(tag) | |
images_top_tags.append(img) |
OlderNewer