@@ -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
1111How 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
0 commit comments