Browse Source

pushing the bot

master
manetta 4 years ago
parent
commit
7b3256f3d5
  1. 187
      content/bot-example/mastodon-bot.ipynb

187
content/bot-example/mastodon-bot.ipynb

@ -22,22 +22,19 @@
] ]
}, },
{ {
"cell_type": "code", "cell_type": "markdown",
"execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [],
"source": [ "source": [
"import sys\n", "## Import the Mastodon library"
"!{sys.executable} -m pip install Mastodon.py"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "markdown",
"execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [],
"source": [ "source": [
"from mastodon import Mastodon # https://github.com/halcy/Mastodon.py" "We're using a Python library that is written for Mastodon.\n",
"\n",
"https://github.com/halcy/Mastodon.py"
] ]
}, },
{ {
@ -46,57 +43,40 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"instance = 'https://botsin.space'\n", "# import sys\n",
"# username = 'USERNAME'\n", "# !{sys.executable} -m pip install Mastodon.py"
"# password = 'PASSWORD'"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 9,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Register the bot as an application, save details as a (.secret) plain text file.\n", "from mastodon import Mastodon "
"\n", ]
"# This only needs to be done once!\n", },
"# (we already did it)\n", {
"\n", "cell_type": "markdown",
"# Mastodon.create_app(\n", "metadata": {},
"# 'bots-as-infrapunctures',\n", "source": [
"# api_base_url = instance,\n", "## Configuring the infrastructure"
"# to_file = 'mastodon-bot.secret'\n",
"# )"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 15,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Write your login details to a (.secret) plain text file.\n", "instance = 'https://botsin.space'"
"\n",
"# This only needs to be done once!\n",
"# (we already did it)\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", "cell_type": "markdown",
"metadata": {}, "metadata": {},
"source": [ "source": [
"Now we will run the bot!!" "## Starting the bot...."
] ]
}, },
{ {
@ -105,21 +85,28 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Start up the bot....\n",
"\n",
"mastodon = Mastodon(\n", "mastodon = Mastodon(\n",
" access_token = 'mastodon-bot-usercred.secret',\n", " access_token = 'mastodon-bot-usercred.secret',\n",
" api_base_url = instance\n", " api_base_url = instance\n",
")" ")"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Tooting time! \n",
"\n",
"These are different examples you can use."
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Start tooting!\n", "# Write a toot.\n",
"\n", "\n",
"mastodon.toot('testing tooting')" "mastodon.toot('testing tooting')"
] ]
@ -149,15 +136,47 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 24,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"data": {
"text/plain": [
"{'id': 105158839281621670,\n",
" 'type': 'image',\n",
" 'url': 'https://files.botsin.space/media_attachments/files/105/158/839/281/621/670/original/b6092861a5b9fea8.png',\n",
" 'preview_url': 'https://files.botsin.space/media_attachments/files/105/158/839/281/621/670/small/b6092861a5b9fea8.png',\n",
" 'remote_url': None,\n",
" 'preview_remote_url': None,\n",
" 'text_url': 'https://botsin.space/media/DMDQwSmifxEp29TPEVw',\n",
" 'meta': {'original': {'width': 1707,\n",
" 'height': 960,\n",
" 'size': '1707x960',\n",
" 'aspect': 1.778125},\n",
" 'small': {'width': 533,\n",
" 'height': 300,\n",
" 'size': '533x300',\n",
" 'aspect': 1.7766666666666666}},\n",
" 'description': None,\n",
" 'blurhash': 'UIFPBE9F00?bIUM{%MofRjt7oft7t7M{Rjj['}"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [ "source": [
"# Something with a dictionary\n", "# Tooting a media file (audio, video, image)\n",
"# https://mastodonpy.readthedocs.io/en/stable/#media-dicts\n",
"\n",
"import urllib.request\n",
"\n",
"url = 'https://vvvvvvaria.org/bots-as-digital-infrapunctures/images/slide.png'\n",
"caption = 'Testing'\n",
"\n", "\n",
"vocabulary = {\n", "urllib.request.urlretrieve(url, 'media/tmp.jpg')\n",
" \n", "mastodon.media_post('media/tmp.jpg', 'image/jpeg')"
"}"
] ]
}, },
{ {
@ -168,9 +187,18 @@
"source": [ "source": [
"# Generate sentences ? \n", "# Generate sentences ? \n",
"\n", "\n",
"import random\n",
"\n",
"names = ['', '', '']\n", "names = ['', '', '']\n",
"objects = ['', '', '']\n", "objects = ['', '', '']\n",
"actions = ['', '', '']" "actions = ['', '', '']\n",
"\n",
"n = random.choice(names)\n",
"o = random.choice(objects)\n",
"a = random.choice(actions)\n",
"\n",
"toot = ''\n",
"mastodon.toot(toot)\n"
] ]
}, },
{ {
@ -194,6 +222,65 @@
"print(datetime.now())\n" "print(datetime.now())\n"
] ]
}, },
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Make your own bot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# instance = 'URL'\n",
"# username = 'USERNAME'\n",
"# password = 'PASSWORD'"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Register the bot as an application, save details as a (.secret) plain text file.\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": [
"# Write your login details to a (.secret) plain text file.\n",
"\n",
"# This only needs to be done once!\n",
"# (we already did it)\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", "cell_type": "code",
"execution_count": null, "execution_count": null,

Loading…
Cancel
Save