English 中文(简体)
在 Scryfall API 调用中选择颜色
原标题:selecting colors on a Scryfall API call
  • 时间:2024-05-17 00:52:02
  •  标签:
  • python
  • api

I m working on a simple project using python and PyQt6 that allows the user to select which colors they want for an MTG commander, and then using the Scryfall API, return a random commander that is in that color identity. I have read through the docs for both the API and regular scryfall, and have gotten to a point where I just don t understand what is happening anymore. Im using the https://api.scryfall.com/cards/random?q=is%3Acommander as a base link and adding extra on to it.

At first I thought I would just be able to do +c%3A{color} in a chain for all of the selected colors, but that just requires those colors to be on the card, and sometimes it gets a card with colors outside of the ones I had specified. Then I tried a chain of that with - instead of +, but that just breaks it. Eventually I wound up with this: -id:wg%20+id:br%20-id:c but it only gets black cards, not black and red cards. I also tried -id:wgu%20+id:br%20-id:c because I realized that I forgot blue, but then it just returns a 404.

医生中是否有一页我不认为能解释如何只搜寻特定颜色, 或我如何呼唤特定颜色身份, 而不在搜索中包括任何其他颜色身份?

问题回答

您可以在 < a href=> "https://scryfall.com/advanced" rel="not follow noreferrer" 中看到指挥官的颜色选项。 这里

Advanced Search

Commander Color enter image description here

https://scryfall.com/search?as=grid&order=name&q=commander:{color characters}+(game:paper)&page={number}
Color Character
White W
Blue U
Black B
Red R
Green G
Colorless C

实例实例实例实例

白色颜色指挥官卡

https://scryfall.com/search?as=grid&order=name&q=commander:W+(game:paper)&page=1

白色和红色颜色指挥官卡片

https://scryfall.com/search?as=grid&order=name&q=commander:WR+(game:paper)&page=1

结果成果成果成果成果成果成果成果成果成果成果

白色颜色指挥官卡

第1页卡片

特殊卡卡卡

获取 JSON 数据

// 20240516230035
// https://api.scryfall.com/cards/e882c9f9-bf30-46b6-bedc-379d2c80e5cb?format=json&pretty=true

