Browse Source

adding a mastodon bot notebook

master
manetta 4 years ago
parent
commit
4d7c2844ab
  1. 0
      content/Section 3 - Bots/1-introduction.md
  2. 0
      content/Section 3 - Bots/10-theoretical-perspectives-on-bots.md
  3. 0
      content/Section 3 - Bots/11-andreas-question-1.md
  4. 0
      content/Section 3 - Bots/12-andreas-question-2.md
  5. 0
      content/Section 3 - Bots/13-andreas-question-3.md
  6. 0
      content/Section 3 - Bots/14-andreas-question-4.md
  7. 0
      content/Section 3 - Bots/15-andreas-question-5.md
  8. 0
      content/Section 3 - Bots/2-examples.md
  9. 0
      content/Section 3 - Bots/3-bot-logic.md
  10. 0
      content/Section 3 - Bots/4-bots-and-infrastructures.md
  11. 0
      content/Section 3 - Bots/5-question-1.md
  12. 0
      content/Section 3 - Bots/6-question-2.md
  13. 0
      content/Section 3 - Bots/7-question-3.md
  14. 0
      content/Section 3 - Bots/8-question-4.md
  15. 0
      content/Section 3 - Bots/9-question-5.md
  16. 0
      content/Section 5 - Infrapunctural Imaginaries (exercise)/1-introduction.md
  17. 0
      content/Section 5 - Infrapunctural Imaginaries (exercise)/2-step-1.md
  18. 0
      content/Section 5 - Infrapunctural Imaginaries (exercise)/3-step-2.md
  19. 0
      content/Section 5 - Infrapunctural Imaginaries (exercise)/4-step-3.md
  20. 0
      content/Section 5 - Infrapunctural Imaginaries (exercise)/5-step-4.md
  21. 0
      content/Section 6 - Critical Interventions Through Bots (exercise)/1-introduction.md
  22. 0
      content/Section 6 - Critical Interventions Through Bots (exercise)/2-example-bot.md
  23. 0
      content/Section 6 - Critical Interventions Through Bots (exercise)/3-situated-bot-code.md
  24. 213
      content/Section 6 - Critical Interventions Through Bots (exercise)/mastodon-bot.ipynb

0
content/Section 3 - Bot Logic/1-introduction.md → content/Section 3 - Bots/1-introduction.md

0
content/Section 3 - Bot Logic/10-theoretical-perspectives-on-bots.md → content/Section 3 - Bots/10-theoretical-perspectives-on-bots.md

0
content/Section 3 - Bot Logic/11-andreas-question-1.md → content/Section 3 - Bots/11-andreas-question-1.md

0
content/Section 3 - Bot Logic/12-andreas-question-2.md → content/Section 3 - Bots/12-andreas-question-2.md

0
content/Section 3 - Bot Logic/13-andreas-question-3.md → content/Section 3 - Bots/13-andreas-question-3.md

0
content/Section 3 - Bot Logic/14-andreas-question-4.md → content/Section 3 - Bots/14-andreas-question-4.md

0
content/Section 3 - Bot Logic/15-andreas-question-5.md → content/Section 3 - Bots/15-andreas-question-5.md

0
content/Section 3 - Bot Logic/2-examples.md → content/Section 3 - Bots/2-examples.md

0
content/Section 3 - Bot Logic/3-bot-logic.md → content/Section 3 - Bots/3-bot-logic.md

0
content/Section 3 - Bot Logic/4-bots-and-infrastructures.md → content/Section 3 - Bots/4-bots-and-infrastructures.md

0
content/Section 3 - Bot Logic/5-question-1.md → content/Section 3 - Bots/5-question-1.md

0
content/Section 3 - Bot Logic/6-question-2.md → content/Section 3 - Bots/6-question-2.md

0
content/Section 3 - Bot Logic/7-question-3.md → content/Section 3 - Bots/7-question-3.md

0
content/Section 3 - Bot Logic/8-question-4.md → content/Section 3 - Bots/8-question-4.md

0
content/Section 3 - Bot Logic/9-question-5.md → content/Section 3 - Bots/9-question-5.md

0
content/Section 4 - Infrapunctural Imaginaries (exercise)/1-introduction.md → content/Section 5 - Infrapunctural Imaginaries (exercise)/1-introduction.md

0
content/Section 4 - Infrapunctural Imaginaries (exercise)/2-step-1.md → content/Section 5 - Infrapunctural Imaginaries (exercise)/2-step-1.md

0
content/Section 4 - Infrapunctural Imaginaries (exercise)/3-step-2.md → content/Section 5 - Infrapunctural Imaginaries (exercise)/3-step-2.md

0
content/Section 4 - Infrapunctural Imaginaries (exercise)/4-step-3.md → content/Section 5 - Infrapunctural Imaginaries (exercise)/4-step-3.md

0
content/Section 4 - Infrapunctural Imaginaries (exercise)/5-step-4.md → content/Section 5 - Infrapunctural Imaginaries (exercise)/5-step-4.md

0
content/Section 5 - Critical Interventions Through Bots (exercise)/1-introduction.md → content/Section 6 - Critical Interventions Through Bots (exercise)/1-introduction.md

0
content/Section 5 - Critical Interventions Through Bots (exercise)/2-example-bot.md → content/Section 6 - Critical Interventions Through Bots (exercise)/2-example-bot.md

0
content/Section 5 - Critical Interventions Through Bots (exercise)/3-situated-bot-code.md → content/Section 6 - Critical Interventions Through Bots (exercise)/3-situated-bot-code.md

213
content/Section 6 - Critical Interventions Through Bots (exercise)/mastodon-bot.ipynb

