# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# <img src="http://andtek.pro/wp-content/uploads/2016/12/Sonity-FINAL-350x350.jpg" width="240" height="240" align="center"/>
#
# # SonityWolf Post Analyzer
#
# ## Microtargeting tool
#
# Based on the information provided by the profilecrawl, this notebook generates hashtags microtargeting the users based on the analysis of your profile

#dependences:
from os import listdir
from os.path import isfile, join
import json
from pprint import pprint
from collections import Counter
from IPython.core.display import display, HTML

accounts = [f.replace(".json","") for f in listdir("./accounts") if isfile(join("./accounts", f))]
print("Accounts Avalaible:")
for index, account in enumerate(accounts):
    print(f"{index} - {account}")

account = accounts[0] #Choose one of the list starting from 0

account

with open(f"accounts/{account}.json") as f:
    data = json.load(f)
# pprint(data)

# +
#Get All Tags
all_tags = []

for post in data['posts']:
    all_tags += post['tags']

# +
hashtag_counter = Counter([x.lower() for x in all_tags])

#pprint(hashtag_counter)
# -

hashtag_render = ""
for ht in [tup[0] for tup in hashtag_counter.most_common(40)]:
    hashtag_render += ht + " "
hashtag_render

hashtag_render.replace("#","")

# +
# %matplotlib inline
from matplotlib import pyplot as plt
import pandas as pd

graph = hashtag_counter.most_common(20)

x = [tup[0] for tup in graph]
y = [tup[1] for tup in graph]

print(x)
s = pd.Series(y, index=x)

s.plot.bar(figsize=(20,10))
plt.xlabel('Hashtags')
plt.ylabel('Number of apparition in posts')
plt.title("Hashtags Usage");
# -

#Most Liked Post
most_liked = {'likes':0}
for post in data['posts']:
    if post['likes'] > most_liked['likes']:
        most_liked = post
display(HTML(f"<img src={most_liked['img']} align=\"center\"/>"))
pprint(most_liked)

# +
#less_liked
for post in data['posts']:
    try:    
        if post['likes'] < most_liked['likes']:
            less_liked = post
    except:
        less_liked = post

display(HTML(f"<img src={less_liked['img']} align=\"center\"/>"))
pprint(less_liked)
# -



StarcoderdataJupyterScriptsDedupFiltered