Skip to content

Commit 649249a

Browse files
committed
Update readme with basic doc
1 parent c7adc2d commit 649249a

File tree

3 files changed

+310
-6
lines changed

3 files changed

+310
-6
lines changed

README.rst

Lines changed: 172 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Python Preparer
55

66
----
77

8-
Fork of restless.prepares.
8+
Simple way to build a new dict based on fields declaration.
99

1010

1111
How to install
@@ -16,13 +16,180 @@ How to install
1616
pip install preparer
1717
1818
19-
Documentation
20-
--------------
19+
How to use
20+
----------
21+
22+
.. code:: python
23+
24+
from preparer import FieldsPreparer, SubPreparer, CollectionSubPreparer
25+
26+
xfiles_game = {
27+
'description': 'As an extension of one of the most long-running...',
28+
'game_id': 1,
29+
'genres': [
30+
{
31+
'genre_category': 'Basic Genres',
32+
'genre_category_id': 1,
33+
'genre_id': 2,
34+
'genre_name': 'Adventure'
35+
},
36+
{
37+
'genre_category': 'Perspective',
38+
'genre_category_id': 2,
39+
'genre_id': 7,
40+
'genre_name': '1st-person'
41+
},
42+
{
43+
'genre_category': 'Narrative Theme/Topic',
44+
'genre_category_id': 8,
45+
'genre_id': 55,
46+
'genre_name': 'Detective / Mystery'
47+
},
48+
{
49+
'genre_category': 'Setting',
50+
'genre_category_id': 10,
51+
'genre_id': 8,
52+
'genre_name': 'Sci-Fi / Futuristic'
53+
},
54+
{
55+
'genre_category': 'Other Attributes',
56+
'genre_category_id': 6,
57+
'genre_id': 82,
58+
'genre_name': 'Licensed Title'
59+
}
60+
],
61+
'moby_score': 3.8,
62+
'moby_url': 'http://www.mobygames.com/game/x-files-game',
63+
'num_votes': 53,
64+
'official_url': None,
65+
'platforms': [
66+
{
67+
'first_release_date': '1998',
68+
'platform_id': 3,
69+
'platform_name': 'Windows'
70+
},
71+
{
72+
'first_release_date': '1998-06',
73+
'platform_id': 74,
74+
'platform_name': 'Macintosh'
75+
},
76+
{
77+
'first_release_date': '1999',
78+
'platform_id': 6,
79+
'platform_name': 'PlayStation'
80+
}
81+
],
82+
'sample_cover': {
83+
'height': 927,
84+
'image': 'http://www.mobygames.com/images/covers/l/3-the-x-files-game...',
85+
'platforms': [
86+
'Windows'
87+
],
88+
'thumbnail_image': 'http://www.mobygames.com/images/covers/s/3-the-x-files...',
89+
'width': 800
90+
},
91+
'sample_screenshots': [
92+
{
93+
'caption': 'Mulder and Special Agent Willmore',
94+
'height': 480,
95+
'image': 'http://www.mobygames.com/images/shots/l/86087-the-x-files...',
96+
'thumbnail_image': 'http://www.mobygames.com/images/shots/s/86087-the...',
97+
'width': 640
98+
},
99+
{
100+
'caption': 'Title screen (from intro)',
101+
'height': 480,
102+
'image': 'http://www.mobygames.com/images/shots/l/313897-the-x-files-game...',
103+
'thumbnail_image': 'http://www.mobygames.com/images/shots/s/313897-the-x...',
104+
'width': 640
105+
},
106+
{
107+
'caption': 'Gillian Anderson (from intro)',
108+
'height': 480,
109+
'image': 'http://www.mobygames.com/images/shots/l/313919-the-x-files-game...',
110+
'thumbnail_image': 'http://www.mobygames.com/images/shots/s/313919-the-x...',
111+
'width': 640
112+
},
113+
{
114+
'caption': 'David Duchovny (from intro)',
115+
'height': 480,
116+
'image': 'http://www.mobygames.com/images/shots/l/313908-the-x-files-game-windows...',
117+
'thumbnail_image': 'http://www.mobygames.com/images/shots/s/313908-the-x-files...',
118+
'width': 640
119+
}
120+
],
121+
'title': 'The X-Files Game'
122+
}
123+
124+
preparer = FieldsPreparer(fields={
125+
'id': 'game_id',
126+
'title': 'title',
127+
'description': 'description'
128+
})
129+
130+
cover_preparer = FieldsPreparer(fields={
131+
'image': 'image',
132+
'thumbnail': 'thumbnail_image'
133+
})
134+
preparer_with_cover = FieldsPreparer(fields={
135+
'id': 'game_id',
136+
'title': 'title',
137+
'description': 'description',
138+
'cover': SubPreparer('sample_cover', cover_preparer)
139+
})
140+
141+
screenshot_preparer = FieldsPreparer(fields={
142+
'caption': 'caption',
143+
'image': 'image',
144+
'thumbnail': 'thumbnail_image'
145+
})
146+
preparer_with_cover_and_screenshots = FieldsPreparer(fields={
147+
'id': 'game_id',
148+
'title': 'title',
149+
'description': 'description',
150+
'cover': SubPreparer('sample_cover', cover_preparer),
151+
'screenshots': CollectionSubPreparer('sample_screenshots', screenshot_preparer)
152+
})
153+
154+
155+
.. code:: python
156+
157+
>>> import pprint
158+
>>> pp = pprint.PrettyPrinter(indent=4)
159+
>>> pp.pprint(preparer.prepare(xfiles_game))
160+
{ 'description': 'As an extension of one of the most long-running...',
161+
'id': 1,
162+
'title': 'The X-Files Game'}
163+
>>> pp.pprint(preparer_with_cover.prepare(xfiles_game))
164+
{ 'cover': { 'image': 'http://www.mobygames.com/images/covers/l/3-the-x-files-game...',
165+
'thumbnail': 'http://www.mobygames.com/images/covers/s/3-the-x-files...'},
166+
'description': 'As an extension of one of the most long-running...',
167+
'id': 1,
168+
'title': 'The X-Files Game'}
169+
>>> pp.pprint(preparer_with_cover_and_screenshots.prepare(xfiles_game))
170+
{ 'cover': { 'image': 'http://www.mobygames.com/images/covers/l/3-the-x-files-game...',
171+
'thumbnail': 'http://www.mobygames.com/images/covers/s/3-the-x-files...'},
172+
'description': 'As an extension of one of the most long-running...',
173+
'id': 1,
174+
'screenshots': [ { 'caption': 'Mulder and Special Agent Willmore',
175+
'image': 'http://www.mobygames.com/images/shots/l/86087-the-x-files...',
176+
'thumbnail': 'http://www.mobygames.com/images/shots/s/86087-the...'},
177+
{ 'caption': 'Title screen (from intro)',
178+
'image': 'http://www.mobygames.com/images/shots/l/313897-the-x-files-game...',
179+
'thumbnail': 'http://www.mobygames.com/images/shots/s/313897-the-x...'},
180+
{ 'caption': 'Gillian Anderson (from intro)',
181+
'image': 'http://www.mobygames.com/images/shots/l/313919-the-x-files-game...',
182+
'thumbnail': 'http://www.mobygames.com/images/shots/s/313919-the-x...'},
183+
{ 'caption': 'David Duchovny (from intro)',
184+
'image': 'http://www.mobygames.com/images/shots/l/313908-the-x-files-game-windows...',
185+
'thumbnail': 'http://www.mobygames.com/images/shots/s/313908-the-x-files...'}],
186+
'title': 'The X-Files Game'}
21187
22-
Check out documentation at `Read the Docs`_ website.
23188
189+
Credits
190+
-------
24191

