{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Requirement already satisfied: Mastodon.py in /home/mb/.local/lib/python3.7/site-packages (1.5.1)\n", "Requirement already satisfied: python-magic in /usr/local/lib/python3.7/dist-packages (from Mastodon.py) (0.4.15)\n", "Requirement already satisfied: pytz in /home/mb/.local/lib/python3.7/site-packages (from Mastodon.py) (2020.1)\n", "Requirement already satisfied: python-dateutil in /home/mb/.local/lib/python3.7/site-packages (from Mastodon.py) (2.8.1)\n", "Requirement already satisfied: blurhash>=1.1.4 in /home/mb/.local/lib/python3.7/site-packages (from Mastodon.py) (1.1.4)\n", "Requirement already satisfied: requests>=2.4.2 in /usr/lib/python3/dist-packages (from Mastodon.py) (2.21.0)\n", "Requirement already satisfied: decorator>=4.0.0 in /usr/lib/python3/dist-packages (from Mastodon.py) (4.3.0)\n", "Requirement already satisfied: six in /usr/lib/python3/dist-packages (from Mastodon.py) (1.12.0)\n" ] } ], "source": [ "import sys\n", "!{sys.executable} -m pip install Mastodon.py" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from mastodon import Mastodon" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "instance = 'INSERTYOURINSTANCEURLHERE'\n", "username = 'INSERTEMAILADDRESSHERE'\n", "password = 'INSERTPASSWORDSHERE'" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('ijslOh1kdBmHnlycZUhP6bpB0wXayAXqZ_Qr4DMB09Y',\n", " '-TZBLBW2XOrwOoCb2mbIWdxALRS8QiHIgIosrq2PqsE')" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Register your app! This only needs to be done once. Uncomment the code and substitute in your information.\n", "\n", "Mastodon.create_app(\n", " 'bots-as-infrapuncture',\n", " api_base_url = instance,\n", " to_file = 'mastodon-bot.secret'\n", ")\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'497bMScwM_Z1goP0Q_lNUsmbmbYByw3XXb-6KBxt-K8'" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Then login. This can be done every time, or use persisted.\n", "\n", "mastodon = Mastodon(\n", " client_id = 'mastodon-bot.secret',\n", " api_base_url = instance\n", ")\n", "\n", "mastodon.log_in(\n", " username,\n", " password,\n", " to_file = 'mastodon-bot-usercred.secret'\n", ")" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'id': 104964779309814302,\n", " 'created_at': datetime.datetime(2020, 10, 2, 10, 43, 46, 538000, tzinfo=tzutc()),\n", " 'in_reply_to_id': None,\n", " 'in_reply_to_account_id': None,\n", " 'sensitive': False,\n", " 'spoiler_text': '',\n", " 'visibility': 'public',\n", " 'language': 'en',\n", " 'uri': 'https://post.lurk.org/users/manetta/statuses/104964779309814302',\n", " 'url': 'https://post.lurk.org/@manetta/104964779309814302',\n", " 'replies_count': 0,\n", " 'reblogs_count': 0,\n", " 'favourites_count': 0,\n", " 'local_only': False,\n", " 'activity_pub_type': '',\n", " 'favourited': False,\n", " 'reblogged': False,\n", " 'muted': False,\n", " 'bookmarked': False,\n", " 'pinned': False,\n", " 'content': '
Testing to toot for the very very first time, excitingly using #mastodonpy !
',\n", " 'reblog': None,\n", " 'application': {'name': 'bagofwords', 'website': None},\n", " 'account': {'id': 4791,\n", " 'username': 'manetta',\n", " 'acct': 'manetta',\n", " 'display_name': 'manetta',\n", " 'locked': False,\n", " 'bot': False,\n", " 'discoverable': False,\n", " 'group': False,\n", " 'created_at': datetime.datetime(2018, 5, 2, 18, 32, 50, 698000, tzinfo=tzutc()),\n", " 'note': 'software studies networks publishing (#nobot)
',\n", " 'url': 'https://post.lurk.org/@manetta',\n", " 'avatar': 'https://post.lurk.org/system/accounts/avatars/000/004/791/original/9ce0ebe273ada8aa.jpg?1584822874',\n", " 'avatar_static': 'https://post.lurk.org/system/accounts/avatars/000/004/791/original/9ce0ebe273ada8aa.jpg?1584822874',\n", " 'header': 'https://post.lurk.org/system/accounts/headers/000/004/791/original/5e99159ef049b6dc.png?1584823076',\n", " 'header_static': 'https://post.lurk.org/system/accounts/headers/000/004/791/original/5e99159ef049b6dc.png?1584823076',\n", " 'followers_count': 134,\n", " 'following_count': 175,\n", " 'statuses_count': 154,\n", " 'last_status_at': datetime.datetime(2020, 10, 2, 0, 0),\n", " 'emojis': [],\n", " 'fields': []},\n", " 'media_attachments': [],\n", " 'mentions': [],\n", " 'tags': [{'name': 'mastodonpy',\n", " 'url': 'https://post.lurk.org/tags/mastodonpy'}],\n", " 'emojis': [],\n", " 'card': None,\n", " 'poll': None}" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# To post, create an actual API instance.\n", "\n", "mastodon = Mastodon(\n", " access_token = 'mastodon-bot-usercred.secret',\n", " api_base_url = instance\n", ")\n", "\n", "mastodon.toot('Testing to toot for the very very first time, excitingly using #mastodonpy !')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 4 }