def comic_week(request, week_of): public_key = os.environ['MAPI_PUBLIC_KEY'] private_key = os.environ['MAPI_PRIVATE_KEY'] cache = DjangoCache() marvel_api = marvelous.api(public_key, private_key, cache=cache) comics = marvel_api.comics({ 'format': "comic", 'formatType': "comic", 'noVariants': True, 'dateRange': "{day},{day}".format(day=week_of), 'limit': 100 }) response = { 'week_of': week_of, 'comics': [], } for comic in comics: response['comics'].append({ 'id': comic.id, 'title': comic.title, 'on_sale': comic.dates.on_sale, 'series_id': comic.series.id, 'images': comic.images, }) return JsonResponse(response)
def test_no_get(self): m = marvelous.api(public_key=self.pub, private_key=self.priv, cache=NoGet()) with self.assertRaises(marvelous.exceptions.CacheError): m.series(466)
def setUp(self): pub = os.getenv('PUBLIC_KEY', 'pub') priv = os.getenv('PRIVATE_KEY', 'priv') self.m = marvelous.api( public_key=pub, private_key=priv, cache=marvelous.SqliteCache("tests/testing_mock.sqlite"))
def talker(dummy_pubkey, dummy_privkey): """marvelous api fixture.""" return api( public_key=dummy_pubkey, private_key=dummy_privkey, cache=sqlite_cache.SqliteCache("tests/testing_mock.sqlite"), )
def api(self): public_key = os.environ['MAPI_PUBLIC_KEY'] private_key = os.environ['MAPI_PRIVATE_KEY'] cache = DjangoCache() marvel_api = marvelous.api(public_key, private_key, cache=cache) series = marvel_api.series(self.series_id) response = { 'title': series.title, 'comics': [], 'series_id': self.series_id, } series_args = { 'format': "comic", 'formatType': "comic", 'noVariants': True, 'limit': 100, } for comic in series.comics(series_args): response['comics'].append({ 'id': comic.id, 'title': comic.title, 'read': (comic.id in self.read), 'skipped': (comic.id in self.skipped), 'on_sale': comic.dates.on_sale, 'series_id': comic.series.id, 'images': comic.images, }) return response
def setUp(self): pub = os.getenv("PUBLIC_KEY", "pub") priv = os.getenv("PRIVATE_KEY", "priv") self.m = api( public_key=pub, private_key=priv, cache=SqliteCache("tests/testing_mock.sqlite"), )
def get_api(): """ Load the Marvel API wrapper :return: :class:`marvelous.sessions.Session` """ public_key = os.environ['MAPI_PUBLIC_KEY'] private_key = os.environ['MAPI_PRIVATE_KEY'] marvel_api = marvelous.api(public_key, private_key) return marvel_api
def test_no_store(dummy_pubkey, dummy_privkey): m = api(public_key=dummy_pubkey, private_key=dummy_privkey, cache=NoStore()) with requests_mock.Mocker() as r: r.get( "http://gateway.marvel.com:80/v1/public/series/466", text='{"response_code": 200}', ) with pytest.raises(exceptions.CacheError): m.series(466)
def test_no_store(self): m = marvelous.api(public_key=self.pub, private_key=self.priv, cache=NoStore()) with requests_mock.Mocker() as r: r.get('http://gateway.marvel.com:80/v1/public/series/466', text='{"response_code": 200}') with self.assertRaises(marvelous.exceptions.CacheError): m.series(466)
def test_api(self): with self.assertRaises(AuthenticationError): marvelous.api() with self.assertRaises(AuthenticationError): marvelous.api(private_key="Something") with self.assertRaises(AuthenticationError): marvelous.api(public_key="Something") m = None try: m = marvelous.api(public_key="Something", private_key="Else") except Exception as exc: self.fail("marvelous.api() raised {} unexpectedly!".format(exc)) self.assertEqual(m.__class__.__name__, marvelous.session.Session.__name__)
def test_api(): with pytest.raises(exceptions.AuthenticationError): api() with pytest.raises(exceptions.AuthenticationError): api(private_key="Something") with pytest.raises(exceptions.AuthenticationError): api(public_key="Something") m = None try: m = api(public_key="Something", private_key="Else") except Exception as exc: print("mokkari.api() raised {} unexpectedly!".format(exc)) assert m.__class__.__name__, session.Session.__name__
def test_sql_store(dummy_pubkey, dummy_privkey): fresh_cache = sqlite_cache.SqliteCache(":memory:") test_cache = sqlite_cache.SqliteCache("tests/testing_mock.sqlite") m = api(public_key=dummy_pubkey, private_key=dummy_privkey, cache=fresh_cache) url = "http://gateway.marvel.com:80/v1/public/series/466" assert fresh_cache.get(url) is None try: with requests_mock.Mocker() as r: r.get(url, text=json.dumps(test_cache.get(url))) m.series(466) assert fresh_cache.get(url) is not None except TypeError: print( "This test will fail after cache db deleted.\n" "It should pass if you now re-run the test suite " "without deleting the database." ) assert False
def test_sql_store(self): fresh_cache = marvelous.SqliteCache(":memory:") test_cache = marvelous.SqliteCache("tests/testing_mock.sqlite") m = marvelous.api(public_key=self.pub, private_key=self.priv, cache=fresh_cache) url = 'http://gateway.marvel.com:80/v1/public/series/466' self.assertTrue(fresh_cache.get(url) is None) try: with requests_mock.Mocker() as r: r.get(url, text=json.dumps(test_cache.get(url))) m.series(466) self.assertTrue(fresh_cache.get(url) is not None) except TypeError: print( 'This test will fail after cache db deleted.\n' 'It should pass if you now re-run the test suite without deleting the database.' ) assert (False)
def setUp(self): pub = os.getenv('PUBLIC_KEY', 'pub') priv = os.getenv('PRIVATE_KEY', 'priv') self.m = marvelous.api( public_key=pub, private_key=priv, cache={ 'name': 'testing_mock', 'expire_after': None})
def test_no_get(dummy_pubkey, dummy_privkey): m = api(public_key=dummy_pubkey, private_key=dummy_privkey, cache=NoGet()) with pytest.raises(exceptions.CacheError): m.series(466)
import os import marvelous # Your own config file to keep your private key local and secret from config import public_key, private_key # All the series IDs of comics I'm not interested in reading # I pull these out of the resulting pulls.txt file, then rerun this script IGNORE = set([ 19709, 20256, 19379, 19062, 19486, 19242, 19371, 19210, 20930, 21328, 20834, 18826, 20933, 20365, 20928, 21129, 20786, 21402, 21018, 14803, 21285, 12212, 21434, 21020, 19512, 19367, 21607, 21131 ]) # Authenticate with Marvel, with keys I got from http://developer.marvel.com/ m = marvelous.api(public_key, private_key) # Get all comics from this week, sorted alphabetically by title pulls = sorted(m.comics({ 'format': "comic", 'formatType': "comic", 'noVariants': True, 'dateDescriptor': "thisWeek", 'limit': 100}), key=lambda comic: comic.title) # Grab the sale date of any of the comics for the current week week = pulls[0].dates.on_sale.strftime('%m/%d') print("New comics for the week of {}:".format(week)) # Check each comic that came out this week
import sys import os from collections import defaultdict import marvelous from config import public_key, private_key m = marvelous.api( public_key, private_key, cache=marvelous.SqliteCache("ultimate_reader.db")) series = sys.argv[1:] def ordinal(n): if 10 <= n % 100 < 20: return str(n) + 'th' else: return str(n) + {1: 'st', 2: 'nd', 3: 'rd'}.get(n % 10, "th") def all_comics_for_series(id): series = m.series(id) LIMIT = 100 offset = 0 total = None comics = [] while total is None or len(comics) < total: response = series.comics({ 'format': 'comic', 'formatType': 'comic',
import marvelous public_key = 'ba0613cb148841f5091cb0075b5076d2' private_key = '140a52c97a8ef92f028d89a543e83d711f9e80a0' m = marvelous.api( public_key, private_key, ) def accessData(name): if (name == "characters"): characters = m.call(['characters'], {'limit': 10}) return characters['data']['results'] elif (name == "comics"): comics = m.call(['comics'], {'limit': 10}) return comics['data']['results'] elif (name == "creators"): creators = m.call(['creators'], {'limit': 10}) return creators['data']['results'] elif (name == "events"): events = m.call(['events'], {'limit': 10}) return events['data']['results'] elif (name == "series"): series = m.call(['series'], {'limit': 10}) return series['data']['results'] elif (name == "stories"): stories = m.call(['stories'], {'limit': 10}) return stories['data']['results']