@ -0,0 +1,213 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Defaulting to user installation because normal site-packages is not writeable\n",
"Requirement already satisfied: Mastodon.py in /home/mb/.local/lib/python3.7/site-packages (1.5.1)\n",
"Requirement already satisfied: python-magic in /usr/local/lib/python3.7/dist-packages (from Mastodon.py) (0.4.15)\n",
"Requirement already satisfied: pytz in /home/mb/.local/lib/python3.7/site-packages (from Mastodon.py) (2020.1)\n",
"Requirement already satisfied: python-dateutil in /home/mb/.local/lib/python3.7/site-packages (from Mastodon.py) (2.8.1)\n",
"Requirement already satisfied: blurhash>=1.1.4 in /home/mb/.local/lib/python3.7/site-packages (from Mastodon.py) (1.1.4)\n",
"Requirement already satisfied: requests>=2.4.2 in /usr/lib/python3/dist-packages (from Mastodon.py) (2.21.0)\n",
"Requirement already satisfied: decorator>=4.0.0 in /usr/lib/python3/dist-packages (from Mastodon.py) (4.3.0)\n",
"Requirement already satisfied: six in /usr/lib/python3/dist-packages (from Mastodon.py) (1.12.0)\n"
]
}
],
"source": [
"import sys\n",
"!{sys.executable} -m pip install Mastodon.py"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from mastodon import Mastodon"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"instance = 'INSERTYOURINSTANCEURLHERE'\n",
"username = 'INSERTEMAILADDRESSHERE'\n",
"password = 'INSERTPASSWORDSHERE'"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('ijslOh1kdBmHnlycZUhP6bpB0wXayAXqZ_Qr4DMB09Y',\n",
" '-TZBLBW2XOrwOoCb2mbIWdxALRS8QiHIgIosrq2PqsE')"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Register your app! This only needs to be done once. Uncomment the code and substitute in your information.\n",
"\n",
"Mastodon.create_app(\n",
" 'bots-as-infrapuncture',\n",
" api_base_url = instance,\n",
" to_file = 'mastodon-bot.secret'\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'497bMScwM_Z1goP0Q_lNUsmbmbYByw3XXb-6KBxt-K8'"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Then login. This can be done every time, or use persisted.\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",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'id': 104964779309814302,\n",
" 'created_at': datetime.datetime(2020, 10, 2, 10, 43, 46, 538000, tzinfo=tzutc()),\n",
" 'in_reply_to_id': None,\n",
" 'in_reply_to_account_id': None,\n",
" 'sensitive': False,\n",
" 'spoiler_text': '',\n",
" 'visibility': 'public',\n",
" 'language': 'en',\n",
" 'uri': 'https://post.lurk.org/users/manetta/statuses/104964779309814302',\n",
" 'url': 'https://post.lurk.org/@manetta/104964779309814302',\n",
" 'replies_count': 0,\n",
" 'reblogs_count': 0,\n",
" 'favourites_count': 0,\n",
" 'local_only': False,\n",
" 'activity_pub_type': '',\n",
" 'favourited': False,\n",
" 'reblogged': False,\n",
" 'muted': False,\n",
" 'bookmarked': False,\n",
" 'pinned': False,\n",
" 'content': '<p>Testing to toot for the very very first time, excitingly using <a href=\"https://post.lurk.org/tags/mastodonpy\" class=\"mention hashtag\" rel=\"tag\">#<span>mastodonpy</span></a> !</p>',\n",
" 'reblog': None,\n",
" 'application': {'name': 'bagofwords', 'website': None},\n",
" 'account': {'id': 4791,\n",
" 'username': 'manetta',\n",
" 'acct': 'manetta',\n",
" 'display_name': 'manetta',\n",
" 'locked': False,\n",
" 'bot': False,\n",
" 'discoverable': False,\n",
" 'group': False,\n",
" 'created_at': datetime.datetime(2018, 5, 2, 18, 32, 50, 698000, tzinfo=tzutc()),\n",
" 'note': '<p>software studies networks publishing (<a href=\"https://post.lurk.org/tags/nobot\" class=\"mention hashtag\" rel=\"tag\">#<span>nobot</span></a>)</p>',\n",
" 'url': 'https://post.lurk.org/@manetta',\n",
" 'avatar': 'https://post.lurk.org/system/accounts/avatars/000/004/791/original/9ce0ebe273ada8aa.jpg?1584822874',\n",
" 'avatar_static': 'https://post.lurk.org/system/accounts/avatars/000/004/791/original/9ce0ebe273ada8aa.jpg?1584822874',\n",
" 'header': 'https://post.lurk.org/system/accounts/headers/000/004/791/original/5e99159ef049b6dc.png?1584823076',\n",
" 'header_static': 'https://post.lurk.org/system/accounts/headers/000/004/791/original/5e99159ef049b6dc.png?1584823076',\n",
" 'followers_count': 134,\n",
" 'following_count': 175,\n",
" 'statuses_count': 154,\n",
" 'last_status_at': datetime.datetime(2020, 10, 2, 0, 0),\n",
" 'emojis': [],\n",
" 'fields': []},\n",
" 'media_attachments': [],\n",
" 'mentions': [],\n",
" 'tags': [{'name': 'mastodonpy',\n",
" 'url': 'https://post.lurk.org/tags/mastodonpy'}],\n",
" 'emojis': [],\n",
" 'card': None,\n",
" 'poll': None}"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# To post, create an actual API instance.\n",
"\n",
"mastodon = Mastodon(\n",
" access_token = 'mastodon-bot-usercred.secret',\n",
" api_base_url = instance\n",
")\n",
"\n",
"mastodon.toot('Testing to toot for the very very first time, excitingly using #mastodonpy !')"
]
},
{
"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…
Cancel
Save