25-
.. _`Read the Docs`: http://python-preparer.readthedocs.org/
192+
This is a fork of excellent https://github.com/toastdriven/restless/blob/master/restless/preparers.py
26193

27194

28195
.. |TravisCI Build Status| image:: https://travis-ci.org/allisson/python-preparer.svg?branch=master

examples/quickstart.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import pprint
2+
3+
from preparer import FieldsPreparer, SubPreparer, CollectionSubPreparer
4+
5+
6+
pp = pprint.PrettyPrinter(indent=4)
7+
xfiles_game = {
8+
'description': 'As an extension of one of the most long-running...',
9+
'game_id': 1,
10+
'genres': [
11+
{
12+
'genre_category': 'Basic Genres',
13+
'genre_category_id': 1,
14+
'genre_id': 2,
15+
'genre_name': 'Adventure'
16+
},
17+
{
18+
'genre_category': 'Perspective',
19+
'genre_category_id': 2,
20+
'genre_id': 7,
21+
'genre_name': '1st-person'
22+
},
23+
{
24+
'genre_category': 'Narrative Theme/Topic',
25+
'genre_category_id': 8,
26+
'genre_id': 55,
27+
'genre_name': 'Detective / Mystery'
28+
},
29+
{
30+
'genre_category': 'Setting',
31+
'genre_category_id': 10,
32+
'genre_id': 8,
33+
'genre_name': 'Sci-Fi / Futuristic'
34+
},
35+
{
36+
'genre_category': 'Other Attributes',
37+
'genre_category_id': 6,
38+
'genre_id': 82,
39+
'genre_name': 'Licensed Title'
40+
}
41+
],
42+
'moby_score': 3.8,
43+
'moby_url': 'http://www.mobygames.com/game/x-files-game',
44+
'num_votes': 53,
45+
'official_url': None,
46+
'platforms': [
47+
{
48+
'first_release_date': '1998',
49+
'platform_id': 3,
50+
'platform_name': 'Windows'
51+
},
52+
{
53+
'first_release_date': '1998-06',
54+
'platform_id': 74,
55+
'platform_name': 'Macintosh'
56+
},
57+
{
58+
'first_release_date': '1999',
59+
'platform_id': 6,
60+
'platform_name': 'PlayStation'
61+
}
62+
],
63+
'sample_cover': {
64+
'height': 927,
65+
'image': 'http://www.mobygames.com/images/covers/l/3-the-x-files-game...',
66+
'platforms': [
67+
'Windows'
68+
],
69+
'thumbnail_image': 'http://www.mobygames.com/images/covers/s/3-the-x-files...',
70+
'width': 800
71+
},
72+
'sample_screenshots': [
73+
{
74+
'caption': 'Mulder and Special Agent Willmore',
75+
'height': 480,
76+
'image': 'http://www.mobygames.com/images/shots/l/86087-the-x-files...',
77+
'thumbnail_image': 'http://www.mobygames.com/images/shots/s/86087-the...',
78+
'width': 640
79+
},
80+
{
81+
'caption': 'Title screen (from intro)',
82+
'height': 480,
83+
'image': 'http://www.mobygames.com/images/shots/l/313897-the-x-files-game...',
84+
'thumbnail_image': 'http://www.mobygames.com/images/shots/s/313897-the-x...',
85+
'width': 640
86+
},
87+
{
88+
'caption': 'Gillian Anderson (from intro)',
89+
'height': 480,
90+
'image': 'http://www.mobygames.com/images/shots/l/313919-the-x-files-game...',
91+
'thumbnail_image': 'http://www.mobygames.com/images/shots/s/313919-the-x...',
92+
'width': 640
93+
},
94+
{
95+
'caption': 'David Duchovny (from intro)',
96+
'height': 480,
97+
'image': 'http://www.mobygames.com/images/shots/l/313908-the-x-files-game-windows...',
98+
'thumbnail_image': 'http://www.mobygames.com/images/shots/s/313908-the-x-files...',
99+
'width': 640
100+
}
101+
],
102+
'title': 'The X-Files Game'
103+
}
104+
105+
preparer = FieldsPreparer(fields={
106+
'id': 'game_id',
107+
'title': 'title',
108+
'description': 'description'
109+
})
110+
111+
cover_preparer = FieldsPreparer(fields={
112+
'image': 'image',
113+
'thumbnail': 'thumbnail_image'
114+
})
115+
preparer_with_cover = FieldsPreparer(fields={
116+
'id': 'game_id',
117+
'title': 'title',
118+
'description': 'description',
119+
'cover': SubPreparer('sample_cover', cover_preparer)
120+
})
121+
122+
screenshot_preparer = FieldsPreparer(fields={
123+
'caption': 'caption',
124+
'image': 'image',
125+
'thumbnail': 'thumbnail_image'
126+
})
127+
preparer_with_cover_and_screenshot = FieldsPreparer(fields={
128+
'id': 'game_id',
129+
'title': 'title',
130+
'description': 'description',
131+
'cover': SubPreparer('sample_cover', cover_preparer),
132+
'screenshots': CollectionSubPreparer('sample_screenshots', screenshot_preparer)
133+
})
134+
135+
pp.pprint(preparer.prepare(xfiles_game))
136+
pp.pprint(preparer_with_cover.prepare(xfiles_game))
137+
pp.pprint(preparer_with_cover_and_screenshot.prepare(xfiles_game))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def run(self):
5050
setup(
5151
name='preparer',
5252
version=version,
53-
description='Fork of restless.prepares',
53+
description='Simple way to build a new dict based on fields declaration',
5454
long_description=long_description,
5555
url='https://github.com/allisson/python-preparer',
5656
author='Allisson Azevedo',

0 commit comments

Comments
 (0)