<?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>simon.net.nz &#187; python</title> <atom:link href="http://simon.net.nz/articles/category/python/feed/" rel="self" type="application/rss+xml" /><link>http://simon.net.nz</link> <description>Dr. Simon J. Greenhill&#039;s website</description> <lastBuildDate>Tue, 29 Nov 2011 09:49:47 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>r8spermute</title><link>http://simon.net.nz/articles/r8spermute/</link> <comments>http://simon.net.nz/articles/r8spermute/#comments</comments> <pubDate>Wed, 14 Oct 2009 02:09:35 +0000</pubDate> <dc:creator>Simon</dc:creator> <category><![CDATA[code]]></category> <category><![CDATA[python]]></category> <guid
isPermaLink="false">http://simon.net.nz/?p=106</guid> <description><![CDATA[This is a small program to assess how robust divergence times are based on the calibrations given to the program r8s.]]></description> <content:encoded><![CDATA[<h2 class="center">r8spermute - Runs all permutations of r8s constraints.</h2><h3 class="center">© Simon J. Greenhill, 2009</h3><p>This is a small program to assess how robust divergence times are based on the calibrations given to the program r8s.</p><p>The program r8s by Mike Sanderson (<a
href="http://loco.biosci.arizona.edu/r8s/">http://loco.biosci.arizona.edu/r8s/</a>) [1, 2] performs a number of phylogenetic dating methods on a set of phylogenetic trees. In essence, you plug in a number of calibration points from known historical evidence and the program r8s takes your estimated trees, and "smoothes" the rates of change observed on those trees, using the calibrations to convert the branches into time.</p><p>However, it is often useful to explore the effect that certain calibration has on the various date estimates. For example, in the paper [3], I wanted to estimate the age at which a large language family originated. We had about 10 different calibration points based on historical evidence. Some of these calibrations were, however, more controversial than the others. So, I wrote this program to take a tree (or set of trees) and analyse them under all the combinations of these calibrations. This allowed us to assess the relative effects on the date estimates of the different calibrations.</p><p>If you find this program useful, please cite reference [3].</p><p><a
href="/contact/">Contact me if you have any problems.</a></p><h2>Download:</h2><p>You can download r8spermute from <a
href="http://bitbucket.org/simongreenhill/r8spermute/">the bitbucket repository</a> here: <a
href="http://bitbucket.org/simongreenhill/r8spermute/downloads/">download r8spermute</a></p><h2>Usage:</h2><p>You will need two things: 1) A set of trees, 2) A r8s command block. Examples of both of these are provided in the "examples" directory.</p><p>Your r8s block file will look something like this:</p><div
class="igBar"><span
id="lcode-1"><a
href="#" onclick="javascript:showPlainTxt('code-1'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-1"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">begin rates;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">blformat lengths=persite nsites=<span
style="color:#800000;color:#800000;">1000</span> ultrametric=no round=yes;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">collapse;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mrca node1 Daisy Fiona;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">constrain taxon=node1 min_age=<span
style="color:#800000;color:#800000;">1</span>.<span
style="color:#800000;color:#800000;">8</span> max_age=<span
style="color:#800000;color:#800000;">2</span>.<span
style="color:#800000;color:#800000;">5</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">mrca node2 Robert Tamara;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">constrain taxon=node2 min_age=<span
style="color:#800000;color:#800000;">1</span>.<span
style="color:#800000;color:#800000;">1</span> max_age=<span
style="color:#800000;color:#800000;">1</span>.<span
style="color:#800000;color:#800000;">3</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">unfixage taxon=Simon;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">constrain taxon=Simon min_age=<span
style="color:#800000;color:#800000;">0</span>.<span
style="color:#800000;color:#800000;">7</span> max_age=<span
style="color:#800000;color:#800000;">1</span>.<span
style="color:#800000;color:#800000;">2</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set num_restarts=<span
style="color:#800000;color:#800000;">5</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">set smoothing=<span
style="color:#800000;color:#800000;">10</span>;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">divtime method=pl algorithm=tn;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">showage shownamed = yes;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">profile taxon=node1 parameter=age;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">profile taxon=node2 parameter=age;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">describe plot=chrono_description;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">end;</div></li></ol></div></div></div><p></p><p>... thus, we have 3 calibrations - node1, node2, and a constraint on the terminal taxon "Simon".</p><p>We can then run r8spermute like this:</p><div
class="igBar"><span
id="lcode-2"><a
href="#" onclick="javascript:showPlainTxt('code-2'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-2"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">r8spermute.<span
style="">py</span> example/example.<span
style="">trees</span> example/example.<span
style="">r8s</span></div></li></ol></div></div></div><p></p><p>This will start r8s running and you should then see some output like this:</p><div
class="igBar"><span
id="lcode-3"><a
href="#" onclick="javascript:showPlainTxt('code-3'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-3"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Constraints found:&nbsp; <span
style="color:#800000;color:#800000;">3</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Constraints ignored:&nbsp; <span
style="color:#800000;color:#800000;">0</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Total Constraint Combinations:&nbsp; <span
style="color:#800000;color:#800000;">7</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Running analysis <span
style="color:#800000;color:#800000;">1</span> of <span
style="color:#800000;color:#800000;">7</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#800000;color:#800000;">0</span>.<span
style="color:#800000;color:#800000;">14</span>%<span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Staging in:&nbsp; /var/folders/9Z/9Z3O2T2o2RmgRU+F75TSx++++TQ/-Tmp-/tmpXn1lw9</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Constraints:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">+&nbsp; constrain taxon=node1 min_age=<span
style="color:#800000;color:#800000;">1</span>.<span
style="color:#800000;color:#800000;">8</span> max_age=<span
style="color:#800000;color:#800000;">2</span>.<span
style="color:#800000;color:#800000;">5</span>;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Logging in: example/example_100.<span
style="">log</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">r8s version <span
style="color:#800000;color:#800000;">1</span>.<span
style="color:#800000;color:#800000;">71</span> <span
style="color:#006600; font-weight:bold;">&#40;</span>compiled May <span
style="color:#800000;color:#800000;">16</span> <span
style="color:#800000;color:#800000;">2006</span><span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#006600; font-weight:bold;">&#91;</span>...<span
style="">reading</span> file /var/folders/9Z/9Z3O2T2o2RmgRU+F75TSx++++TQ/-Tmp-/tmpXn1lw9<span
style="color:#006600; font-weight:bold;">&#93;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Elapsed time: <span
style="color:#800000;color:#800000;">4</span>.28s <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#800000;color:#800000;">0</span>.<span
style="color:#800000;color:#800000;">07</span> minutes<span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Average run-time so far: <span
style="color:#800000;color:#800000;">4</span>.28s <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#800000;color:#800000;">0</span>.<span
style="color:#800000;color:#800000;">07</span> minutes<span
style="color:#006600; font-weight:bold;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Estimated run-time left: <span
style="color:#800000;color:#800000;">25</span>.68s <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#800000;color:#800000;">0</span>.<span
style="color:#800000;color:#800000;">43</span> minutes<span
style="color:#006600; font-weight:bold;">&#41;</span></div></li></ol></div></div></div><p></p><p>...etc.</p><p>This tells us that we've got one constraint turned on (+  constrain taxon=node1 min_age=1.8 max_age=2.5;)' in this sub-analysis, as well as various other run-time statistics. ....and now we wait for this to finish. It could take some time..</p><p>When the analysis has finished, we use the program r8spermute_results.py to parse the results:</p><div
class="igBar"><span
id="lcode-4"><a
href="#" onclick="javascript:showPlainTxt('code-4'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-4"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">python r8spermute_results.<span
style="">py</span> example/</div></li></ol></div></div></div><p></p><p>This will loop over the log files and extract the relevant information. You probably want to output this information to a file, so run it like this:</p><div
class="igBar"><span
id="lcode-5"><a
href="#" onclick="javascript:showPlainTxt('code-5'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-5"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">python r8spermute_results.<span
style="">py</span> example/&amp;gt; results.<span
style="">txt</span></div></li></ol></div></div></div><p></p><p>Now, we can look at the results, which will look something like this:</p><div
class="igBar"><span
id="lcode-6"><a
href="#" onclick="javascript:showPlainTxt('code-6'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-6"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">node1 node2 Simon node1 node2</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#800000;color:#800000;">0</span> <span
style="color:#800000;color:#800000;">0</span> <span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">15</span>.<span
style="color:#800000;color:#800000;">22</span> <span
style="color:#800000;color:#800000;">2</span>.<span
style="color:#800000;color:#800000;">84</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#800000;color:#800000;">0</span> <span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">0</span> <span
style="color:#800000;color:#800000;">54</span>.<span
style="color:#800000;color:#800000;">60</span> <span
style="color:#800000;color:#800000;">1</span>.<span
style="color:#800000;color:#800000;">30</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#800000;color:#800000;">0</span> <span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">49</span>.<span
style="color:#800000;color:#800000;">45</span> <span
style="color:#800000;color:#800000;">1</span>.<span
style="color:#800000;color:#800000;">30</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">0</span> <span
style="color:#800000;color:#800000;">0</span> <span
style="color:#800000;color:#800000;">2</span>.<span
style="color:#800000;color:#800000;">50</span> <span
style="color:#800000;color:#800000;">4</span>.<span
style="color:#800000;color:#800000;">38</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">0</span> <span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">2</span>.<span
style="color:#800000;color:#800000;">50</span> <span
style="color:#800000;color:#800000;">4</span>.<span
style="color:#800000;color:#800000;">18</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">0</span> <span
style="color:#800000;color:#800000;">2</span>.<span
style="color:#800000;color:#800000;">50</span> <span
style="color:#800000;color:#800000;">1</span>.<span
style="color:#800000;color:#800000;">30</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">1</span> <span
style="color:#800000;color:#800000;">2</span>.<span
style="color:#800000;color:#800000;">50</span> <span
style="color:#800000;color:#800000;">1</span>.<span
style="color:#800000;color:#800000;">30</span></div></li></ol></div></div></div><p></p><p>It's probably easiest to load this into a spreadsheet. Each row is an analysis. The first 3 columns (containing 1's and 0's) are our constraints and whether they're turned on (=1) or off (=0) in the analysis. The last two columns "node1" and "node2" are our estimated ages of those nodes, under the calibrations.</p><p>So, the first line shows that node1 is estimated to be 15.22 years old and node2 is 2.84 years old when only the calibration called "Simon" is used.</p><p>The second line shows that when only node2 is calibrated, the estimate for node1 and node2 is 54.60 and 1.30 respectively.</p><p>In contrast, the very last line shows that when all calibrations are turned on, then the age estimates are 2.50 and 1.30 respectively.</p><h2>References:</h2><p>[1] Sanderson, M. J. 1997. A nonparametric approach to estimating divergence<br
/> times in the absence of rate constancy. Mol. Biol. Evol. 14:1218-1231.</p><p>[2] Sanderson, M. J. 2002. Estimating absolute rates of molecular evolution and<br
/> divergence times: a penalized likelihood approach. Mol. Biol. Evol.<br
/> 19:101-109.</p><p>[3] Gray, R.D., Drummond, A.J., &amp; Greenhill, S.J. (2009) Language Phylogenies<br
/> Reveal Expansion Pulses and Pauses in Pacific Settlement. Science, 323:<br
/> 479-483.</p> ]]></content:encoded> <wfw:commentRss>http://simon.net.nz/articles/r8spermute/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Query PubMed for citation information using a DOI and Python</title><link>http://simon.net.nz/articles/query-pubmed-for-citation-information-using-a-doi-and-python/</link> <comments>http://simon.net.nz/articles/query-pubmed-for-citation-information-using-a-doi-and-python/#comments</comments> <pubDate>Mon, 29 Jan 2007 14:01:44 +0000</pubDate> <dc:creator>Simon</dc:creator> <category><![CDATA[code]]></category> <category><![CDATA[python]]></category> <guid
isPermaLink="false">http://simon.net.nz/articles/query-pubmed-for-citation-information-using-a-doi-and-python/</guid> <description><![CDATA[Here's a simple little script to query PubMed for a Digitial Object Identifier (a DOI)]]></description> <content:encoded><![CDATA[<p>Here's a simple little script to query <a
href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi">PubMed</a> for a <a
href="http://en.wikipedia.org/wiki/Digital_object_identifier">Digitial Object Identifier</a> (a DOI)</p><p>Usage is quite simple, find a DOI somewhere, e.g. <em>10.1038/nature02029</em> (for <a
href="http://language.psy.auckland.ac.nz/publications/index.php?pub=Gray_and_Atkinson2003Nature">this groundbreaking paper</a>), and run this:</p><div
class="igBar"><span
id="lcode-7"><a
href="#" onclick="javascript:showPlainTxt('code-7'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-7"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">lurch:~ python pythonquery.<span
style="">py</span> <span
style="color:#800000;color:#800000;">10</span>.<span
style="color:#800000;color:#800000;">1038</span>/nature02029</div></li></ol></div></div></div><p></p><p>... and via the magic of webservices and XML, and with a bit of luck, you'll get something like this back:</p><div
class="igBar"><span
id="lcode-8"><a
href="#" onclick="javascript:showPlainTxt('code-8'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">CODE:</span><div
id="code-8"><div
class="code"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Language-tree divergence times support the Anatolian theory of Indo-European origin.</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="">Gray</span>, RD, Atkinson, QD</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Nature <span
style="color:#800000;color:#800000;">2003</span>, <span
style="color:#800000;color:#800000;">426</span> <span
style="color:#006600; font-weight:bold;">&#40;</span><span
style="color:#800000;color:#800000;">6965</span><span
style="color:#006600; font-weight:bold;">&#41;</span>:<span
style="color:#800000;color:#800000;">435</span>-<span
style="color:#800000;color:#800000;">9</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Languages, like genes, provide vital clues about human history. <span
style="">The</span> origin of</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">the Indo-European language family is <span
style="color:#CC0000;">"the most intensively studied, yet still</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#CC0000;">most recalcitrant, problem of historical linguistics"</span>. <span
style="">Numerous</span> genetic studies</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">of Indo-European origins have also produced inconclusive results. <span
style="">Here</span> we</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">analyse linguistic data using computational methods derived from evolutionary</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">biology. <span
style="">We</span> test two theories of Indo-European origin: the <span
style="color:#CC0000;">'Kurgan expansion'</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">and the <span
style="color:#CC0000;">'Anatolian farming'</span> hypotheses. <span
style="">The</span> Kurgan theory centres on possible</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">archaeological evidence for an expansion into Europe and the Near East by</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Kurgan horsemen beginning in the sixth millennium BP. <span
style="">In</span> contrast, the Anatolian</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">theory claims that Indo-European languages expanded with the spread of</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">agriculture from Anatolia around <span
style="color:#800000;color:#800000;">8</span>,<span
style="color:#800000;color:#800000;">000</span>-<span
style="color:#800000;color:#800000;">9</span>,<span
style="color:#800000;color:#800000;">500</span> years bp. <span
style="">In</span> striking agreement</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">with the Anatolian hypothesis, our analysis of a matrix of <span
style="color:#800000;color:#800000;">87</span> languages with</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color:#800000;color:#800000;">2</span>,<span
style="color:#800000;color:#800000;">449</span> lexical items produced an estimated age range for the initial Indo-European</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">divergence of between <span
style="color:#800000;color:#800000;">7</span>,<span
style="color:#800000;color:#800000;">800</span> and <span
style="color:#800000;color:#800000;">9</span>,<span
style="color:#800000;color:#800000;">800</span> years bp. <span
style="">These</span> results were robust to</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">changes in coding procedures, calibration points, rooting of the trees and priors</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">in the bayesian analysis.</div></li></ol></div></div></div><p></p><h2>The Code:</h2><div
class="igBar"><span
id="lpython-9"><a
href="#" onclick="javascript:showPlainTxt('python-9'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PYTHON:</span><div
id="python-9"><div
class="python"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;">#!/usr/bin/env python#&nbsp; &nbsp;Simple script to query pubmed for a DOI</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;">#&nbsp; &nbsp;(c) Simon Greenhill, 2007</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;">#&nbsp; &nbsp;http://simon.net.nz/</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">import</span> <span
style="color: #dc143c;">urllib</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">from</span> <span
style="color: #dc143c;">xml</span>.<span
style="color: black;">dom</span> <span
style="color: #ff7700;font-weight:bold;">import</span> minidom</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">def</span> get_citation_from_doi<span
style="color: black;">&#40;</span>query, <span
style="color: #dc143c;">email</span>=<span
style="color: #483d8b;">'YOUR EMAIL GOES HERE'</span>, tool=<span
style="color: #483d8b;">'SimonsPythonQuery'</span>, database=<span
style="color: #483d8b;">'pubmed'</span><span
style="color: black;">&#41;</span>:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; params = <span
style="color: black;">&#123;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #483d8b;">'db'</span>:database,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #483d8b;">'tool'</span>:tool,</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #483d8b;">'email'</span>:<span
style="color: #dc143c;">email</span>,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #483d8b;">'term'</span>:query,</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #483d8b;">'usehistory'</span>:<span
style="color: #483d8b;">'y'</span>,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #483d8b;">'retmax'</span>:<span
style="color: #ff4500;color:#800000;">1</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: black;">&#125;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #808080; font-style: italic;"># try to resolve the PubMed ID of the DOI</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; url = <span
style="color: #483d8b;">'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?'</span> + <span
style="color: #dc143c;">urllib</span>.<span
style="color: black;">urlencode</span><span
style="color: black;">&#40;</span>params<span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; data = <span
style="color: #dc143c;">urllib</span>.<span
style="color: black;">urlopen</span><span
style="color: black;">&#40;</span>url<span
style="color: black;">&#41;</span>.<span
style="color: black;">read</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #808080; font-style: italic;"># parse XML output from PubMed...</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; xmldoc = minidom.<span
style="color: black;">parseString</span><span
style="color: black;">&#40;</span>data<span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; ids = xmldoc.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'Id'</span><span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #808080; font-style: italic;"># nothing found, exit</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">if</span> <span
style="color: #008000;">len</span><span
style="color: black;">&#40;</span>ids<span
style="color: black;">&#41;</span> == <span
style="color: #ff4500;color:#800000;">0</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">raise</span> <span
style="color: #008000;">Exception</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">"DoiNotFound"</span><span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #808080; font-style: italic;"># get ID</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #008000;">id</span> = ids<span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">childNodes</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">data</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #808080; font-style: italic;"># remove unwanted parameters</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; params.<span
style="color: black;">pop</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'term'</span><span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; params.<span
style="color: black;">pop</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'usehistory'</span><span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; params.<span
style="color: black;">pop</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'retmax'</span><span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #808080; font-style: italic;"># and add new ones...</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; params<span
style="color: black;">&#91;</span><span
style="color: #483d8b;">'id'</span><span
style="color: black;">&#93;</span> = <span
style="color: #008000;">id</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; params<span
style="color: black;">&#91;</span><span
style="color: #483d8b;">'retmode'</span><span
style="color: black;">&#93;</span> = <span
style="color: #483d8b;">'xml'</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #808080; font-style: italic;"># get citation info:</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; url = <span
style="color: #483d8b;">'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?'</span> + <span
style="color: #dc143c;">urllib</span>.<span
style="color: black;">urlencode</span><span
style="color: black;">&#40;</span>params<span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; data = <span
style="color: #dc143c;">urllib</span>.<span
style="color: black;">urlopen</span><span
style="color: black;">&#40;</span>url<span
style="color: black;">&#41;</span>.<span
style="color: black;">read</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">return</span> data</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">def</span> text_output<span
style="color: black;">&#40;</span><span
style="color: #dc143c;">xml</span><span
style="color: black;">&#41;</span>:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #483d8b;">""</span><span
style="color: #483d8b;">"Makes a simple text output from the XML returned from efetch"</span><span
style="color: #483d8b;">""</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; xmldoc = minidom.<span
style="color: black;">parseString</span><span
style="color: black;">&#40;</span><span
style="color: #dc143c;">xml</span><span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; title = xmldoc.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'ArticleTitle'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; title = title.<span
style="color: black;">childNodes</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">data</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; abstract = xmldoc.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'AbstractText'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; abstract = abstract.<span
style="color: black;">childNodes</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">data</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; authors = xmldoc.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'AuthorList'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; authors = authors.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'Author'</span><span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; authorlist = <span
style="color: black;">&#91;</span><span
style="color: black;">&#93;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">for</span> author <span
style="color: #ff7700;font-weight:bold;">in</span> authors:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LastName = author.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'LastName'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">childNodes</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">data</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Initials = author.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'Initials'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">childNodes</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">data</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; author = <span
style="color: #483d8b;">'%s, %s'</span> % <span
style="color: black;">&#40;</span>LastName, Initials<span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; authorlist.<span
style="color: black;">append</span><span
style="color: black;">&#40;</span>author<span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; journalinfo = xmldoc.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'Journal'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; journal = journalinfo.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'Title'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">childNodes</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">data</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; journalinfo = journalinfo.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'JournalIssue'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; volume = journalinfo.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'Volume'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">childNodes</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">data</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; issue = journalinfo.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'Issue'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">childNodes</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">data</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; year = journalinfo.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'Year'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">childNodes</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">data</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #808080; font-style: italic;"># this is a bit odd?</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; pages = xmldoc.<span
style="color: black;">getElementsByTagName</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'MedlinePgn'</span><span
style="color: black;">&#41;</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">childNodes</span><span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span>.<span
style="color: black;">data</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; output = <span
style="color: black;">&#91;</span><span
style="color: black;">&#93;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; output.<span
style="color: black;">append</span><span
style="color: black;">&#40;</span>title<span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; output.<span
style="color: black;">append</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">''</span><span
style="color: black;">&#41;</span> <span
style="color: #808080; font-style: italic;">#empty line</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; output.<span
style="color: black;">append</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">', '</span>.<span
style="color: black;">join</span><span
style="color: black;">&#40;</span>authorlist<span
style="color: black;">&#41;</span><span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; output.<span
style="color: black;">append</span><span
style="color: black;">&#40;</span> <span
style="color: #483d8b;">'%s %s, %s (%s):%s'</span> % <span
style="color: black;">&#40;</span>journal, year, volume, issue, pages<span
style="color: black;">&#41;</span> <span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; output.<span
style="color: black;">append</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">''</span><span
style="color: black;">&#41;</span> <span
style="color: #808080; font-style: italic;">#empty line</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; output.<span
style="color: black;">append</span><span
style="color: black;">&#40;</span>abstract<span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">return</span> output</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span
style="color: #483d8b;">'__main__'</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">from</span> <span
style="color: #dc143c;">sys</span> <span
style="color: #ff7700;font-weight:bold;">import</span> argv, exit</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">if</span> <span
style="color: #008000;">len</span><span
style="color: black;">&#40;</span>argv<span
style="color: black;">&#41;</span> == <span
style="color: #ff4500;color:#800000;">1</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">'Usage: %s &lt;query&gt;'</span> % argv<span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">' e.g. %s 10.1038/ng1946'</span> % argv<span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">0</span><span
style="color: black;">&#93;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; exit<span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; citation = get_citation_from_doi<span
style="color: black;">&#40;</span>argv<span
style="color: black;">&#91;</span><span
style="color: #ff4500;color:#800000;">1</span><span
style="color: black;">&#93;</span><span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">for</span> line <span
style="color: #ff7700;font-weight:bold;">in</span> text_output<span
style="color: black;">&#40;</span>citation<span
style="color: black;">&#41;</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span
style="color: #ff7700;font-weight:bold;">print</span> line</div></li></ol></div></div></div><p></p><p>--Simon</p> ]]></content:encoded> <wfw:commentRss>http://simon.net.nz/articles/query-pubmed-for-citation-information-using-a-doi-and-python/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Simple FAQ application for Django</title><link>http://simon.net.nz/articles/simple-faq-application-for-django/</link> <comments>http://simon.net.nz/articles/simple-faq-application-for-django/#comments</comments> <pubDate>Sat, 30 Dec 2006 22:32:28 +0000</pubDate> <dc:creator>Simon</dc:creator> <category><![CDATA[code]]></category> <category><![CDATA[django]]></category> <category><![CDATA[python]]></category> <guid
isPermaLink="false">http://simon.net.nz/articles/simple-faq-application-for-django/</guid> <description><![CDATA[This is an exceedingly simple FAQ application for Django, which I wrote for Henry.]]></description> <content:encoded><![CDATA[<p>This is an exceedingly simple FAQ application for <a
href="http://djangoproject.com">Django</a>, which I wrote for <a
href="http://henry.simon.net.nz/about/">Henry</a>.</p><p>Do what you want with it, &amp; let me know of any bugs etc.</p><h2>The Model</h2><p>To store the FAQs!</p><div
class="igBar"><span
id="lpython-10"><a
href="#" onclick="javascript:showPlainTxt('python-10'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PYTHON:</span><div
id="python-10"><div
class="python"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">from</span> django.<span
style="color: black;">db</span> <span
style="color: #ff7700;font-weight:bold;">import</span> models</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">from</span> django.<span
style="color: black;">conf</span> <span
style="color: #ff7700;font-weight:bold;">import</span> settings</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;"># Create your models here.</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">class</span> Faq<span
style="color: black;">&#40;</span> models.<span
style="color: black;">Model</span> <span
style="color: black;">&#41;</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">""</span><span
style="color: #483d8b;">"Stores FAQS"</span><span
style="color: #483d8b;">""</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">question = models.<span
style="color: black;">CharField</span><span
style="color: black;">&#40;</span>maxlength=<span
style="color: #ff4500;color:#800000;">255</span><span
style="color: black;">&#41;</span> <span
style="color: #808080; font-style: italic;"># The Q</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">answer = models.<span
style="color: black;">TextField</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span> <span
style="color: #808080; font-style: italic;"># the A</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">post_date = models.<span
style="color: black;">DateTimeField</span><span
style="color: black;">&#40;</span>auto_now_add=<span
style="color: #008000;">True</span>, db_index=<span
style="color: #008000;">True</span><span
style="color: black;">&#41;</span> <span
style="color: #808080; font-style: italic;"># when we answered it</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">def</span> <span
style="color: #0000cd;">__str__</span><span
style="color: black;">&#40;</span> <span
style="color: #008000;">self</span> <span
style="color: black;">&#41;</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">return</span> <span
style="color: #008000;">self</span>.<span
style="color: black;">question</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">class</span> Admin:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">search_fields = <span
style="color: black;">&#40;</span> <span
style="color: #483d8b;">'question'</span>, <span
style="color: #483d8b;">'answer'</span> <span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">date_hierarchy = <span
style="color: #483d8b;">'post_date'</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">list_display = <span
style="color: black;">&#40;</span> <span
style="color: #483d8b;">'question'</span>, <span
style="color: #483d8b;">'post_date'</span> <span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">fields = <span
style="color: black;">&#40;</span><span
style="color: black;">&#40;</span><span
style="color: #008000;">None</span>, <span
style="color: black;">&#123;</span> <span
style="color: #483d8b;">'fields'</span>: <span
style="color: black;">&#40;</span> <span
style="color: #483d8b;">'question'</span>, <span
style="color: #483d8b;">'answer'</span> <span
style="color: black;">&#41;</span><span
style="color: black;">&#125;</span><span
style="color: black;">&#41;</span>,<span
style="color: black;">&#41;</span></div></li></ol></div></div></div><p></p><h2>The View:</h2><p>To get the FAQs...</p><div
class="igBar"><span
id="lpython-11"><a
href="#" onclick="javascript:showPlainTxt('python-11'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PYTHON:</span><div
id="python-11"><div
class="python"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">from</span> django.<span
style="color: black;">shortcuts</span> <span
style="color: #ff7700;font-weight:bold;">import</span> render_to_response</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">from</span> django.<span
style="color: black;">template</span> <span
style="color: #ff7700;font-weight:bold;">import</span> RequestContext</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;"># Change &quot;myproject&quot; to your project name</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">from</span> myproject.<span
style="color: black;">about</span>.<span
style="color: black;">models</span> <span
style="color: #ff7700;font-weight:bold;">import</span> *</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">def</span> about<span
style="color: black;">&#40;</span>request<span
style="color: black;">&#41;</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">""</span><span
style="color: #483d8b;">"Displays all the FAQs"</span><span
style="color: #483d8b;">""</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">faqs = Faq.<span
style="color: black;">objects</span>.<span
style="color: black;">all</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">return</span> render_to_response<span
style="color: black;">&#40;</span> <span
style="color: #483d8b;">'about.html'</span>, <span
style="color: black;">&#123;</span>&nbsp; <span
style="color: #483d8b;">'faqs'</span>:faqs, <span
style="color: black;">&#125;</span>,</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">context_instance=RequestContext<span
style="color: black;">&#40;</span>request<span
style="color: black;">&#41;</span> <span
style="color: black;">&#41;</span></div></li></ol></div></div></div><p></p><h2>The Template:</h2><p>...and finally, the template to bring it all together:</p><div
class="igBar"><span
id="lhtml-12"><a
href="#" onclick="javascript:showPlainTxt('html-12'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">HTML:</span><div
id="html-12"><div
class="html"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{% extends &quot;base.html&quot; %}</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{% load markup %}</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{% block content %}</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #009900;"><a
href="http://december.com/html/4/element/h2.html"><span
style="color: #000000; font-weight: bold;">&lt;h2&gt;</span></a></span>Frequently Asked Questions:<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/h2&gt;</span></span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{% comment %}</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">build a &quot;table of contents first...&quot;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{% endcomment %}</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #009900;"><a
href="http://december.com/html/4/element/ul.html"><span
style="color: #000000; font-weight: bold;">&lt;ul&gt;</span></a></span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{% for faq in faqs %}</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span
style="color: #009900;"><a
href="http://december.com/html/4/element/li.html"><span
style="color: #000000; font-weight: bold;">&lt;li&gt;</span></a></span><span
style="color: #009900;"><a
href="http://december.com/html/4/element/a.html"><span
style="color: #000000; font-weight: bold;">&lt;a</span></a> <span
style="color: #000066;">href</span>=<span
style="color: #ff0000;">"http://simon.net.nz/wp-admin/#%7B%7B%20faq.id%20%7D%7D"</span><span
style="color: #000000; font-weight: bold;">&gt;</span></a></span>{{ faq.question|escape }}<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/li&gt;</span></span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{% endfor %}<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/ul&gt;</span></span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{% comment %}</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">now show the FAQs</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{% endcomment %}</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{% for faq in faqs %}</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #009900;"><a
href="http://december.com/html/4/element/a.html"><span
style="color: #000000; font-weight: bold;">&lt;a</span></a> <span
style="color: #000066;">title</span>=<span
style="color: #ff0000;">"{{ faq.id }}"</span> <span
style="color: #000066;">name</span>=<span
style="color: #ff0000;">"{{ faq.id }}"</span><span
style="color: #000000; font-weight: bold;">&gt;</span></a></span><span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #009900;"><a
href="http://december.com/html/4/element/h3.html"><span
style="color: #000000; font-weight: bold;">&lt;h3</span></a> <span
style="color: #000066;">class</span>=<span
style="color: #ff0000;">"q"</span><span
style="color: #000000; font-weight: bold;">&gt;</span></a></span> {{ faq.question|escape }}<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/h3&gt;</span></span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #009900;"><a
href="http://december.com/html/4/element/p.html"><span
style="color: #000000; font-weight: bold;">&lt;p</span></a> <span
style="color: #000066;">class</span>=<span
style="color: #ff0000;">"faq"</span><span
style="color: #000000; font-weight: bold;">&gt;</span></a></span> {{ faq.answer|textile }}<span
style="color: #009900;"><span
style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; {% endfor %}</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">{% endblock %}</div></li></ol></div></div></div><p></p><h2>The End:</h2><p>You couldn't get any simpler than that without using a textfile..</p><p><strong>Note:</strong> this requires textile - but you can easily change the filter in the template to whatever you want. You will need to have <em>django.contrib.markup</em> installed though.</p><p
class="download"> <a
href="http://simon.net.nz/files/djangofaqapplication.zip" id="p27">Download the Django FAQ Application</a></p><p>--Simon</p> ]]></content:encoded> <wfw:commentRss>http://simon.net.nz/articles/simple-faq-application-for-django/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Django Database Export, v.00001</title><link>http://simon.net.nz/articles/django-database-export-v00001/</link> <comments>http://simon.net.nz/articles/django-database-export-v00001/#comments</comments> <pubDate>Sat, 04 Nov 2006 10:11:26 +0000</pubDate> <dc:creator>Simon</dc:creator> <category><![CDATA[code]]></category> <category><![CDATA[django]]></category> <category><![CDATA[python]]></category> <guid
isPermaLink="false">http://simon.net.nz/articles/django-database-export-v00001/</guid> <description><![CDATA[Here's something I wrote to export database contents from a django application into the Django database API format.]]></description> <content:encoded><![CDATA[<p>Here's something I wrote to export database contents from <a
href="http://djangoproject.com">a django application</a> into the Django database API format.</p><p>It's certainly not going to do all the work for you - in particular you'll need to reorder things to make sure things that Django wants to be objects (i.e. Foreign Keys) are instantiated before the related object gets made.</p><p>Hope this helps someone somewhere.</p><div
class="igBar"><span
id="lpython-13"><a
href="#" onclick="javascript:showPlainTxt('python-13'); return false;">PLAIN TEXT</a></span></div><div
class="syntax_hilite"><span
class="langName">PYTHON:</span><div
id="python-13"><div
class="python"><ol><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;">#!/usr/bin/env python</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">""</span><span
style="color: #483d8b;">"</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">Script to export data from a Django database and generate</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">the appropriate django DB-API commands</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">Make sure you run it from the same directory as your settings.py</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">NOTE: it does NOT handle relationships yet, so, you'll need to take the output</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">and hand edit it to make sure that anything that Django needs as an object,</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">gets instantiated first</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">(c) Simon Greenhill / dev@simon.net.nz / http://simon.net.nz</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">Version: 0.00001</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">"</span><span
style="color: #483d8b;">""</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">debug = <span
style="color: #008000;">False</span> <span
style="color: #808080; font-style: italic;"># just a debug flag to spit out what we're doing.</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">import</span> <span
style="color: #dc143c;">sys</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">from</span> django.<span
style="color: black;">core</span>.<span
style="color: black;">management</span> <span
style="color: #ff7700;font-weight:bold;">import</span> setup_environ</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">try</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">import</span> settings</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">except</span> <span
style="color: #008000;">ImportError</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">"You don't appear to have a settings file in this directory!"</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">"Please run this from inside a project directory"</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #dc143c;">sys</span>.<span
style="color: black;">exit</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">setup_environ<span
style="color: black;">&#40;</span>settings<span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">from</span> django.<span
style="color: black;">db</span> <span
style="color: #ff7700;font-weight:bold;">import</span> models</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;"># do model imports</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">""</span><span
style="color: #483d8b;">"</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">###############################################################</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">#&nbsp; &nbsp;Model imports&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">#&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;#</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">###############################################################</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #483d8b;">"</span><span
style="color: #483d8b;">""</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">for</span> app <span
style="color: #ff7700;font-weight:bold;">in</span> models.<span
style="color: black;">get_apps</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">for</span> model <span
style="color: #ff7700;font-weight:bold;">in</span> app.<span
style="color: black;">models</span>.<span
style="color: black;">get_models</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span>:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">"from %s import %s"</span> % <span
style="color: black;">&#40;</span> app.__name__, model._meta.<span
style="color: black;">object_name</span> <span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;"># what apps we've done</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">seen = <span
style="color: black;">&#91;</span><span
style="color: black;">&#93;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">for</span> app <span
style="color: #ff7700;font-weight:bold;">in</span> models.<span
style="color: black;">get_apps</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">for</span> model <span
style="color: #ff7700;font-weight:bold;">in</span> app.<span
style="color: black;">models</span>.<span
style="color: black;">get_models</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span>:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">if</span> model <span
style="color: #ff7700;font-weight:bold;">not</span> <span
style="color: #ff7700;font-weight:bold;">in</span> seen:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">"# %s.%s "</span> % <span
style="color: black;">&#40;</span>app.__name__, model._meta.<span
style="color: black;">object_name</span><span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">if</span> debug:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">"#<span
style="color: #000099; font-weight: bold;">\t</span>"</span>, model</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">for</span> row <span
style="color: #ff7700;font-weight:bold;">in</span> model.<span
style="color: black;">objects</span>.<span
style="color: black;">iterator</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">if</span> debug:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">"#<span
style="color: #000099; font-weight: bold;">\t</span><span
style="color: #000099; font-weight: bold;">\t</span>"</span>,row</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">attrs = <span
style="color: black;">&#91;</span><span
style="color: black;">&#93;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">for</span> col <span
style="color: #ff7700;font-weight:bold;">in</span> row._meta.<span
style="color: black;">fields</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">key = col.<span
style="color: black;">name</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">value = <span
style="color: #008000;">getattr</span><span
style="color: black;">&#40;</span>row, key<span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">if</span> col.<span
style="color: black;">get_internal_type</span><span
style="color: black;">&#40;</span><span
style="color: black;">&#41;</span> == <span
style="color: #483d8b;">'ForeignKey'</span>:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;">###print key, 'bork bork bork'</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">pass</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;"># if it's numeric, we don't need to quote it.</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">if</span> <span
style="color: #008000;">isinstance</span><span
style="color: black;">&#40;</span>value,<span
style="color: #008000;">int</span><span
style="color: black;">&#41;</span> <span
style="color: #ff7700;font-weight:bold;">or</span> <span
style="color: #008000;">isinstance</span><span
style="color: black;">&#40;</span>value,<span
style="color: #008000;">float</span><span
style="color: black;">&#41;</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">pass</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;"># if it's a string...</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">elif</span> <span
style="color: #008000;">isinstance</span><span
style="color: black;">&#40;</span>value,<span
style="color: #008000;">str</span><span
style="color: black;">&#41;</span>:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;"># ... and it's got a quote mark or new line in it, then triple-quote it.</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">if</span> value.<span
style="color: black;">find</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">'&quot;'</span><span
style="color: black;">&#41;</span>&amp;gt; <span
style="color: #ff4500;color:#800000;">0</span> <span
style="color: #ff7700;font-weight:bold;">or</span> value.<span
style="color: black;">find</span><span
style="color: black;">&#40;</span><span
style="color: #483d8b;">"<span
style="color: #000099; font-weight: bold;">\n</span>"</span><span
style="color: black;">&#41;</span>&amp;gt; <span
style="color: #ff4500;color:#800000;">0</span>:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">value = <span
style="color: #483d8b;">'&quot;&quot;&quot;%s&quot;&quot;&quot;'</span> % value</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;"># ... otherwise single quote it.</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">else</span>:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">value = <span
style="color: #483d8b;">'&quot;%s&quot;'</span> % value</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #808080; font-style: italic;"># don't know what it is, but single quote it</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">else</span>:</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">value = <span
style="color: #483d8b;">'&quot;%s&quot;'</span> % value</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">attrs.<span
style="color: black;">append</span><span
style="color: black;">&#40;</span> <span
style="color: #483d8b;">'%s=%s'</span> % <span
style="color: black;">&#40;</span> key, value <span
style="color: black;">&#41;</span> <span
style="color: black;">&#41;</span></div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">if</span> debug:</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">"#<span
style="color: #000099; font-weight: bold;">\t</span><span
style="color: #000099; font-weight: bold;">\t</span><span
style="color: #000099; font-weight: bold;">\t</span>"</span>, key, <span
style="color: #008000;">getattr</span><span
style="color: black;">&#40;</span>row, key<span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span
style="color: #ff7700;font-weight:bold;">print</span> <span
style="color: #483d8b;">""</span><span
style="color: #483d8b;">"%s(%s).save()"</span><span
style="color: #483d8b;">""</span> % <span
style="color: black;">&#40;</span> model._meta.<span
style="color: black;">object_name</span>, <span
style="color: #483d8b;">', '</span>.<span
style="color: black;">join</span><span
style="color: black;">&#40;</span>attrs<span
style="color: black;">&#41;</span> <span
style="color: black;">&#41;</span></div></li><li
style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li><li
style="font-weight: bold;color:#26536A;"><div
style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">seen.<span
style="color: black;">append</span><span
style="color: black;">&#40;</span>model<span
style="color: black;">&#41;</span></div></li></ol></div></div></div><p></p><p
class="highlight"> <strong>Update 19/01/2007:</strong> limodou has written  a <a
href="http://code.djangoproject.com/wiki/DbDumpScript">far superior export solution here</a>.</p><p>--Simon</p> ]]></content:encoded> <wfw:commentRss>http://simon.net.nz/articles/django-database-export-v00001/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>mnemosyne &#8211; a personal information wiki</title><link>http://simon.net.nz/articles/mnemosyne/</link> <comments>http://simon.net.nz/articles/mnemosyne/#comments</comments> <pubDate>Thu, 19 Oct 2006 07:12:35 +0000</pubDate> <dc:creator>Simon</dc:creator> <category><![CDATA[code]]></category> <category><![CDATA[django]]></category> <category><![CDATA[mnemosyne]]></category> <category><![CDATA[python]]></category> <guid
isPermaLink="false">http://simon.net.nz/articles/mnemosyne/</guid> <description><![CDATA[I've just released my personal wiki system mnemosyne to the public. It runs under Django, written in Python and I've released it under the BSD licence, check it out at http://mnemosyne.simon.net.nz]]></description> <content:encoded><![CDATA[<p>I've just released my personal wiki system <a
href="http://mnemosyne.simon.net.nz/">mnemosyne</a> to the public. It runs under Django, written in Python and I've released it under the BSD licence, check it out at <a
href="http://mnemosyne.simon.net.nz">mnemosyne.simon.net.nz</a></p><h3>Features:</h3><ul><li> internal and external linking</li><li> page versioning</li><li> edit history tracking</li><li> backlinks</li><li> users (sort of - in progress),</li><li> page tagging</li><li> bibtex handling</li><li> a pretentious name</li><li> 'sensible' file attachment handling</li><li> 'sensible' data storage</li><li> full search capabilities</li><li> swappable wiki parsers (textile, reStructured Text, plain text and<br
/> should be easy to add others)</li><li> macros for extra functionality</li></ul><p>This is the first major app. I've tackled in both python and Django, and I would love to hear comments / criticisms / suggestions. Be brutal!</p><p>--Simon</p> ]]></content:encoded> <wfw:commentRss>http://simon.net.nz/articles/mnemosyne/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
