summaryrefslogtreecommitdiffstats
path: root/doggobot.py
diff options
context:
space:
mode:
Diffstat (limited to 'doggobot.py')
-rwxr-xr-xdoggobot.py23
1 files changed, 23 insertions, 0 deletions
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