mirror of
https://github.com/cfultz/MTGRandomScryfallBot.git
synced 2024-11-21 15:50:03 +01:00
Initial Commit
This commit is contained in:
commit
6124c79413
9
LICENSE
Normal file
9
LICENSE
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
Copyright 2024 Caleb Fultz aka cfultz
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
45
MTGMastodonBot.py
Normal file
45
MTGMastodonBot.py
Normal file
@ -0,0 +1,45 @@
|
||||
# Import required methods
|
||||
from requests import get
|
||||
from json import loads
|
||||
from shutil import copyfileobj
|
||||
from mastodon import Mastodon
|
||||
|
||||
mastodon = Mastodon(
|
||||
access_token = 'token.secret',
|
||||
api_base_url = 'https://cfultz.com'
|
||||
)
|
||||
|
||||
|
||||
# Load the card data from Scryfall
|
||||
card = loads(get(f"https://api.scryfall.com/cards/random?format=image.json").text)
|
||||
|
||||
# Get the image URL
|
||||
img_url = card['image_uris']['large']
|
||||
|
||||
# Get card title
|
||||
mtg_title = card['name']
|
||||
|
||||
# Artist name
|
||||
mtg_artist = card['artist']
|
||||
|
||||
# Get flavor text
|
||||
flavor = card['oracle_text']
|
||||
|
||||
# Get card set
|
||||
mtg_set = card['set_name']
|
||||
|
||||
# Save the image
|
||||
with open('image.jpg', 'wb') as out_file:
|
||||
copyfileobj(get(img_url, stream = True).raw, out_file)
|
||||
|
||||
# Set the Mastodon post information
|
||||
media = mastodon.media_post("image.jpg","size:'372x520'", description="Card Name: " + mtg_title + "\n" + "Set: " + mtg_set + "\n" + "Description: " + flavor + "\n" + "Artist: " + mtg_artist)
|
||||
|
||||
# Print Text
|
||||
print (mtg_title)
|
||||
print (mtg_set)
|
||||
print (img_url)
|
||||
print (flavor)
|
||||
|
||||
|
||||
mastodon.status_post("#magicthegathering" + " " + "#mtg" + " " + "#" + mtg_title.replace(" ", "") + " " + "#" + mtg_set.replace(" ","") + " " + "#" + mtg_artist.replace(" ",""),media_ids=media)
|
20
README.md
Normal file
20
README.md
Normal file
@ -0,0 +1,20 @@
|
||||
# MTG Random Scryfall Bot
|
||||
|
||||
The is a Mastodon bot that pulls a random Magic: The Gathering card from Scryfall and toots it correctly to a Mastodon instance with full description and hashtags.
|
||||
|
||||
![Screenshot](screenshot.jpg)
|
||||
|
||||
## Requirments
|
||||
- Mastodon.py (pip install Mastodon)
|
||||
|
||||
## How to Use
|
||||
|
||||
- Clone repository
|
||||
- Create file called ``token.secret`` and place Mastodon Access Token inside
|
||||
- Change ``api_url_endpoint`` in ``MTGMastodonBot.py`` to your instance URL
|
||||
- Save and run the bot. eg: ``python MTGMastodonBot.py``
|
||||
|
||||
## TODO
|
||||
|
||||
- Add ability to have the bot respond to specific card search queries from users and reply
|
||||
- ???
|
BIN
screenshot.jpg.jpeg
Normal file
BIN
screenshot.jpg.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 158 KiB |
Loading…
Reference in New Issue
Block a user