Skip to content

Instantly share code, notes, and snippets.

View jessienewell's full-sized avatar

Jessie N jessienewell

  • GetStream.io
  • Colorado
View GitHub Profile
from InstagramAPI import InstagramAPI
from tqdm import tqdm
import pandas as pd
api = InstagramAPI("username", "password")
api.login() # login
#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']):
df = pd.DataFrame(follow_relationships,
columns=['src_id','dst_id', 'src_name', 'dst_name'])
import graphistry
graphistry.register(key='Email pygraphistry@graphistry.com for an API key!')
graphistry.bind(source='src_name', destination='dst_name').edges(df).plot()
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
#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']]
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:
Index(['adventure', 'climbing_pictures_of_Instagram', 'love', 'optoutside',
'mtb', 'mountains', 'sunset', 'skiuphill', 'earnyourturns', 'colorado'],
dtype='object')
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():
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)