<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Building Browsergames &#187; python</title>
	<atom:link href="http://buildingbrowsergames.com/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://buildingbrowsergames.com</link>
	<description>Ever wanted to build a browsergame?</description>
	<lastBuildDate>Mon, 29 Mar 2010 14:00:39 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Getting Started With MongoDB (Python)</title>
		<link>http://buildingbrowsergames.com/2010/02/08/getting-started-with-mongodb-python/</link>
		<comments>http://buildingbrowsergames.com/2010/02/08/getting-started-with-mongodb-python/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 14:00:23 +0000</pubDate>
		<dc:creator>Luke</dc:creator>
				<category><![CDATA[tutorial]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://buildingbrowsergames.com/2010/02/08/getting-started-with-mongodb-python/</guid>
		<description><![CDATA[Now that I&#8217;ve extolled the virtues of using a NoSQL database, it&#8217;s time to put my money where my mouth is and show you how to use one.
To start things off, we&#8217;re going to build a super-simple site using the excellent Bottle Python framework, which is built for building simple sites like this.
This tutorial assumes [...]]]></description>
			<content:encoded><![CDATA[<p>Now that I&#8217;ve <a href='http://buildingbrowsergames.com/2010/02/01/you-should-try-a-nosql-database-today/'>extolled the virtues</a> of using a NoSQL database, it&#8217;s time to put my money where my mouth is and show you how to <strong>use</strong> one.</p>
<p>To start things off, we&#8217;re going to build a super-simple site using the excellent <a href='http://bottle.paws.de/'>Bottle</a> Python framework, which is built for building simple sites like this.</p>
<p>This tutorial assumes that you already have a mongoDB instance up and running somewhere; if you haven&#8217;t done that already, take a look at <a href='http://www.mongodb.org/display/DOCS/Quickstart'>the quickstart on mongodb.org</a>.</p>
<p>First, <a href='http://bottle.paws.de/#download-install'>download and install Bottle</a> (it&#8217;s pretty easy). Once that&#8217;s done, we can start working on building our mini project.</p>
<p>Today we&#8217;re going to build a small &#8216;army manager&#8217; site; users will be able to add, edit, and delete members of their army, and everything we need to track for the user will be stored in our mongodb database.</p>
<p>To start off, we&#8217;ll just make the index page return a template:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> bottle, <span style="color: #dc143c;">random</span>
<span style="color: #ff7700;font-weight:bold;">from</span> bottle <span style="color: #ff7700;font-weight:bold;">import</span> route, jinja2_view <span style="color: #ff7700;font-weight:bold;">as</span> view, debug, run
&nbsp;
DATABASE_HOST = <span style="color: #483d8b;">'localhost'</span>
DATABASE_NAME = <span style="color: #483d8b;">'army'</span>
DATABASE_PORT = <span style="color: #ff4500;">27017</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> pymongo
<span style="color: #ff7700;font-weight:bold;">from</span> pymongo <span style="color: #ff7700;font-weight:bold;">import</span> Connection
connection = Connection<span style="color: black;">&#40;</span>DATABASE_HOST, DATABASE_PORT<span style="color: black;">&#41;</span>
db = connection<span style="color: black;">&#91;</span>DATABASE_NAME<span style="color: black;">&#93;</span>
users = db.<span style="color: black;">users</span>
&nbsp;
SOLDIER_NAMES = <span style="color: black;">&#91;</span><span style="color: #483d8b;">&quot;Moe&quot;</span>, <span style="color: #483d8b;">&quot;Curly&quot;</span>, <span style="color: #483d8b;">&quot;Janne&quot;</span>, <span style="color: #483d8b;">&quot;Peter&quot;</span>, <span style="color: #483d8b;">&quot;Paul&quot;</span>, <span style="color: #483d8b;">&quot;Kyle&quot;</span>, <span style="color: #483d8b;">&quot;Chris&quot;</span>, <span style="color: #483d8b;">&quot;Jude&quot;</span>, <span style="color: #483d8b;">&quot;Larry&quot;</span>, <span style="color: #483d8b;">&quot;Gus&quot;</span><span style="color: black;">&#93;</span>
&nbsp;
@route<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span>
@view<span style="color: black;">&#40;</span><span style="color: #483d8b;">'templates/index.html'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> index<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    current_user = get_current_user<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#123;</span>
        <span style="color: #483d8b;">'user'</span>: current_user,
    <span style="color: black;">&#125;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> get_current_user<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    ip = request.<span style="color: black;">environ</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'REMOTE_ADDR'</span><span style="color: black;">&#93;</span>
    current_user = users.<span style="color: black;">find_one</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'ip'</span>: ip<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> current_user:
        users.<span style="color: black;">insert</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">'ip'</span>: ip,
            <span style="color: #483d8b;">'army'</span>: <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>,
        <span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
        current_user = users.<span style="color: black;">find_one</span><span style="color: black;">&#40;</span><span style="color: black;">&#123;</span><span style="color: #483d8b;">'ip'</span>: ip<span style="color: black;">&#125;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> current_user    
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    debug<span style="color: black;">&#40;</span><span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
    run<span style="color: black;">&#40;</span>host=<span style="color: #483d8b;">'localhost'</span>, port=<span style="color: #ff4500;">8000</span>, reloader=<span style="color: #008000;">True</span><span style="color: black;">&#41;</span></pre></td></tr></table></div>

<p>You may have noticed that instead of using the default template renderer, I used the <a href='http://jinja.pocoo.org/2/'>Jinja</a> renderer instead &#8211; which templating engine you use is up to you, but I prefer Jinja.</p>
<p>There&#8217;s a lot going on here &#8211; and if you&#8217;re new to Python, this code probably looks pretty scary. However, it&#8217;s pretty simple once you get the hang of it &#8211; here&#8217;s what we&#8217;re doing:</p>
<ul>
<li>
<p>First, we&#8217;re importing all of the libraries we need, and setting up some of our configuration. This could be split out into another file easily enough &#8211; but for the sake of this tutorial, we&#8217;re going to keep everything self-contained for now. The libraries and helpers we&#8217;ve imported are <em>random</em>, <em>bottle.route</em>, <em>bottle.run</em>, <em>bottle.request</em>, <em>bottle.jinja2_view as view</em>, <em>bottle.response</em>, <em>bottle.debug</em>, <em>bottle.redirect</em>, <em>pymongo</em>, and <em>pymongo.Connection</em></p>
<p>Most of these come from the <a href='http://bottle.paws.de/'>Bottle</a> library, and are designed to help us get our app off the ground faster &#8211; we imported <em>random</em> to be able to choose names for our soldiers, and <em>pymongo</em> to help us work with our MongoDB database.</p>
</li>
<li>
<p>The next thing we did was create our index view &#8211; by saying that Bottle should route the url &#8216;/&#8217; to our &#8216;index&#8217; function. As you can see, all our index function does is retrieve the current user, and return it so that we can render it with our template &#8211; which we specified using our view() decorator.</p>
</li>
<li>
<p>The next thing we do is define a function to retrieve the current user, based on their IP address &#8211; this is our first dive into working with MongoDB. First, we retrieve the IP address of the computer that&#8217;s requesting the page, so that we can track the visitor&#8217;s information. Once we have that, we query our <em>users</em> database, to see if a user exists with our IP &#8211; if there is no user with the IP address we&#8217;re testing for, we create a new user with an empty army, and then return that one.</p>
</li>
<li>
<p>Finally, we have a little bit of utility code to let us test our Bottle app. This piece of code allows us to run our app by navigating to it in the terminal, and then just running &#8220;python app.py&#8221; &#8211; assuming your MongoDB instance is up and running and your dependencies are okay, you should be able to check out your app by navigating to <a href='http://localhost:8000/'>http://localhost:8000/</a>.</p>
</li>
</ul>
<p>If you navigate to your app right now though, you might notice that there&#8217;s a problem &#8211; we don&#8217;t have an index template! We&#8217;ll fix that by creating a template for our app, under templates/index.html:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">    <span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;</span>
<span style="color: #00bbdd;">       &quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;</span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">&quot;en&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Python MongoDB Tutorial<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/head<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        Your Army: {{ user.army }}
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">'/add-soldier/'</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">'post'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Add Soldier&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">'/remove-soldier/'</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">'post'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Remove Soldier&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;form</span> <span style="color: #000066;">action</span>=<span style="color: #ff0000;">'/rename-army/'</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">'post'</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;input</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;Rename All Soldiers&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/form<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/body<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/html<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>As you can see, we&#8217;re not shattering any barriers with this template &#8211; but it lets us test our app, so it will do for now. Navigate again to <a href='http://localhost:8000/'>http://localhost:8000/</a>, and you should see something like this:</p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/mongodb-python/first.png' alt="Your Army: [], Add Soldier button, Remove Soldier button, Rename All Soldiers button" /></p>
<p>With our template all set up, it&#8217;s time to write our views &#8211; starting with the view that lets us add soldiers:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@route<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/add-soldier/'</span>, method=<span style="color: #483d8b;">'POST'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> add_soldier<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    current_user = get_current_user<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    army = current_user.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'army'</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    army.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span>SOLDIER_NAMES<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    users.<span style="color: black;">update</span><span style="color: black;">&#40;</span>
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'ip'</span>: current_user<span style="color: black;">&#91;</span><span style="color: #483d8b;">'ip'</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span>,
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'$set'</span>: <span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">'army'</span>: army,
        <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span>
    <span style="color: black;">&#41;</span>
    redirect<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>For the most part, this view&#8217;s pretty simple &#8211; we want it to be at the url &#8216;/add-soldier/&#8217;, and only responding when users POST to it (by clicking on the &#8216;add soldier&#8217; button in our template). When a user clicks on the button and POSTs to this view, we retrieve their current army (making sure to default to [] if it doesn&#8217;t exist &#8211; this is important!), add a new soldier to it (by appending a random name from our SOLDIER_NAMES variable), and then update the user&#8217;s information in our MongoDB database. Finally, we redirect back to the frontpage so that the user can see their new army.</p>
<p>It&#8217;s important to keep in mind that when you&#8217;re using a schema-less database like MongoDB, you may not actually <strong>have</strong> the properties you&#8217;re expecting to, especially if you haven&#8217;t set them. With that in mind, always be sure to write your code in such a way that it will still work if a an object doesn&#8217;t have the property that you were expecting it to.</p>
<p>If you visit your testing page at <a href='http://localhost:8000/'>http://localhost:8000/</a> now and click the &#8216;Add Soldier&#8217; button, you should notice that your army has increased &#8211; there&#8217;s a new name there!</p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/mongodb-python/second.png' alt="Index page with a new army member" /></p>
<p>Now that we can <strong>add</strong> soldiers to our army, we need to be able to remove them as well. Let&#8217;s write a quick view to do that:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@route<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/remove-soldier/'</span>, method=<span style="color: #483d8b;">'POST'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> remove_soldier<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    current_user = get_current_user<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    army = current_user.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'army'</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>army<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">0</span>:   <span style="color: #808080; font-style: italic;"># make sure we don't pop from an empty list</span>
        army.<span style="color: black;">pop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    users.<span style="color: black;">update</span><span style="color: black;">&#40;</span>
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'ip'</span>: current_user<span style="color: black;">&#91;</span><span style="color: #483d8b;">'ip'</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span>,
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'$set'</span>: <span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">'army'</span>: army,
        <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span>
    <span style="color: black;">&#41;</span>
    redirect<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This view is just about the same as our <em>add_soldier</em> view from earlier, except that we&#8217;re removing soldiers instead of adding them before we write the user&#8217;s army into our database. We make sure they actually have soldiers in their &#8216;army&#8217; array, and then we remove one if they do before writing their army back to the database, and redirecting back to the front page.</p>
<p><img src='http://buildingbrowsergames.com/blog/wp-content/images/mongodb-python/first.png' alt="Index page, with an empty army" /></p>
<p>With that view written, there&#8217;s only one more to write &#8211; this one will live at &#8216;/rename-army/&#8217;, and update the names of all the soldiers in the user&#8217;s army:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">@route<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/rename-army/'</span>, method=<span style="color: #483d8b;">'POST'</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">def</span> rename_army<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    current_user = get_current_user<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    army = current_user.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'army'</span>, <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
    army = <span style="color: black;">&#91;</span><span style="color: #dc143c;">random</span>.<span style="color: black;">choice</span><span style="color: black;">&#40;</span>SOLDIER_NAMES<span style="color: black;">&#41;</span> <span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> army<span style="color: black;">&#93;</span>
    users.<span style="color: black;">update</span><span style="color: black;">&#40;</span>
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'ip'</span>: current_user<span style="color: black;">&#91;</span><span style="color: #483d8b;">'ip'</span><span style="color: black;">&#93;</span><span style="color: black;">&#125;</span>,
        <span style="color: black;">&#123;</span><span style="color: #483d8b;">'$set'</span>: <span style="color: black;">&#123;</span>
            <span style="color: #483d8b;">'army'</span>: army,
        <span style="color: black;">&#125;</span><span style="color: black;">&#125;</span>
    <span style="color: black;">&#41;</span>
    redirect<span style="color: black;">&#40;</span><span style="color: #483d8b;">'/'</span><span style="color: black;">&#41;</span></pre></div></div>

<p>As you can see, there isn&#8217;t much changed in this view either &#8211; we retrieve the user and their army, update the value of their &#8216;army&#8217; array, write it to the database, and then redirect them. We use a <a href='http://docs.python.org/tutorial/datastructures.html#list-comprehensions'>list comprehension</a> to update the name of every one of our army members, and that&#8217;s all that&#8217;s special here.</p>
<p>With that, we&#8217;re done! If you visit <a href="http://localhost:8000/">http://localhost:8000/</a>, you should be able to add soldiers, remove soldiers, and rename soldiers &#8211; with all the data being stored in your MongoDB database.</p>
<p>If you&#8217;re stuck, or can&#8217;t seem to get it going, you can download the code for this tutorial at <a href='http://buildingbrowsergames.com/blog/wp-content/downloads/mongodb-python-1.zip'>http://buildingbrowsergames.com/blog/wp-content/downloads/mongodb-python-1.zip</a>.</p>
<h2>Extra Homework</h2>
<ul>
<li>
<p>Our views involved writing a lot of boilerplate code, which can probably be refactored. Write a custom User object that handles storage and retrieval, along with making it easier to interact with the user&#8217;s army.</p>
</li>
</li>
<p>Modify the &#8216;army&#8217; array to store custom Soldier objects, which have a name <strong>and</strong> an attack value &#8211; when a user adds a soldier to their army, randomize both values (some of the work for this has been done for you &#8211; see the download above).</p>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://buildingbrowsergames.com/2010/02/08/getting-started-with-mongodb-python/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

