From 9f1d1bcf7d6a735e5b9b0fa8ee9def6b8a1a833f Mon Sep 17 00:00:00 2001 From: NandaScott Date: Wed, 2 Oct 2019 21:15:26 -0400 Subject: [PATCH 1/5] Added preview key --- docs/scrython.cards/ArenaId.md | 16 ++++++++++++++++ docs/scrython.cards/Collector.md | 16 ++++++++++++++++ docs/scrython.cards/Id.md | 16 ++++++++++++++++ docs/scrython.cards/Mtgo.md | 16 ++++++++++++++++ docs/scrython.cards/Multiverse.md | 16 ++++++++++++++++ docs/scrython.cards/Named.md | 16 ++++++++++++++++ docs/scrython.cards/Random.md | 16 ++++++++++++++++ scrython/cards/cards_object.py | 21 ++++++++++++++++++++- unittests/TestCards.py | 5 +++++ 9 files changed, 137 insertions(+), 1 deletion(-) diff --git a/docs/scrython.cards/ArenaId.md b/docs/scrython.cards/ArenaId.md index 2c4dfd8..6a26da5 100644 --- a/docs/scrython.cards/ArenaId.md +++ b/docs/scrython.cards/ArenaId.md @@ -432,6 +432,22 @@ The power of the creature, if applicable Returns: string +``` +--- +### `preview()` + +``` +Preview information for this card, if any. + You may pass the name of a valid key to return the value of that key. + Such as a source_uri. + + Args: + key (string): A key for specific information about the preview. + + Returns: + dict: If provided no key, the entire dict is returned. + string: If provided a key, the value of that key is returned. + ``` --- ### `prices()` diff --git a/docs/scrython.cards/Collector.md b/docs/scrython.cards/Collector.md index a52a210..a216f95 100644 --- a/docs/scrython.cards/Collector.md +++ b/docs/scrython.cards/Collector.md @@ -429,6 +429,22 @@ The power of the creature, if applicable Returns: string +``` +--- +### `preview()` + +``` +Preview information for this card, if any. + You may pass the name of a valid key to return the value of that key. + Such as a source_uri. + + Args: + key (string): A key for specific information about the preview. + + Returns: + dict: If provided no key, the entire dict is returned. + string: If provided a key, the value of that key is returned. + ``` --- ### `prices()` diff --git a/docs/scrython.cards/Id.md b/docs/scrython.cards/Id.md index 25c7d79..064c3a3 100644 --- a/docs/scrython.cards/Id.md +++ b/docs/scrython.cards/Id.md @@ -432,6 +432,22 @@ The power of the creature, if applicable Returns: string +``` +--- +### `preview()` + +``` +Preview information for this card, if any. + You may pass the name of a valid key to return the value of that key. + Such as a source_uri. + + Args: + key (string): A key for specific information about the preview. + + Returns: + dict: If provided no key, the entire dict is returned. + string: If provided a key, the value of that key is returned. + ``` --- ### `prices()` diff --git a/docs/scrython.cards/Mtgo.md b/docs/scrython.cards/Mtgo.md index 9751c98..75a8db1 100644 --- a/docs/scrython.cards/Mtgo.md +++ b/docs/scrython.cards/Mtgo.md @@ -432,6 +432,22 @@ The power of the creature, if applicable Returns: string +``` +--- +### `preview()` + +``` +Preview information for this card, if any. + You may pass the name of a valid key to return the value of that key. + Such as a source_uri. + + Args: + key (string): A key for specific information about the preview. + + Returns: + dict: If provided no key, the entire dict is returned. + string: If provided a key, the value of that key is returned. + ``` --- ### `prices()` diff --git a/docs/scrython.cards/Multiverse.md b/docs/scrython.cards/Multiverse.md index b8de0b3..5c82f6f 100644 --- a/docs/scrython.cards/Multiverse.md +++ b/docs/scrython.cards/Multiverse.md @@ -432,6 +432,22 @@ The power of the creature, if applicable Returns: string +``` +--- +### `preview()` + +``` +Preview information for this card, if any. + You may pass the name of a valid key to return the value of that key. + Such as a source_uri. + + Args: + key (string): A key for specific information about the preview. + + Returns: + dict: If provided no key, the entire dict is returned. + string: If provided a key, the value of that key is returned. + ``` --- ### `prices()` diff --git a/docs/scrython.cards/Named.md b/docs/scrython.cards/Named.md index 76558ec..6872c17 100644 --- a/docs/scrython.cards/Named.md +++ b/docs/scrython.cards/Named.md @@ -434,6 +434,22 @@ The power of the creature, if applicable Returns: string +``` +--- +### `preview()` + +``` +Preview information for this card, if any. + You may pass the name of a valid key to return the value of that key. + Such as a source_uri. + + Args: + key (string): A key for specific information about the preview. + + Returns: + dict: If provided no key, the entire dict is returned. + string: If provided a key, the value of that key is returned. + ``` --- ### `prices()` diff --git a/docs/scrython.cards/Random.md b/docs/scrython.cards/Random.md index a0ab860..23038d4 100644 --- a/docs/scrython.cards/Random.md +++ b/docs/scrython.cards/Random.md @@ -430,6 +430,22 @@ The power of the creature, if applicable Returns: string +``` +--- +### `preview()` + +``` +Preview information for this card, if any. + You may pass the name of a valid key to return the value of that key. + Such as a source_uri. + + Args: + key (string): A key for specific information about the preview. + + Returns: + dict: If provided no key, the entire dict is returned. + string: If provided a key, the value of that key is returned. + ``` --- ### `prices()` diff --git a/scrython/cards/cards_object.py b/scrython/cards/cards_object.py index 96a9022..d89b8c3 100644 --- a/scrython/cards/cards_object.py +++ b/scrython/cards/cards_object.py @@ -728,4 +728,23 @@ class CardsObject(FoundationObject): """ super(CardsObject, self)._checkForKey('released_at') - return self.scryfallJson['released_at'] \ No newline at end of file + return self.scryfallJson['released_at'] + + def preview(self, key=None): + """Preview information for this card, if any. + You may pass the name of a valid key to return the value of that key. + Such as a source_uri. + + Args: + key (string): A key for specific information about the preview. + + Returns: + dict: If provided no key, the entire dict is returned. + string: If provided a key, the value of that key is returned. + """ + super(CardsObject, self)._checkForKey('preview') + + if key in self.scryfallJson['preview']: + return self.scryfallJson['preview'][key] + + return self.scryfallJson['preview'] \ No newline at end of file diff --git a/unittests/TestCards.py b/unittests/TestCards.py index 1db8b7a..3dca286 100644 --- a/unittests/TestCards.py +++ b/unittests/TestCards.py @@ -17,6 +17,7 @@ transform = Id(id='aae6fb12-b252-453b-bca7-1ea2a0d6c8dc'); time.sleep(0.1) vanguard = Id(id='87c1234b-3834-4bba-bef2-05707bb1e8e2'); time.sleep(0.1) alt_lang_card = Collector(code='ths', collector_number='75', lang='ja'); time.sleep(0.1) planeswalker = Id(id='4c565076-5db2-47ea-8ee0-4a4fd7bb353d'); time.sleep(0.1) +preview_check = Id(id='fb6b12e7-bb93-4eb6-bad1-b256a6ccff4e'); time.sleep(0.1) autocomplete = Autocomplete(q='Thal'); time.sleep(0.1) @@ -207,6 +208,10 @@ class TestCardObjects(unittest.TestCase): def test_oversized(self): self.assertIsInstance(non_online_card.oversized(), bool) + def test_preview(self): + self.assertIsInstance(preview_check.preview(), dict) + self.assertIsInstance(preview_check.preview('source'), str) + class TestAutocomplete(unittest.TestCase): def test_object(self): From 10ea4bfb616390b5dbee89214da89576b6e6cf22 Mon Sep 17 00:00:00 2001 From: Katelyn Gigante Date: Tue, 9 Jun 2020 13:33:25 +1000 Subject: [PATCH 2/5] Github Action to automatically run the unit tests --- .github/workflows/tests.yml | 26 +++++++++++++++++++ unittests/__init__.py | 0 unittests/{TestBulk.py => test_bulk.py} | 0 unittests/{TestCards.py => test_cards.py} | 0 unittests/{TestCatalog.py => test_catalog.py} | 0 unittests/{TestRulings.py => test_rulings.py} | 0 unittests/{TestSets.py => test_sets.py} | 0 .../{TestSymbology.py => test_symbology.py} | 0 8 files changed, 26 insertions(+) create mode 100644 .github/workflows/tests.yml create mode 100644 unittests/__init__.py rename unittests/{TestBulk.py => test_bulk.py} (100%) rename unittests/{TestCards.py => test_cards.py} (100%) rename unittests/{TestCatalog.py => test_catalog.py} (100%) rename unittests/{TestRulings.py => test_rulings.py} (100%) rename unittests/{TestSets.py => test_sets.py} (100%) rename unittests/{TestSymbology.py => test_symbology.py} (100%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..113c822 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,26 @@ +name: Python Tests + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.5, 3.6, 3.7, 3.8] + + steps: + - uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Test with pytest + run: | + pytest diff --git a/unittests/__init__.py b/unittests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/unittests/TestBulk.py b/unittests/test_bulk.py similarity index 100% rename from unittests/TestBulk.py rename to unittests/test_bulk.py diff --git a/unittests/TestCards.py b/unittests/test_cards.py similarity index 100% rename from unittests/TestCards.py rename to unittests/test_cards.py diff --git a/unittests/TestCatalog.py b/unittests/test_catalog.py similarity index 100% rename from unittests/TestCatalog.py rename to unittests/test_catalog.py diff --git a/unittests/TestRulings.py b/unittests/test_rulings.py similarity index 100% rename from unittests/TestRulings.py rename to unittests/test_rulings.py diff --git a/unittests/TestSets.py b/unittests/test_sets.py similarity index 100% rename from unittests/TestSets.py rename to unittests/test_sets.py diff --git a/unittests/TestSymbology.py b/unittests/test_symbology.py similarity index 100% rename from unittests/TestSymbology.py rename to unittests/test_symbology.py From b625f0a5fd463024b10ead23dcf37c4e8521657c Mon Sep 17 00:00:00 2001 From: Katelyn Gigante Date: Tue, 9 Jun 2020 13:48:40 +1000 Subject: [PATCH 3/5] Bulk data was renamed --- scrython/bulk_data/bulk_data.py | 9 +++++++-- unittests/test_bulk.py | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scrython/bulk_data/bulk_data.py b/scrython/bulk_data/bulk_data.py index ec61638..d3c4478 100644 --- a/scrython/bulk_data/bulk_data.py +++ b/scrython/bulk_data/bulk_data.py @@ -5,6 +5,7 @@ import asyncio import aiohttp import urllib.parse from threading import Thread +import warnings class BulkData(FoundationObject): """ @@ -164,6 +165,10 @@ class BulkData(FoundationObject): return self.scryfallJson['data'][num]['compressed_size'] def bulk_permalink_uri(self, num): + warnings.warn("This method has been renamed to bulk_uri as per https://scryfall.com/blog/updates-to-bulk-data-and-cards-deprecation-notice-217", DeprecationWarning) + return self.bulk_uri(num) + + def bulk_uri(self, num): """The URL that hosts the bulk file Args: @@ -172,9 +177,9 @@ class BulkData(FoundationObject): Returns: string: A URI to download the compressed data """ - super(BulkData, self)._checkForTupleKey('data', num, 'permalink_uri') + super(BulkData, self)._checkForTupleKey('data', num, 'uri') - return self.scryfallJson['data'][num]['permalink_uri'] + return self.scryfallJson['data'][num]['uri'] def bulk_content_type(self, num): """The MIME type of the file diff --git a/unittests/test_bulk.py b/unittests/test_bulk.py index c1a10c8..f6bcdfa 100644 --- a/unittests/test_bulk.py +++ b/unittests/test_bulk.py @@ -41,8 +41,8 @@ class TestBulk(unittest.TestCase): self.assertIsInstance(bulk.bulk_compressed_size(0), int) self.assertIsInstance(bulk.bulk_compressed_size(0, True), str) - def test_bulk_permalink_uri(self): - self.assertIsInstance(bulk.bulk_permalink_uri(0), str) + def test_bulk_uri(self): + self.assertIsInstance(bulk.bulk_uri(0), str) def test_bulk_content_type(self): self.assertIsInstance(bulk.bulk_content_type(0), str) From 1b889ce42020989d5d1d63e36d61ed929ed5d2d2 Mon Sep 17 00:00:00 2001 From: NandaScott Date: Tue, 9 Jun 2020 09:59:18 -0400 Subject: [PATCH 4/5] Updated docs and changelog --- Changelog.md | 8 ++++++++ docs/scrython.bulk_data/BulkData.md | 22 ++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/Changelog.md b/Changelog.md index 4de8267..4f965b9 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,13 @@ # Changelog +## 1.8.0 + +Changes +- CI tests have now been added +- Bulk data uri method has been updated, with a deprecation warning for the previous method. +- `preview()` method has been added to all card methods. +- Tests have been updated to reflect new changes. + ## 1.7.1 New stuff - Added image uri compatability for adventure cards diff --git a/docs/scrython.bulk_data/BulkData.md b/docs/scrython.bulk_data/BulkData.md index c8f7c04..c249ca3 100644 --- a/docs/scrython.bulk_data/BulkData.md +++ b/docs/scrython.bulk_data/BulkData.md @@ -123,14 +123,7 @@ Returns the type of object the specified index is ### `bulk_permalink_uri()` ``` -The URL that hosts the bulk file - - Args: - num (int): The index of the object in the `data` key - - Returns: - string: A URI to download the compressed data - +None ``` --- ### `bulk_type()` @@ -157,6 +150,19 @@ The time the item was last updated Returns: string: Timestamp +``` +--- +### `bulk_uri()` + +``` +The URL that hosts the bulk file + + Args: + num (int): The index of the object in the `data` key + + Returns: + string: A URI to download the compressed data + ``` --- ### `data()` From b28992861e2895a6d8f0a7b55bb5b4a6b6be9398 Mon Sep 17 00:00:00 2001 From: NandaScott Date: Tue, 9 Jun 2020 10:03:26 -0400 Subject: [PATCH 5/5] Incremented version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 13408e8..c94c107 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup( name='scrython', packages=['scrython', 'scrython.cards', 'scrython.rulings', 'scrython.catalog', 'scrython.sets', 'scrython.symbology', 'scrython.bulk_data'], - version='1.7.1', + version='1.8.0', description='A wrapper for using the Scryfall API.', long_description='https://github.com/NandaScott/Scrython/blob/master/README.md', url='https://github.com/NandaScott/Scrython',