Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
I’m building a tool to check Magic: The Gathering deck legality in custom formats and want to update my formats with the same frequency as the Penny Dreadful format. Penny Dreadful updates when a n...
#2: Post edited
I’m building a tool to check Magic: The Gathering deck legality in custom formats. I want to update the formats automatically whenever a new Standard-legal set releases.Is there a programmatic way to fetch the release date of the latest Standard set, ideally via an API or a reliable data source?Some sample code of what I'd like to do:```pythonimport requestsimport jsonimport osLAST_UPDATED_FILE = "last_updated.json"SCRYFALL_SETS_API = "https://api.scryfall.com/sets"def fetch_sets_data():"""Fetch data from Scryfall sets API."""response = requests.get(SCRYFALL_SETS_API)response.raise_for_status()return response.json()def load_saved_updated_at(file_path=LAST_UPDATED_FILE):"""Load previously saved updated_at from file."""if os.path.exists(file_path):with open(file_path, "r") as f:data = json.load(f)return data.get("updated_at")return Nonedef save_updated_at(updated_at, file_path=LAST_UPDATED_FILE):"""Save updated_at to file."""with open(file_path, "w") as f:json.dump({"updated_at": updated_at}, f)def check_for_update(latest_updated_at, saved_updated_at):"""Return True if update detected, else False. Print 'updating' if True."""if saved_updated_at is None or latest_updated_at > saved_updated_at:save_updated_at(latest_updated_at)return Truereturn Falsedef main():data = fetch_sets_data()latest_updated_at = data.get("updated_at") # hypothetical fieldsaved_updated_at = load_saved_updated_at()if check_for_update(latest_updated_at, saved_updated_at):print(Updating)if __name__ == "__main__":main()```
- I’m building a tool to check Magic: The Gathering deck legality in custom formats and want to update my formats with the same frequency as the Penny Dreadful format. Penny Dreadful updates when a new Standard-legal set is released but typically ignores smaller supplemental sets.
- Is there a programmatic way to fetch the release date of the latest Standard set, ideally via an API or a reliable data source?
#1: Initial revision
How to automatically get the release date of the latest Magic: The Gathering Standard set?
I’m building a tool to check Magic: The Gathering deck legality in custom formats. I want to update the formats automatically whenever a new Standard-legal set releases.
Is there a programmatic way to fetch the release date of the latest Standard set, ideally via an API or a reliable data source?
Some sample code of what I'd like to do:
```python
import requests
import json
import os
LAST_UPDATED_FILE = "last_updated.json"
SCRYFALL_SETS_API = "https://api.scryfall.com/sets"
def fetch_sets_data():
"""Fetch data from Scryfall sets API."""
response = requests.get(SCRYFALL_SETS_API)
response.raise_for_status()
return response.json()
def load_saved_updated_at(file_path=LAST_UPDATED_FILE):
"""Load previously saved updated_at from file."""
if os.path.exists(file_path):
with open(file_path, "r") as f:
data = json.load(f)
return data.get("updated_at")
return None
def save_updated_at(updated_at, file_path=LAST_UPDATED_FILE):
"""Save updated_at to file."""
with open(file_path, "w") as f:
json.dump({"updated_at": updated_at}, f)
def check_for_update(latest_updated_at, saved_updated_at):
"""Return True if update detected, else False. Print 'updating' if True."""
if saved_updated_at is None or latest_updated_at > saved_updated_at:
save_updated_at(latest_updated_at)
return True
return False
def main():
data = fetch_sets_data()
latest_updated_at = data.get("updated_at") # hypothetical field
saved_updated_at = load_saved_updated_at()
if check_for_update(latest_updated_at, saved_updated_at):
print(Updating)
if __name__ == "__main__":
main()
```
