diff options
author | Admin <admin@pleiades.link> | 2021-05-24 15:21:48 +0200 |
---|---|---|
committer | Admin <admin@pleiades.link> | 2021-05-24 15:21:48 +0200 |
commit | aee6b509a6d743c08066376db115bd92fb37c553 (patch) | |
tree | a9ab4a87de0144c566c8ad00e169d3b4c709dc80 | |
download | DoggoBot-aee6b509a6d743c08066376db115bd92fb37c553.tar.bz2 DoggoBot-aee6b509a6d743c08066376db115bd92fb37c553.zip |
-rwxr-xr-x | .gitignore | 2 | ||||
-rwxr-xr-x | doggobot.py | 23 |
2 files changed, 25 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..03e0c28 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +avatar.png
+background.png
diff --git a/doggobot.py b/doggobot.py new file mode 100755 index 0000000..ff737cb --- /dev/null +++ b/doggobot.py @@ -0,0 +1,23 @@ +import requests, json, os
+from mastodon import Mastodon
+
+# Mastodon token and domain
+mastodon = Mastodon(
+ access_token = 'abcdef',
+ api_base_url = 'https://domain.com/'
+)
+
+# Get the image URL
+URL = json.loads(requests.get('https://dog.ceo/api/breeds/image/random').content)["message"]
+
+# Save image from URL
+img = requests.get(URL).content
+with open("dog.png", "wb") as png:
+ png.write(img)
+
+# Upload PNG file to Mastodon
+media = mastodon.media_post("dog.png")
+mastodon.status_post("#dogs #dogsofmastodon #mastodogs", media_ids=media)
+
+# Delete the image, since it is no longer needed
+os.remove("dog.png")
\ No newline at end of file |