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.
 
 
 
 
 

148 lines
3.0 KiB

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Mastodon bot Example"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This Mastodon bot example is part of the module *Bots as Infrapuncture*. :-)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(explain a bit how Jupyter notebooks work)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"!{sys.executable} -m pip install Mastodon.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from time import sleep\n",
"from mastodon import Mastodon # https://github.com/halcy/Mastodon.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"instance = 'https://botsin.space'\n",
"username = 'info@varia.zone'\n",
"password = 'INSERTPASSWORDHERE'"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"# Register the bot as an application.\n",
"\n",
"# This only needs to be done once!\n",
"# (we already did it :--))\n",
"\n",
"# Mastodon.create_app(\n",
"# 'bots-as-infrapunctures',\n",
"# api_base_url = instance,\n",
"# to_file = 'mastodon-bot.secret'\n",
"# )"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# First login.\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": "markdown",
"metadata": {},
"source": [
"Now we will run the bot!!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Now let's run the bot!\n",
"\n",
"mastodon = Mastodon(\n",
" access_token = 'mastodon-bot-usercred.secret',\n",
" api_base_url = instance\n",
")\n",
"\n",
"toots = [\n",
" 'Sentence 1',\n",
" 'Sentence 2',\n",
" 'Sentence 3',\n",
" 'Sentence 4',\n",
" 'Sentence 5'\n",
"]\n",
"\n",
"for toot in toots:\n",
" mastodon.toot(toot)\n",
" sleep(300) # 5 minutes"
]
}
],
"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
}