Skip to content

Commit f9f452d

Browse files
author
YOGESHWARAN R
committed
added instagram-analyzer
1 parent baf022d commit f9f452d

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Instagram Analyzer
2+
3+
This Scripts analyze the Instagram user data like Followers, Followings and Posts with Matplotlib
4+
bar charts.
5+
6+
## How to use this script?
7+
8+
1. Install the required packages
9+
10+
`pip install -r requirements.txt`
11+
12+
2. Make a text file of list of Instagram username. For example
13+
`user.txt` contains
14+
15+
```
16+
github
17+
pubg
18+
facebook
19+
iplt20
20+
chennaiipl
21+
google
22+
```
23+
24+
3. Run the script
25+
26+
```python instagram_analyzer.py user.txt```
27+
28+
## Author
29+
30+
[YOGESHWARAN R]("https://github.com/yogeshwaran01/)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
from instagramy import InstagramUser
4+
import sys
5+
6+
"""
7+
Usage:
8+
python instalysis.py <text_file_of_usernames>
9+
"""
10+
11+
try:
12+
filename = sys.argv[1]
13+
print("Extracting...")
14+
except (IndexError, KeyError):
15+
print("List of username as textfile in arguement")
16+
sys.exit()
17+
18+
usernames = []
19+
file = open(filename, "r")
20+
for line in file:
21+
if line != "\n":
22+
usernames.append(str(line).strip())
23+
followers = []
24+
following = []
25+
posts = []
26+
27+
for username in usernames:
28+
user = InstagramUser(username)
29+
followers.append(user.number_of_followers)
30+
following.append(user.number_of_followings)
31+
posts.append(user.number_of_posts)
32+
33+
x = np.arange(len(usernames)) # the label locations
34+
width = 0.25 # the width of the bars
35+
36+
fig, ax = plt.subplots()
37+
rects1 = ax.bar(x + 0.2, followers, width, label="Followers")
38+
rects2 = ax.bar(x, following, width, label="Following")
39+
rects3 = ax.bar(x - 0.2, posts, width, label="Posts")
40+
41+
# Add some text for labels, title and custom x-axis tick labels, etc.
42+
ax.set_ylabel("Popularity")
43+
ax.yaxis.set_visible(True)
44+
ax.set_title("Username")
45+
ax.set_xticks(x)
46+
ax.set_xticklabels(usernames)
47+
ax.legend()
48+
49+
50+
def autolabel(rects):
51+
"""Attach a text label above each bar in *rects*, displaying its height."""
52+
for rect in rects:
53+
height = rect.get_height()
54+
ax.annotate(
55+
"{}".format(height),
56+
xy=(rect.get_x() + rect.get_width() / 2, height),
57+
xytext=(0, 3), # 3 points vertical offset
58+
textcoords="offset points",
59+
ha="center",
60+
va="bottom",
61+
)
62+
63+
64+
autolabel(rects1)
65+
autolabel(rects2)
66+
autolabel(rects3)
67+
fig.tight_layout()
68+
plt.show()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
instagramy==3.0
2+
matplotlib==3.3.2
3+
numpy==1.19.2

0 commit comments

Comments
 (0)