Skip to content

Instantly share code, notes, and snippets.

@Alliegaytor
Created February 4, 2024 09:50
Show Gist options
  • Save Alliegaytor/c562dc2b45610c677e51e3763f33c481 to your computer and use it in GitHub Desktop.
Save Alliegaytor/c562dc2b45610c677e51e3763f33c481 to your computer and use it in GitHub Desktop.
Graph lemmy user's comment frequency
# Uses lemmy api to grab all of a user's comments and show how/when
# they are active
import json
import requests
import pandas as pd
import matplotlib.pyplot as plt
# Change these as needed
username = 'neurospice'
server = 'https://lemmy.dbzer0.com'
# Starting page
page = 1
headers = {"accept": "application/json"}
url = server + '/api/v3/user?username=' + username + '&limit=50&sort=New&page='
def getResponse(page: int):
return json.loads(requests.get(url + str(page), headers=headers).text)
data = getResponse(page)
comment_dates = []
while data['comments']:
comment_dates += list(map(lambda cmt: cmt['comment']['published'], data['comments']))
page += 1
data = getResponse(page)
df = pd.DataFrame(index=comment_dates)
df.index = pd.to_datetime(df.index)
df['comments'] = df.index.value_counts()
print(f"{username}'s total comments: {df['comments'].sum()}") # Sum
df.resample('w').sum().plot(title='Weekly Comments on lemmy')
plt.savefig('plot.png')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment