summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdmin <admin@pleiades.link>2021-05-24 15:28:43 +0200
committerAdmin <admin@pleiades.link>2021-05-24 15:28:43 +0200
commit36f4466454b091597e3458980a9a70935fbc798c (patch)
tree2ff133f5dc11146c4eff8ec55e11213358507947
downloadMagicBot-master.tar.bz2
MagicBot-master.zip
-rwxr-xr-x.gitignore64
-rwxr-xr-xmagicbot.py23
2 files changed, 87 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100755
index 0000000..2636231
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,64 @@
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+*.png
+*.jpg
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+env/
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+*.egg-info/
+.installed.cfg
+*.egg
+
+# PyInstaller
+# Usually these files are written by a python script from a template
+# before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*,cover
+.hypothesis/
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+
+# Sphinx documentation
+docs/_build/
+
+# PyBuilder
+target/
+
+#Ipython Notebook
+.ipynb_checkpoints
diff --git a/magicbot.py b/magicbot.py
new file mode 100755
index 0000000..e9ea7f7
--- /dev/null
+++ b/magicbot.py
@@ -0,0 +1,23 @@
+import requests, json, os, random
+from mastodon import Mastodon
+
+# Mastodon token and domain
+mastodon = Mastodon(
+ access_token = "abcdef",
+ api_base_url = "https://domain.com/"
+)
+
+# Get a random card
+card = json.loads(requests.get("https://api.scryfall.com/cards/random").content)
+
+# Save the card image
+img = requests.get(card["image_uris"]["art_crop"]).content
+with open("card.png", "wb") as png:
+ png.write(img)
+
+# Post in Mastodon
+media = mastodon.media_post("card.png")
+mastodon.status_post(card["name"] + "\nArtwork by " + card["artist"], media_ids=media)
+
+# Delete the image, since it is no longer needed
+os.remove("card.png") \ No newline at end of file