For the Mastodon archive, it is recommended to refer to The above [Python] Post date and time scatter plot in the Mastodon archive .... Especially, I will omit the part to read from the json file and store the toot contents in objects this time.
at = []
for object in objects:
if '@' in object:
at.append(object)
name = []
others = []
for a in at:
while '@' in a:
if ' ' in a:
name.append(a[1:a.index(' ')])
a=a[a.index(' ')+1:]
else:
others.append(a)
break
len(name)
I have stripped the tag from the toot content, but since @onekodate remains at the beginning, I will first search for the one that contains @ from the toot content. Next, fetch from the second to the blank after the ID. Note the toots without this space and the toots with multiple destinations. Toots with no blanks are collected by others, so it's a good idea to check them. If there are any mentions, they are usually empty, so I will omit them. Also, repeat the operation with the while statement as long as there is @ in the rest so as not to miss multiple destinations. This will collect the destination IDs.
import pandas as pd
name = pd.Series(name)
namerank = name.value_counts()
print(namerank[0:29])
Since value.counts () of pandas.Series is convenient, I purposely converted it to use it, and it is designed to display the top 30 people.
import json
import numpy as np
file = 'likes.json'
with open(file, 'r', encoding='utf-8') as fi:
novels = json.load(fi)
for novel in novels:
likes = np.array(novels[novel])
len(likes)
Load likes.json containing the destination URL of the favourite in exactly the same way as you loaded outbox.json at the beginning of the last time.
favuser = []
others = []
for like in likes:
if 'users' in like and 'statuses' in like:
favuser.append(like[like.index('users')+6:like.index('statuses')-1])
else:
others.append(like)
len(favuser)
In likes, the URL of the destination of the favorite such as https://mstdn.jp/users/onekodate/statuses/99502681496689830 is written, and the URL of Mastodon contains the ID information, so please take it out. You can tell who you are, but there are two problems here. ・ Misskey and Pleroma URLs do not include ID information -Occasionally, the mysterious character string'tag: pawoo.net, 2017-09-15: objectId = 41135378: objectType = Status'is included in the URL. There is nothing I can do about these two, so I'll set them aside for others. Therefore, the URL contains'users' and'statuses', and the character string between them is fetched as the ID.
import pandas as pd
fav = pd.Series(favuser)
favrank = fav.value_counts()
print(favrank[0:29])
This is exactly the same as when replying. You don't have to import pandas every time, though.
follower = np.zeros((10,len(favuser)))
for i in range(len(favuser)):
for j in range(10):
if favuser[i]==favrank.index[j]:
follower[j][i:len(favuser)] = follower[j][i] + 1
I will graph the transition of the number of fabs for the 10 prestigious people who have a lot of fabs from me. There is no time data in likes.json, but it is probably arranged in chronological order, so let's assume that the order can be regarded as time. Create a two-dimensional array using numpy and count by force. If you just want to draw a graph, I feel that you should write it every time without creating a two-dimensional array.
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10, 5), dpi=200)
for j in range(10):
plt.plot(range(len(favuser)),follower[j],label=favrank.index[j])
plt.legend(bbox_to_anchor=(1, 1), loc='upper left', borderaxespad=0, fontsize=18)
fig.savefig('favtime.png')
Here is the one with the legend removed. The number one person was overwhelming, but it seems that it has been sluggish recently, certainly I have not seen it recently. The light blue person in 10th place seems to have been sluggish recently, because he has reincarnated.
I thought it would be interesting to see the relationship with my followers, so I looked at the replies. You can probably boost in the same way. If you can see this person, it will be unrequited love or both feelings and it will be fun, but we are waiting for everyone's use.
Recommended Posts