Skip to main content

TravisCI Build Status Coverage Status Requirements Status


Simple way to build a new dict based on fields declaration.

How to install

pip install preparer

How to use

from preparer import FieldsPreparer, SubPreparer, CollectionSubPreparer

xfiles_game = {
    'description': 'As an extension of one of the most long-running...',
    'game_id': 1,
    'genres': [
        {
            'genre_category': 'Basic Genres',
            'genre_category_id': 1,
            'genre_id': 2,
            'genre_name': 'Adventure'
        },
        {
            'genre_category': 'Perspective',
            'genre_category_id': 2,
            'genre_id': 7,
            'genre_name': '1st-person'
        },
        {
            'genre_category': 'Narrative Theme/Topic',
            'genre_category_id': 8,
            'genre_id': 55,
            'genre_name': 'Detective / Mystery'
        },
        {
            'genre_category': 'Setting',
            'genre_category_id': 10,
            'genre_id': 8,
            'genre_name': 'Sci-Fi / Futuristic'
        },
        {
            'genre_category': 'Other Attributes',
            'genre_category_id': 6,
            'genre_id': 82,
            'genre_name': 'Licensed Title'
        }
    ],
    'moby_score': 3.8,
    'moby_url': 'http://www.mobygames.com/game/x-files-game',
    'num_votes': 53,
    'official_url': None,
    'platforms': [
        {
            'first_release_date': '1998',
            'platform_id': 3,
            'platform_name': 'Windows'
        },
        {
            'first_release_date': '1998-06',
            'platform_id': 74,
            'platform_name': 'Macintosh'
        },
        {
            'first_release_date': '1999',
            'platform_id': 6,
            'platform_name': 'PlayStation'
        }
    ],
    'sample_cover': {
        'height': 927,
        'image': 'http://www.mobygames.com/images/covers/l/3-the-x-files-game...',
        'platforms': [
            'Windows'
        ],
        'thumbnail_image': 'http://www.mobygames.com/images/covers/s/3-the-x-files...',
        'width': 800
    },
    'sample_screenshots': [
        {
            'caption': 'Mulder and Special Agent Willmore',
            'height': 480,
            'image': 'http://www.mobygames.com/images/shots/l/86087-the-x-files...',
            'thumbnail_image': 'http://www.mobygames.com/images/shots/s/86087-the...',
            'width': 640
        },
        {
            'caption': 'Title screen (from intro)',
            'height': 480,
            'image': 'http://www.mobygames.com/images/shots/l/313897-the-x-files-game...',
            'thumbnail_image': 'http://www.mobygames.com/images/shots/s/313897-the-x...',
            'width': 640
        },
        {
            'caption': 'Gillian Anderson (from intro)',
            'height': 480,
            'image': 'http://www.mobygames.com/images/shots/l/313919-the-x-files-game...',
            'thumbnail_image': 'http://www.mobygames.com/images/shots/s/313919-the-x...',
            'width': 640
        },
        {
            'caption': 'David Duchovny (from intro)',
            'height': 480,
            'image': 'http://www.mobygames.com/images/shots/l/313908-the-x-files-game-windows...',
            'thumbnail_image': 'http://www.mobygames.com/images/shots/s/313908-the-x-files...',
            'width': 640
        }
    ],
    'title': 'The X-Files Game'
}

preparer = FieldsPreparer(fields={
    'id': 'game_id',
    'title': 'title',
    'description': 'description'
})

cover_preparer = FieldsPreparer(fields={
    'image': 'image',
    'thumbnail': 'thumbnail_image'
})
preparer_with_cover = FieldsPreparer(fields={
    'id': 'game_id',
    'title': 'title',
    'description': 'description',
    'cover': SubPreparer('sample_cover', cover_preparer)
})

screenshot_preparer = FieldsPreparer(fields={
    'caption': 'caption',
    'image': 'image',
    'thumbnail': 'thumbnail_image'
})
preparer_with_cover_and_screenshots = FieldsPreparer(fields={
    'id': 'game_id',
    'title': 'title',
    'description': 'description',
    'cover': SubPreparer('sample_cover', cover_preparer),
    'screenshots': CollectionSubPreparer('sample_screenshots', screenshot_preparer)
})
>>> import pprint
>>> pp = pprint.PrettyPrinter(indent=4)
>>> pp.pprint(preparer.prepare(xfiles_game))
{   'description': 'As an extension of one of the most long-running...',
    'id': 1,
    'title': 'The X-Files Game'}
>>> pp.pprint(preparer_with_cover.prepare(xfiles_game))
{   'cover': {   'image': 'http://www.mobygames.com/images/covers/l/3-the-x-files-game...',
                 'thumbnail': 'http://www.mobygames.com/images/covers/s/3-the-x-files...'},
    'description': 'As an extension of one of the most long-running...',
    'id': 1,
    'title': 'The X-Files Game'}
>>> pp.pprint(preparer_with_cover_and_screenshots.prepare(xfiles_game))
{   'cover': {   'image': 'http://www.mobygames.com/images/covers/l/3-the-x-files-game...',
                 'thumbnail': 'http://www.mobygames.com/images/covers/s/3-the-x-files...'},
    'description': 'As an extension of one of the most long-running...',
    'id': 1,
    'screenshots': [   {   'caption': 'Mulder and Special Agent Willmore',
                           'image': 'http://www.mobygames.com/images/shots/l/86087-the-x-files...',
                           'thumbnail': 'http://www.mobygames.com/images/shots/s/86087-the...'},
                       {   'caption': 'Title screen (from intro)',
                           'image': 'http://www.mobygames.com/images/shots/l/313897-the-x-files-game...',
                           'thumbnail': 'http://www.mobygames.com/images/shots/s/313897-the-x...'},
                       {   'caption': 'Gillian Anderson (from intro)',
                           'image': 'http://www.mobygames.com/images/shots/l/313919-the-x-files-game...',
                           'thumbnail': 'http://www.mobygames.com/images/shots/s/313919-the-x...'},
                       {   'caption': 'David Duchovny (from intro)',
                           'image': 'http://www.mobygames.com/images/shots/l/313908-the-x-files-game-windows...',
                           'thumbnail': 'http://www.mobygames.com/images/shots/s/313908-the-x-files...'}],
    'title': 'The X-Files Game'}

Check https://github.com/allisson/python-preparer/tree/master/examples for more code examples.

Credits

This is a fork of excellent https://github.com/toastdriven/restless/blob/master/restless/preparers.py

Release files for preparer 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for preparer 0.1.0
File Size Uploaded
preparer-0.1.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for preparer 0.1.0
File Interpreter ABI Platform
preparer-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.9 kB

Release files / preparer-0.1.0.tar.gz

Download URL preparer-0.1.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5202ab842a3e272625c17ad72d6d1541e2a9ddf77ab15b2dbc248a58e37d63e0
BLAKE2b-256 checksum
How to use checksums
1f5567e716793956976725aa9ea2459d78370aaaf8f8961fd1abba29bb5e754e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / preparer-0.1.0-py3-none-any.whl

Download URL preparer-0.1.0-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
267c986635fa2680c879d7b2d24a38734e9de78a834bf0753ce3461aef197de0
BLAKE2b-256 checksum
How to use checksums
50da6e2de926df761a81883dfdc301f5df37d40c73494b6c79403e818666bc59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page