poppu-mtg / StackIt

Python script generating a column-shaped TCG decklist based on cropped captions of each card's art.
MIT License
14 stars 6 forks source link

database for scans does not use 3 letter code for sets prior to Shadowmoor #16

Closed poppu-mtg closed 7 years ago

poppu-mtg commented 7 years ago
  1. magiccards.info only uses a 2 letter code for most sets prior to Shadowmoor;
  2. Timeshifted, Expeditions and Masterpieces also have different letter codes;
  3. mtgvault.com simply does not carry Expeditions, and only half of the Inventions...
poppu-mtg commented 7 years ago

It has been pointed out to me that there is another website that generates a database for magic cards: https://mtgjson.com/sets.html which uses JSON language. So far, no luck in opening it via python though...

silasary commented 7 years ago

Ok, so as far as mtgjson goes. I have code that can handle it over in PennyDreadfulMtg/Penny-Dreadful-Tools, but that feels like overkill for what we're doing. What I'd recommend doing is using magicthegathering.io (an API that allows you to query individual cards from it)

silasary commented 7 years ago

I'd recommend something like

import json, requests
blob = json.loads(requests.get('https://api.magicthegathering.io/v1/cards?name={cardname}'.format(cardname=cardname)))
cost = blob[0].manaCost

(Note that this is an eyeballed pseudocode - It might not compile or work as intended)

silasary commented 7 years ago

Also of note: They do have a python library (https://github.com/MagicTheGathering/mtg-sdk-python/), which would be easier than using requests and json parsing. But it's only compatible with python3, so we're stuck with doing it the hard way unless we port StackIt to 3

poppu-mtg commented 7 years ago

The lines you wrote are a great start, I'll work on that for a new CMC search method.

As for the scan search and the different code names, I think a dictionary would suffice, from official set name to magiccards.info set name.

poppu-mtg commented 7 years ago

Using python 2.7, I cannot get the request on https to work apparently:

File "newparser-default3.py", line 13, in blob = json.loads(requests.get('https://api.magicthegathering.io/v1/cards?name={cardname}'.format(cardname=cardname))) File "/Library/Python/2.7/site-packages/requests/api.py", line 70, in get return request('get', url, params=params, kwargs) File "/Library/Python/2.7/site-packages/requests/api.py", line 56, in request return session.request(method=method, url=url, kwargs) File "/Library/Python/2.7/site-packages/requests/sessions.py", line 488, in request resp = self.send(prep, send_kwargs) File "/Library/Python/2.7/site-packages/requests/sessions.py", line 609, in send r = adapter.send(request, kwargs) File "/Library/Python/2.7/site-packages/requests/adapters.py", line 497, in send raise SSLError(e, request=request) requests.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)

silasary commented 7 years ago

So, I got the SSL issues working for me, but now I'm having problems with Unicode characters in the ForeignNames key.

silasary commented 7 years ago

Ok, so:

silasary commented 7 years ago

Note that switching to mtgjson itself, rather than magicthegathering.io would be better for responsiveness and caching, but that's an issue for another day, and would require additional effort, and a longer initial wait time, as it downloads the entire 6.29MB blob.