Skip to content

Instantly share code, notes, and snippets.

@ekollof
Last active October 2, 2018 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekollof/47e3f3f54f2aee5ab1b512d6222bf292 to your computer and use it in GitHub Desktop.
Save ekollof/47e3f3f54f2aee5ab1b512d6222bf292 to your computer and use it in GitHub Desktop.
Example getting stats from mastodon
#!/usr/bin/env python3.7
import sys
from mastodon import Mastodon
from pprint import pprint
from urllib.parse import urlparse
def main():
host = urlparse(sys.argv[1])
Mastodon.create_app(
'maststats',
api_base_url = sys.argv[1],
to_file = f"{host.netloc}.secret"
)
mastodon = Mastodon(
client_id = f'{host.netloc}.secret',
api_base_url = sys.argv[1]
)
instance = mastodon.instance()
pprint(instance)
activity = mastodon.instance_activity()[0]
pprint(activity)
if __name__ == "__main__":
main()
@ekollof
Copy link
Author

ekollof commented Oct 2, 2018

From my own instance:

 ./getstats.py https://social.hackerheaven.org
{'contact_account': {'acct': 'andrath',
                     'avatar': 'https://social.hackerheaven.org/system/accounts/avatars/000/000/003/original/9dc646fa3ff9ef3e.jpg?1527846922',
                     'avatar_static': 'https://social.hackerheaven.org/system/accounts/avatars/000/000/003/original/9dc646fa3ff9ef3e.jpg?1527846922',
                     'bot': False,
                     'created_at': datetime.datetime(2018, 6, 1, 9, 41, 24, 996000, tzinfo=tzutc()),
                     'display_name': 'Andrath of the Abyss',
                     'emojis': [],
                     'fields': [{'name': 'Weblog',
                                 'value': '<a href="https://coolvibe.org" '
                                          'rel="me nofollow noopener" '
                                          'target="_blank"><span '
                                          'class="invisible">https://</span><span '
                                          'class="">coolvibe.org</span><span '
                                          'class="invisible"></span></a>'},
                                {'name': 'Jabber/XMPP',
                                 'value': 'coolvibe@hackerheaven.org'},
                                {'name': 'Twitter', 'value': '@coolvibe'}],
                     'followers_count': 9,
                     'following_count': 10,
                     'header': 'https://social.hackerheaven.org/system/accounts/headers/000/000/003/original/4202aa01f6944678.jpg?1527846923',
                     'header_static': 'https://social.hackerheaven.org/system/accounts/headers/000/000/003/original/4202aa01f6944678.jpg?1527846923',
                     'id': 3,
                     'locked': False,
                     'note': '<p>Opinionated Metalhead. Creates ungodly music '
                             'when left unattended. Free speech absolutist. '
                             'Abhors injustice. Allergic to censorship. '
                             'Tinkerer.</p>',
                     'statuses_count': 74,
                     'url': 'https://social.hackerheaven.org/@andrath',
                     'username': 'andrath'},
 'description': 'This is my mastodon instance. There are many like it. This '
                'one is mine.',
 'email': 'coolvibe@hackerheaven.org',
 'languages': ['en'],
 'stats': {'domain_count': 1108, 'status_count': 74, 'user_count': 2},
 'thumbnail': 'https://social.hackerheaven.org/packs/preview-9a17d32fc48369e8ccd910a75260e67d.jpg',
 'title': 'Hackerheaven Social Hub',
 'uri': 'social.hackerheaven.org',
 'urls': {'streaming_api': 'wss://social.hackerheaven.org'},
 'version': '2.5.0'}
{'logins': 1,
 'registrations': 0,
 'statuses': 1,
 'week': datetime.datetime(2018, 9, 30, 22, 0, tzinfo=<UTC>)}

@ekollof
Copy link
Author

ekollof commented Oct 2, 2018

Against a bigger instance ;)

./getstats.py https://mastodon.social        
{'contact_account': {'acct': 'Gargron',
                     'avatar': 'https://files.mastodon.social/accounts/avatars/000/000/001/original/ba7cb4a53cf22d9a.png',
                     'avatar_static': 'https://files.mastodon.social/accounts/avatars/000/000/001/original/ba7cb4a53cf22d9a.png',
                     'bot': False,
                     'created_at': datetime.datetime(2016, 3, 16, 14, 34, 26, 392000, tzinfo=tzutc()),
                     'display_name': 'Eugenio',
                     'emojis': [],
                     'fields': [{'name': 'Patreon',
                                 'value': '<a '
                                          'href="https://www.patreon.com/mastodon" '
                                          'rel="me nofollow noopener" '
                                          'target="_blank"><span '
                                          'class="invisible">https://www.</span><span '
                                          'class="">patreon.com/mastodon</span><span '
                                          'class="invisible"></span></a>',
                                 'verified_at': None},
                                {'name': 'E-mail',
                                 'value': 'eugen@zeonfederated.com'},
                                {'name': 'Avatar by',
                                 'value': '<span class="h-card"><a '
                                          'href="https://mastodon.art/@DearMsDear" '
                                          'class="u-url '
                                          'mention">@<span>DearMsDear</span></a></span>'}],
                     'followers_count': 154387,
                     'following_count': 497,
                     'header': 'https://files.mastodon.social/accounts/headers/000/000/001/original/998815725e9554b0.jpg',
                     'header_static': 'https://files.mastodon.social/accounts/headers/000/000/001/original/998815725e9554b0.jpg',
                     'id': 1,
                     'locked': False,
                     'note': '<p>Developer of Mastodon. 25</p>',
                     'statuses_count': 44211,
                     'url': 'https://mastodon.social/@Gargron',
                     'username': 'Gargron'},
 'description': 'This page describes the mastodon.social <em>instance</em> - '
                'wondering what Mastodon is? Check out <a '
                'href="https://joinmastodon.org">joinmastodon.org</a> instead! '
                'In essence, Mastodon is a decentralized, open source social '
                'network. This is just one part of the network, run by the '
                'main developers of the project <img draggable="false" alt="" '
                'class="emojione" '
                'src="https://mastodon.social/emoji/1f418.svg" /> It is not '
                'focused on any particular niche interest - everyone is '
                'welcome as long as you follow our code of conduct!</p><p>Hero '
                'image by <a href="https://mastodon.social/@b_cavello" '
                'class="u-url mention">@<span>b_cavello</span></a>',
 'email': 'hello@joinmastodon.org',
 'languages': ['en'],
 'stats': {'domain_count': 6612, 'status_count': 8575351, 'user_count': 242543},
 'thumbnail': 'https://files.mastodon.social/site_uploads/files/000/000/001/original/DN5wMUeVQAENPwp.jpg_large.jpeg',
 'title': 'Mastodon',
 'uri': 'mastodon.social',
 'urls': {'streaming_api': 'wss://mastodon.social'},
 'version': '2.5.0'}
{'logins': 11668,
 'registrations': 2051,
 'statuses': 48038,
 'week': datetime.datetime(2018, 9, 30, 22, 0, tzinfo=<UTC>)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment