This is the repository for the online module Bots as Digital Infrapuncture, commissioned by the Utrecht University
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

137 lines
3.7 KiB

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Mastodon-bot Example"
]
},
{
"cell_type": "code",
"execution_count": 10,
"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: six in /usr/lib/python3/dist-packages (from Mastodon.py) (1.12.0)\n",
"Requirement already satisfied: requests>=2.4.2 in /usr/lib/python3/dist-packages (from Mastodon.py) (2.21.0)\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: python-magic in /usr/local/lib/python3.7/dist-packages (from Mastodon.py) (0.4.15)\n",
"Requirement already satisfied: decorator>=4.0.0 in /usr/lib/python3/dist-packages (from Mastodon.py) (4.3.0)\n",
"Requirement already satisfied: pytz in /home/mb/.local/lib/python3.7/site-packages (from Mastodon.py) (2020.1)\n"
]
}
],
"source": [
"import sys\n",
"!{sys.executable} -m pip install Mastodon.py"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from mastodon import Mastodon\n",
"# https://github.com/halcy/Mastodon.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"instance = 'INSERTYOURINSTANCEURLHERE'\n",
"username = 'INSERTEMAILADDRESSHERE'\n",
"password = 'INSERTPASSWORDSHERE'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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": null,
"metadata": {},
"outputs": [],
"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": null,
"metadata": {},
"outputs": [],
"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
}