pushing the bot

This commit is contained in:
manetta 2020-11-05 18:19:38 +01:00
parent 76a55d1faf
commit 7b3256f3d5

View File

@ -21,14 +21,30 @@
"(explain a bit how Jupyter notebooks work)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Import the Mastodon library"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We're using a Python library that is written for Mastodon.\n",
"\n",
"https://github.com/halcy/Mastodon.py"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"!{sys.executable} -m pip install Mastodon.py"
"# import sys\n",
"# !{sys.executable} -m pip install Mastodon.py"
]
},
{
@ -37,7 +53,30 @@
"metadata": {},
"outputs": [],
"source": [
"from mastodon import Mastodon # https://github.com/halcy/Mastodon.py"
"from mastodon import Mastodon "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configuring the infrastructure"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"instance = 'https://botsin.space'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Starting the bot...."
]
},
{
@ -46,7 +85,157 @@
"metadata": {},
"outputs": [],
"source": [
"instance = 'https://botsin.space'\n",
"mastodon = Mastodon(\n",
" access_token = 'mastodon-bot-usercred.secret',\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",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Write a toot.\n",
"\n",
"mastodon.toot('testing tooting')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Another one, automized over a longer period of time\n",
"\n",
"from time import sleep\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) # 300 seconds = 5 minutes"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"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": [
"# 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",
"urllib.request.urlretrieve(url, 'media/tmp.jpg')\n",
"mastodon.media_post('media/tmp.jpg', 'image/jpeg')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Generate sentences ? \n",
"\n",
"import random\n",
"\n",
"names = ['', '', '']\n",
"objects = ['', '', '']\n",
"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"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-11-05 17:31:54.233814\n"
]
}
],
"source": [
"# Using the current time\n",
"\n",
"from datetime import datetime\n",
"\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'"
]
@ -92,108 +281,6 @@
"# )"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now we will run the bot!!"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Start up the bot....\n",
"\n",
"mastodon = Mastodon(\n",
" access_token = 'mastodon-bot-usercred.secret',\n",
" api_base_url = instance\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Start tooting!\n",
"\n",
"mastodon.toot('testing tooting')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Another one, automized over a longer period of time\n",
"\n",
"from time import sleep\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) # 300 seconds = 5 minutes"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Something with a dictionary\n",
"\n",
"vocabulary = {\n",
" \n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Generate sentences ? \n",
"\n",
"names = ['', '', '']\n",
"objects = ['', '', '']\n",
"actions = ['', '', '']"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"2020-11-05 17:31:54.233814\n"
]
}
],
"source": [
"# Using the current time\n",
"\n",
"from datetime import datetime\n",
"\n",
"print(datetime.now())\n"
]
},
{
"cell_type": "code",
"execution_count": null,