2020-10-02 13:26:36 +02:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
2020-10-02 17:19:58 +02:00
|
|
|
"# 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)"
|
2020-10-02 13:26:36 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2020-10-02 17:19:58 +02:00
|
|
|
"execution_count": null,
|
2020-10-02 13:26:36 +02:00
|
|
|
"metadata": {},
|
2020-10-02 17:19:58 +02:00
|
|
|
"outputs": [],
|
2020-10-02 13:26:36 +02:00
|
|
|
"source": [
|
|
|
|
"import sys\n",
|
|
|
|
"!{sys.executable} -m pip install Mastodon.py"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2020-10-02 17:19:58 +02:00
|
|
|
"execution_count": null,
|
2020-10-02 13:26:36 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2020-10-02 17:19:58 +02:00
|
|
|
"from time import sleep\n",
|
|
|
|
"from mastodon import Mastodon # https://github.com/halcy/Mastodon.py"
|
2020-10-02 13:26:36 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2020-10-02 17:19:58 +02:00
|
|
|
"instance = 'https://botsin.space'\n",
|
|
|
|
"username = 'info@varia.zone'\n",
|
|
|
|
"password = 'INSERTPASSWORDHERE'"
|
2020-10-02 13:26:36 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
2020-10-02 17:19:58 +02:00
|
|
|
"execution_count": 20,
|
2020-10-02 13:26:36 +02:00
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2020-10-02 17:19:58 +02:00
|
|
|
"# Register the bot as an application.\n",
|
|
|
|
"\n",
|
|
|
|
"# This only needs to be done once!\n",
|
|
|
|
"# (we already did it :--))\n",
|
2020-10-02 13:26:36 +02:00
|
|
|
"\n",
|
2020-10-02 17:19:58 +02:00
|
|
|
"# Mastodon.create_app(\n",
|
|
|
|
"# 'bots-as-infrapunctures',\n",
|
|
|
|
"# api_base_url = instance,\n",
|
|
|
|
"# to_file = 'mastodon-bot.secret'\n",
|
|
|
|
"# )"
|
2020-10-02 13:26:36 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2020-10-02 17:19:58 +02:00
|
|
|
"# First login.\n",
|
2020-10-02 13:26:36 +02:00
|
|
|
"\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",
|
|
|
|
")"
|
|
|
|
]
|
|
|
|
},
|
2020-10-02 17:19:58 +02:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"Now we will run the bot!!"
|
|
|
|
]
|
|
|
|
},
|
2020-10-02 13:26:36 +02:00
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2020-10-02 17:19:58 +02:00
|
|
|
"# Now let's run the bot!\n",
|
2020-10-02 13:26:36 +02:00
|
|
|
"\n",
|
|
|
|
"mastodon = Mastodon(\n",
|
|
|
|
" access_token = 'mastodon-bot-usercred.secret',\n",
|
|
|
|
" api_base_url = instance\n",
|
|
|
|
")\n",
|
|
|
|
"\n",
|
2020-10-02 17:19:58 +02:00
|
|
|
"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"
|
2020-10-02 13:26:36 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"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
|
|
|
|
}
|