magicthegathering / mtg-sdk-python Goto Github PK
View Code? Open in Web Editor NEWMagic: The Gathering SDK - Python
License: MIT License
Magic: The Gathering SDK - Python
License: MIT License
I noticed in #15 that we changed from __init__
to __new__
in classes like Card
and Set
. I was wondering what the advantage of this is? It seems like __init__
offers more utility over __new__
, since IDEs can suggest class members and, with Python 3.6 type annotations, could even infer their type (see below)
class Card:
def __init__(self, response_dict=None):
if response_dict is None:
response_dict = {}
self.name: str = response_dict.get('name')
self.cmc: int = response_dict.get('cmc')
# ...
Related to #23?
I haven't tested this with other models, but the Card model at least is throwing a 500 when using orderBy
.
This is my query:
Card.where(name=card_name).where(orderBy='name').all()
And this is the response I'm getting:
Traceback (most recent call last):
File "/home/user/.local/lib/python3.8/site-packages/mtgsdk/restclient.py", line 35, in get
response = json.loads(urlopen(req).read().decode("utf-8"))
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/usr/lib/python3.8/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error
My comment on this failed pull request details a single example, but it seems that server-side changes have resulted in tests failing.
The following tests produce the following failures (This information is also in my comment on the pull request):
test_find_returns_set (tests.test_set.TestSet) seems to fail because 'border' seems to have been removed from API responses
test_find_returns_card (tests.test_card.TestCard) seems to fail because of formatting changes, in the case of the pull request above, the addition of newlines before quote attributions in flavor text.
test_all_returns_changelogs (tests.test_changelog.TestChangelog) seems to fail because the server returns an empty changelog
test_generate_booster_returns_cards (tests.test_set.TestSet) seems to fail because the server does not consistently return 15-item boosters. In the pull request above it returned 13-item boosters. In the in-browser calls I made reviewing the test I was getting 14-item boosters.
test_where_filters_on_name (tests.test_set.TestSet) seems to fail because of the addition of the "promos" set (in this case PKTK) increasing the length of the returned list of sets.
test_all_returns_supertypes (tests.test_supertype.TestSupertype) seems to fail because 'Host' was added to the Types test instead of the Supertypes test.
test_all_returns_types (tests.test_type.TestType) seems to fail because 'Host' was added to the test instead of 'Hero', and B.F.M. has added 'Summon' and 'You'll'
As of this comment, there is no way to put a "not" statement in a query, which is a part of gatherer and honestly is an essential logical function.
I tried to filter a search based on the Card property reserved and I am seeing AttributeError: 'Card' object has no attribute 'reserved. Other properties like cmc, name and rarity work without any issues.
ive written a few programs handling the information generated by the apk, mostly just adding it all to a database for querying, how would one go about sorting by legality? the fields are available but the best way i can find is simply creating databases hard coded by set, is there a better way to do this?
From HOU, number 52
does anyone have ideas on parsing card text for synergies ive used the sdk to create a database in hopes i can find a player bot ai to train with all these cards but basically im looking for anything anyone has done with this apk in the way of development, the project i hope to one day complete is fairly feature heavy and i could use all the help i can get, tysm for this library its been incredibly helpful
Generating an Eldritch Moon booster with generate_booster occasionally results in a booster that contains one of the "Meld" cards; "Brisela, Voice of Nightmares", "Hanweir, the Writhing Township" and "Chittering Host" (I have only confirmed this with Brisela). These cards are entities created by the use of the Meld ability to combine two other cards; hence they do not physically exist as cards and the game rules prevent them from existing in virtual formats in any other context than gameplay.
It would be nice if the command were prevented (or able to be prevented) from including in generated boosters from more recent expansions cards that are considered by Gatherer to be part of that expansion but do not exist in the box/booster paradigm (such as Buy-A-Box promotional cards and cards included only in the introductory Planeswalker Decks) but boosters that include cards that do not exist at all at least is incorrect behaviour.
I can't filter a card on multiverse_id or id and filtering in combination with other traits like color and subtype. Am I misreading something or is this not implemented?
https://api.magicthegathering.io/v1/cards/mutliverse_id or id works,but when i do https://api.magicthegathering.io/v1/cards?id=id or ?multiverse_id= multiverse_id it just gives all cards as result.
python:
query.where(multiverse_id=mid) and query.where(id=id) is also ignored.
I need this because i want to link my own database to yours by storing which user owns which card and letting your database doing the rest.
Even if I use where(page=1).all(), I will get all results. When name is just a few characters (1-3), this will get absolutely out of hand and take forever. This might be wanted, but that all() ignores page keywords doesn't feel right...
It appears the query ignores color identity filters. For example:
Card.where(power = 15).where(color_identity = 'G').all()
Returns four cards, only one of which has green (the other three are None). This happens even when the other cards are an actual color and not just colorless. When mixing and matching queries, the color identity is always ignored.
I have been using the MTGSDK to fetch card data, particularly card text. However, I have encountered an issue with character encoding when fetching the card text using the MTGSDK. Specifically, certain characters like apostrophes (') are not being properly decoded in the fetched card text. This issue is consistently present across different sets and cards.
Steps to Reproduce:
Expected Behavior:
The fetched card text should properly decode characters like apostrophes (') and display them correctly.
Actual Behavior:
The fetched card text displays characters like apostrophes (') in a different encoding, leading to incorrect display.
Additional Information:
html.unescape()
and direct replacement of Unicode characters, but the issue persists.Example with Kayla's Command :
Kayla's Command,Rare,['W'],Sorcery,,"Choose two —
• Create a 2/2 colorless Construct artifact creature token.
• Put a +1/+1 counter on a creature you control. It gains double strike until end of turn.
• Search your library for a basic Plains card, reveal it, put it into your hand, then shuffle.
• You gain 2 life and scry 2.",,,BRO,The Brothers' War,"[{""date"": ""2022-10-14"", ""text"": ""None of the modes have any targets. Notably, this means that you don\u2019t have to choose a creature for the second mode until the spell resolves.""}]",Legal
You can show the problem at this line : Notably, this means that you don\u2019t have to choose a creature for the second mode until the spell resolves.
"don't" appear as "don\u2019t" and it is similar for so many special characters ( \u201c, \u201d, \u2014, etc...)
Thank you for the help.
Environment:
If you try a card query by set, and the name of the set contains an apostrophe urllib throws HTTP Error 500.
Card.where(set="Urza's Saga").all()
Using this to get the cards from brothers war -
cards = Card.where(set='BRO').all()
but coming back
cards = [ ]
Tried lowercase found BRO from your Set.name
Any help appreciated
I'm trying to use
Card.where(language='portuguese').all()
and i'm always geting empty list, i'v try as well:
Card.where(language='russian').where(name=3).all()
that are the same of
https://api.magicthegathering.io/v1/cards?language=russian&name=3
and i'm getting empty list too.
image_url
attribute is empty (returns None
) for WAR cards.
Hi! Any plans to port this to Javascript?
The following code returns 448 results where it should only return one.
from mtgsdk import Set
sets = Set.find('ktk').all()
len(sets)
I obtained this snippet from the code examples on the repo readme https://github.com/MagicTheGathering/mtg-sdk-python/blob/master/README.md
Hello, Im new to coding and I'm trying to experience with Magic SDK. Im doing this:
`from mtgsdk import Card
card = Card.find(386616)`
and if i print card, i get <mtgsdk.card.Card object at 0x7f63e6c42320>
how do i access tho that info?
I know it can be basic, i just need some help and i cant find any tutorials on this...
Thanks:)
Just installed the sdk and have run into an issue seaching using the multiverse_id
the code
card = Card.find(420830)
print(card)
returns the following string instead of information about the card
<mtgsdk.card.Card object at 0x0000023A3E5190A0>
Other commands like getting sets, types, etc. seem to work fine.
using python 3.9
Only english cards are filtered.
Even Card.where(language='Portuguese (Brazil)').where(set="RIX").all() just brings up english text as states in a closed issue.
cards = Card.where(language="German").where(set="RIX").all()
for card in cards:
print(card.name)
print(card.mana_cost)
print(card.supertypes)
print(card.subtypes)
print(card.types)
print(card.rarity)
print(card.text)
print(card.power)
print(card.toughness)
print(card.loyalty)
print(card.multiverse_id)
print(card.image_url)
print(card.set)
print(card.set_name)
print(card.rulings)
Example Output:
Angrath's Fury
{3}{B}{R}
None
None
['Sorcery']
Rare
Destroy target creature. Angrath's Fury deals 3 damage to target player. You may search your library and/or graveyard for a card named Angrath, Minotaur Pirate, reveal it, and put it into your hand. If you search your library this way, shuffle it.
None
None
None
441898
http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=441898&type=card
RIX
Rivals of Ixalan
[{'date': '2018-01-19', 'text': "You can't cast Angrath's Fury unless you choose both a target creature and a target player."}, {'date': '2018-01-19', 'text': "If either target becomes illegal after you cast Angrath's Fury but before it resolves, the other is still affected as appropriate and you'll search for Angrath. However, if both targets become illegal, the spell is countered and you won't search."}]
The API returns a colorIdentity
field which is not present in this SDK.
Whatever backend server this SDK is calling is returning HTTP 500 errors. Even the simple examples in the README fail.
Example:
from mtgsdk import Card
card = Card.find(386616)
throws:
File "/home/user/env/lib/python3.8/site-packages/mtgsdk/restclient.py", line 35, in get
response = json.loads(urlopen(req).read().decode("utf-8"))
File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/usr/lib/python3.8/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 500: Internal Server Error
This SDK is unusable if its dependencies are unreliable.
I just started using mtgsdk and I think it's great. I have two questions/concerns:
Some of the cards from the most recent set Kamigawa Neon Dynasty do not include image_url
's. Example: "The Wandering Emperor"
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.