{
  "object": "card",
  "id": "e882c9f9-bf30-46b6-bedc-379d2c80e5cb",
  "oracle_id": "629fe1be-272d-465f-b9b1-2ce177410f13",
  "multiverse_ids": [
    
  ],
  "mtgo_id": 91504,
  "arena_id": 77106,
  "tcgplayer_id": 243201,
  "cardmarket_id": 571299,
  "name": "+2 Mace",
  "lang": "en",
  "released_at": "2021-07-23",
  "uri": "https://api.scryfall.com/cards/e882c9f9-bf30-46b6-bedc-379d2c80e5cb",
  "scryfall_uri": "https://scryfall.com/card/afr/1/+2-mace?utm_source=api",
  "layout": "normal",
  "highres_image": true,
  "image_status": "highres_scan",
  "image_uris": {
    "small": "https://cards.scryfall.io/small/front/e/8/e882c9f9-bf30-46b6-bedc-379d2c80e5cb.jpg?1627701221",
    "normal": "https://cards.scryfall.io/normal/front/e/8/e882c9f9-bf30-46b6-bedc-379d2c80e5cb.jpg?1627701221",
    "large": "https://cards.scryfall.io/large/front/e/8/e882c9f9-bf30-46b6-bedc-379d2c80e5cb.jpg?1627701221",
    "png": "https://cards.scryfall.io/png/front/e/8/e882c9f9-bf30-46b6-bedc-379d2c80e5cb.png?1627701221",
    "art_crop": "https://cards.scryfall.io/art_crop/front/e/8/e882c9f9-bf30-46b6-bedc-379d2c80e5cb.jpg?1627701221",
    "border_crop": "https://cards.scryfall.io/border_crop/front/e/8/e882c9f9-bf30-46b6-bedc-379d2c80e5cb.jpg?1627701221"
  },
  "mana_cost": "{1}{W}",
  "cmc": 2.0,
  "type_line": "Artifact — Equipment",
  "oracle_text": "Equipped creature gets +2/+2.
Equip {3} ({3}: Attach to target creature you control. Equip only as a sorcery.)",
  "colors": [
    "W"
  ],
  "color_identity": [
    "W"
  ],
  "keywords": [
    "Equip"
  ],
  "legalities": {
    "standard": "not_legal",
    "future": "not_legal",
    "historic": "legal",
    "timeless": "legal",
    "gladiator": "legal",
    "pioneer": "legal",
    "explorer": "legal",
    "modern": "legal",
    "legacy": "legal",
    "pauper": "legal",
    "vintage": "legal",
    "penny": "not_legal",
    "commander": "legal",
    "oathbreaker": "legal",
    "standardbrawl": "not_legal",
    "brawl": "legal",
    "alchemy": "not_legal",
    "paupercommander": "legal",
    "duel": "legal",
    "oldschool": "not_legal",
    "premodern": "not_legal",
    "predh": "not_legal"
  },
  "games": [
    "arena",
    "paper",
    "mtgo"
  ],
  "reserved": false,
  "foil": true,
  "nonfoil": true,
  "finishes": [
    "nonfoil",
    "foil"
  ],
  "oversized": false,
  "promo": false,
  "reprint": false,
  "variation": false,
  "set_id": "e1ef87ba-ba92-4573-817f-543b996d2851",
  "set": "afr",
  "set_name": "Adventures in the Forgotten Realms",
  "set_type": "expansion",
  "set_uri": "https://api.scryfall.com/sets/e1ef87ba-ba92-4573-817f-543b996d2851",
  "set_search_uri": "https://api.scryfall.com/cards/search?order=set&q=e%3Aafr&unique=prints",
  "scryfall_set_uri": "https://scryfall.com/sets/afr?utm_source=api",
  "rulings_uri": "https://api.scryfall.com/cards/e882c9f9-bf30-46b6-bedc-379d2c80e5cb/rulings",
  "prints_search_uri": "https://api.scryfall.com/cards/search?order=released&q=oracleid%3A629fe1be-272d-465f-b9b1-2ce177410f13&unique=prints",
  "collector_number": "1",
  "digital": false,
  "rarity": "common",
  "flavor_text": "The weight of this magic weapon falls heavy on the wicked.",
  "card_back_id": "0aeebaf5-8c7d-4636-9e82-8c27447861f7",
  "artist": "Jarel Threat",
  "artist_ids": [
    "0fd89fbd-bd59-4ded-890e-731a8982f278"
  ],
  "illustration_id": "444cd469-4a05-4a58-a098-8af8a7b0f886",
  "border_color": "black",
  "frame": "2015",
  "full_art": false,
  "textless": false,
  "booster": true,
  "story_spotlight": false,
  "edhrec_rank": 14852,
  "preview": {
    "source": "Wizards of the Coast",
    "source_uri": "https://twitter.com/MTG_Arena/status/1410327287317270534",
    "previewed_at": "2021-07-01"
  },
  "prices": {
    "usd": "0.02",
    "usd_foil": "0.05",
    "usd_etched": null,
    "eur": "0.07",
    "eur_foil": "0.15",
    "tix": "0.03"
  },
  "related_uris": {
    "tcgplayer_infinite_articles": "https://tcgplayer.pxf.io/c/4931599/1830156/21018?subId1=api&trafcat=infinite&u=https%3A%2F%2Finfinite.tcgplayer.com%2Fsearch%3FcontentMode%3Darticle%26game%3Dmagic%26partner%3Dscryfall%26q%3D%252B2%2BMace",
    "tcgplayer_infinite_decks": "https://tcgplayer.pxf.io/c/4931599/1830156/21018?subId1=api&trafcat=infinite&u=https%3A%2F%2Finfinite.tcgplayer.com%2Fsearch%3FcontentMode%3Ddeck%26game%3Dmagic%26partner%3Dscryfall%26q%3D%252B2%2BMace",
    "edhrec": "https://edhrec.com/route/?cc=%2B2+Mace"
  },
  "purchase_uris": {
    "tcgplayer": "https://tcgplayer.pxf.io/c/4931599/1830156/21018?subId1=api&u=https%3A%2F%2Fwww.tcgplayer.com%2Fproduct%2F243201%3Fpage%3D1",
    "cardmarket": "https://www.cardmarket.com/en/Magic/Products/Singles/Adventures-in-the-Forgotten-Realms/2-Mace?referrer=scryfall&utm_campaign=card_prices&utm_medium=text&utm_source=scryfall",
    "cardhoarder": "https://www.cardhoarder.com/cards/91504?affiliate_id=scryfall&ref=card-profile&utm_campaign=affiliate&utm_medium=card&utm_source=scryfall"
  }
}

Convert

要使用 Python 将带有特殊字符的 URL 转换为编码格式,您可以使用 urlib.parse 模块。这里您如何做到这一点 :

import urllib.parse

original_url =  https://scryfall.com/search?as=grid&order=name&q=commander:WR+(game:paper)&page=1 
encoded_url = urllib.parse.quote(original_url, safe= :/?&amp;= )

print(encoded_url)

结果成果成果成果成果成果成果成果成果成果成果

https://scryfall.com/search?as=grid&order=name&q=commander:WR%2B%28game:paper%29&page=1




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签