<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
     xmlns:content="http://purl.org/rss/1.0/modules/content/"
     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
     xmlns:atom="http://www.w3.org/2005/Atom"
     xmlns:dc="http://purl.org/dc/elements/1.1/"
     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
     >
  <channel>
    <title>EnigmaCurry</title>
    <link>http://www.enigmacurry.com/</link>
    <description>The Curry Enigma</description>
    <pubDate>Mon, 02 Aug 2010 17:43:01 GMT</pubDate>
    <generator>Blogofile</generator>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Writing an OpenOffice.org Calc extension in Python</title>
      <link>http://www.enigmacurry.com/2009/12/13/writing-an-openoffice.org-calc-extension-in-python</link>
      <pubDate>Sun, 13 Dec 2009 10:08:00 EST</pubDate>
      <category><![CDATA[Python]]></category>
      <category><![CDATA[OpenOffice.org]]></category>
      <guid>http://www.enigmacurry.com/2009/12/13/writing-an-openoffice.org-calc-extension-in-python</guid>
      <description>Writing an OpenOffice.org Calc extension in Python</description>
      <content:encoded><![CDATA[<p>A very well organized group of thugs steals my money every day. I'm getting really tired of it, but I found a way to save at least some of my money so they don't steal nearly as much of it, nearly as often. For whatever reason, this gang hasn't devised a way to steal gold and silver nearly as efficiently as these little green pieces of paper that they call money. So I buy gold and silver whenever I can as a hedge against 'inflation' (which is really just their gang-speak for the wholesale-theft of my money.)
</p>
<p>I want to keep track of how much gold and silver I've bought, when I bought it, and inevitably I'll still want to know how many green pieces of paper I could theoretically trade it all in for.
</p>
<p>The easiest way to track all this information was to create a spreadsheet in OpenOffice.org's Calc. I created a sheet for gold purchases and another sheet for silver purchases. Everytime I make a purchase, I record the number of ounces, what form it is in (coins, bars, junk etc), who I bought it from, when I bought it, and the price I paid in FRNs (Federal Reserve Notes, aka green pieces of paper.) On another sheet I total the number of ounces I own and multiply it by the current spot price for the metal, which gives me the current price I could get if I sold it for FRNs. When tallying this total, I reference a special cell on the sheet, one that has the current spot price for gold, and another for silver.
</p>
<p>But checking the spot price myself and manually updating those cells was just too tedious for my programmer's heart. I wanted OpenOffice.org to automatically retrieve this information for me. So, I started researching OpenOffice.org extensions (plugins).
</p>
<p>Turns out, OpenOffice.org extensions can be written in my favorite programming language, Python (yea!), so I wrote the following extension a few weekends ago. It's <a href="http://github.com/EnigmaCurry/SpotMetal">on github</a> and can be downloaded with git:
</p>
<div class="pygments_murphy"><pre>  git clone git://github.com/EnigmaCurry/SpotMetal.git
</pre></div>

<p>If you just want the pre-compiled extension, it can be downloaded here locally:
</p>
<p><a href="/blog-post-files/SpotMetal-0.1.oxt">SpotMetal-0.1.oxt</a>
</p>
<p>You install it inside OpenOffice.org by going to <code>Tools -&gt; Extension Manager</code> and clicking on <code>Add</code> and browsing to the <code>SpotMetal-0.1.oxt</code> file you downloaded or built yourself.
</p>
<p>Once you have it installed, you now have a new Calc function available called <code>SPOTMETAL</code> which takes two arguments:
</p>
<ul>
 <li>
     <em>metal</em> - Which metal you want to look up. Can be one of <code>"gold", "silver", "platinum",</code> or <code>"palladium"</code>
 </li>

 <li>
     <em>bidAsk</em> - Whether you want the bid or the ask price. Can be either <code>"bid"</code> or <code>"ask"</code>.
 </li>
</ul>
<p>The price will automatically be refreshed every 5 minutes by default, but you can also force a refresh with the Calc function called <code>SPOTMETALREFRESH</code>.
</p>
<p>Here's an <a href="/blog-post-files/MetalTrackerExample.ods">example OpenOffice.org spreadhseet</a> that shows how you might track your own precious metal investment portfolio. The big button labeled "Refresh Spot Price" does what it says it does, but requires a bit more boiler-plate code in order for it to actually display on screen. In OpenOffice.org, you can see another macro called doReCalculate:
</p>
<ul>
 <li>
     <code>Tools-&gt;Macros-&gt;Organize Macros-&gt;OpenOffice.org Basic</code> 
 </li>

 <li>
     <code>MetalTrackerExample.ods-&gt;Standard-&gt;SpotMetal-&gt;doReCalculate</code>. 
 </li>
</ul>
<p>This extra macro is necessary to actually force the spreadsheet to request new data from the extension when you click the "Refresh Spot Price" button.
</p>
<p>While this extension might be of use to you if you also invest in precious metals, I guess the main reason I posted this is because it took a good deal of time researching how to write a Python extension for OpenOffice.org. Check out <a href="http://github.com/EnigmaCurry/SpotMetal">the source code on github</a> if you're looking to write your own extension, it's got it's own Makefile and hopefully it's documented well enough for it be useful for someone in the future.
</p>]]></content:encoded>
    </item>
  </channel>
</rss>
