Skip to content

Commit d6e8eae

Browse files
authored
Merge pull request Python-World#105 from yogeshwaran01/master
Added Instagram Analyzer
2 parents 21f642b + b391a1a commit d6e8eae

File tree

4 files changed

+101
-0
lines changed

4 files changed

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

0 commit comments

Comments
 (0)