ccl
4 years ago
7 changed files with 300 additions and 40 deletions
@ -0,0 +1,247 @@ |
|||||
|
{ |
||||
|
"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": 9, |
||||
|
"metadata": {}, |
||||
|
"outputs": [], |
||||
|
"source": [ |
||||
|
"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 = '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": "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": 7, |
||||
|
"metadata": {}, |
||||
|
"outputs": [ |
||||
|
{ |
||||
|
"name": "stdout", |
||||
|
"output_type": "stream", |
||||
|
"text": [ |
||||
|
"<method 'time' of 'datetime.datetime' objects>\n" |
||||
|
] |
||||
|
} |
||||
|
], |
||||
|
"source": [ |
||||
|
"# Using the current time\n", |
||||
|
"\n", |
||||
|
"from datetime import datetime\n", |
||||
|
"\n", |
||||
|
"print(datetime.now)" |
||||
|
] |
||||
|
}, |
||||
|
{ |
||||
|
"cell_type": "code", |
||||
|
"execution_count": null, |
||||
|
"metadata": {}, |
||||
|
"outputs": [], |
||||
|
"source": [] |
||||
|
}, |
||||
|
{ |
||||
|
"cell_type": "code", |
||||
|
"execution_count": null, |
||||
|
"metadata": {}, |
||||
|
"outputs": [], |
||||
|
"source": [] |
||||
|
}, |
||||
|
{ |
||||
|
"cell_type": "code", |
||||
|
"execution_count": null, |
||||
|
"metadata": {}, |
||||
|
"outputs": [], |
||||
|
"source": [] |
||||
|
}, |
||||
|
{ |
||||
|
"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 |
||||
|
} |
Loading…
Reference in new issue