<?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>super-cooper &#187; python</title>
	<atom:link href="http://www.super-cooper.com/archive/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.super-cooper.com</link>
	<description>Python, GIS, and a sprinkling of mindless drivel from Chad Cooper</description>
	<lastBuildDate>Sat, 21 Aug 2010 20:22:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Uploading photos to Shutterfly via Python</title>
		<link>http://www.super-cooper.com/archive/2008/12/07/uploading-photos-to-shutterfly-via-python/</link>
		<comments>http://www.super-cooper.com/archive/2008/12/07/uploading-photos-to-shutterfly-via-python/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 19:14:23 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[photography]]></category>

		<guid isPermaLink="false">http://www.super-cooper.com/?p=63</guid>
		<description><![CDATA[I finally got done sorting my 2008 photos this morning so I can start putting Christmas gifts together with them and needed to upload about 280 pictures to Shutterfly, where I have been getting prints since about 1999. Of course I could do this with their uploader, but that would be quite lame now, wouldn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got done sorting my 2008 photos this morning so I can start putting Christmas gifts together with them and needed to upload about 280 pictures to Shutterfly, where I have been getting prints since about 1999. Of course I could do this with their uploader, but that would be <em>quite lame</em> now, wouldn&#8217;t it, considering I <em>could</em> use Python to do it. Using the code below, the <a href="http://pypi.python.org/pypi/IPTCInfo/1.9.2-rc8">IPTCInfo module</a> and Jeremy Slater&#8217;s very cool <a href="http://conduit.sourcearchive.com/documentation/0.3.13.1/shutterfly_8py-source.html">shutterfly module</a> he wrote for the <a href="http://www.conduit-project.org/">GNOME Conduit Project</a> , I can iterate through my entire 2008 photo directory, look for my photos tagged for upload, and upload them to a specific album on Shutterfly. Sweet!</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #0008E6;font-weight:bold;">from</span> IPTC <span style="color: #0008E6;font-weight:bold;">import</span> IPTCInfo</code></li>
<li value="2" class="tab0 even"><code><span style="color: #0008E6;font-weight:bold;">import</span> <span style="color: #990000;">sys</span>, <span style="color: #990000;">os</span>, shutterfly</code></li>
<li value="3" class="odd">&nbsp;</li>
<li value="4" class="tab0 even"><code><span style="color: #0008E6;font-weight:bold;">class</span> ShutterflyUploadr:</code></li>
<li value="5" class="odd">&nbsp;</li>
<li value="6" class="tab1 even"><code><span style="color: #990000;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:</code></li>
<li value="7" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">pass</span></code></li>
<li value="8" class="even">&nbsp;</li>
<li value="9" class="tab1 odd"><code><span style="color: #990000;font-weight:bold;">def</span> grab_new_images<span style="color: black;">&#40;</span> <span style="color: #008000;">self</span> <span style="color: black;">&#41;</span>:</code></li>
<li value="10" class="tab2 even"><code><span style="color: #FF6600;">&quot;&quot;&quot; Recurses thru directories and looks for images to upload. I only want to upload my '5-star' images, so we scan the IPTC tags for 'r5', my way of tagging my pics I really like (usually get prints of r5s) &quot;&quot;&quot;</span></code></li>
<li value="11" class="tab2 odd"><code>images = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="12" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> dirpath, dirnames, filenames <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #990000;">os</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/users/chad/pictures/2008'</span><span style="color: black;">&#41;</span>:</code></li>
<li value="13" class="tab3 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> f <span style="color: #0008E6;font-weight:bold;">in</span> filenames :</code></li>
<li value="14" class="tab4 even"><code><span style="color: #FF6600;"># Grab IPTC keywords</span></code></li>
<li value="15" class="tab4 odd"><code>info = IPTCInfo<span style="color: black;">&#40;</span><span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>dirpath, f<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="16" class="tab4 even"><code><span style="color: #FF6600;"># Is it a 5-star photo?</span></code></li>
<li value="17" class="tab4 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #2DB300;">'r5'</span> <span style="color: #0008E6;font-weight:bold;">in</span> info.<span style="color: black;">keywords</span>:</code></li>
<li value="18" class="tab5 even"><code>ext = f.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span>&#038;quot<span style="color: #66cc66;">;</span>.&#038;quot<span style="color: #66cc66;">;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">-1</span><span style="color: black;">&#93;</span></code></li>
<li value="19" class="tab5 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> ext == &#038;quot<span style="color: #66cc66;">;</span>jpg&#038;quot<span style="color: #66cc66;">;</span> <span style="color: black;">&#41;</span>:</code></li>
<li value="20" class="tab6 even"><code>images.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">normpath</span><span style="color: black;">&#40;</span> dirpath + &#038;quot<span style="color: #66cc66;">;</span>/&#038;quot<span style="color: #66cc66;">;</span> + f <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span></code></li>
<li value="21" class="tab2 odd"><code>images.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="22" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">return</span> images</code></li>
<li value="23" class="odd">&nbsp;</li>
<li value="24" class="tab1 even"><code><span style="color: #990000;font-weight:bold;">def</span> upload<span style="color: black;">&#40;</span> <span style="color: #008000;">self</span> <span style="color: black;">&#41;</span>:</code></li>
<li value="25" class="tab2 odd"><code><span style="color: #FF6600;">&quot;&quot;&quot; Upload images to Shutterfly &quot;&quot;&quot;</span></code></li>
<li value="26" class="tab2 even"><code><span style="color: #990000;">user</span> = <span style="color: #2DB300;">'your_user_name'</span></code></li>
<li value="27" class="tab2 odd"><code><span style="color: #990000;">pwd</span> = <span style="color: #2DB300;">'your_password'</span></code></li>
<li value="28" class="tab2 even"><code>sfly = shutterfly.<span style="color: black;">Shutterfly</span><span style="color: black;">&#40;</span><span style="color: #990000;">user</span>,<span style="color: #990000;">pwd</span><span style="color: black;">&#41;</span></code></li>
<li value="29" class="tab2 odd"><code><span style="color: #FF6600;"># Get an existing album</span></code></li>
<li value="30" class="tab2 even"><code>album = sfly.<span style="color: black;">getAlbums</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #2DB300;">'Album_Name'</span><span style="color: black;">&#93;</span></code></li>
<li value="31" class="tab2 odd"><code>image_list = <span style="color: #008000;">self</span>.<span style="color: black;">grab_new_images</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="32" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> image <span style="color: #0008E6;font-weight:bold;">in</span> image_list:</code></li>
<li value="33" class="tab3 odd"><code>album.<span style="color: black;">uploadPhoto</span><span style="color: black;">&#40;</span>image, <span style="color: #2DB300;">'image/jpeg'</span>, <span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">basename</span><span style="color: black;">&#40;</span>image<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="34" class="even">&nbsp;</li>
<li value="35" class="tab0 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> __name__ == <span style="color: #2DB300;">'__main__'</span>:</code></li>
<li value="36" class="even">&nbsp;</li>
<li value="37" class="tab1 odd"><code>sfu = ShutterflyUploadr<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="38" class="tab1 even"><code>sfu.<span style="color: black;">upload</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/shutterflyuploadr.txt">shutterflyuploadr.txt</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/12/07/uploading-photos-to-shutterfly-via-python/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Python and GIS &#8211; Beyond ModelBuilder and PythonWin</title>
		<link>http://www.super-cooper.com/archive/2008/11/15/python-and-gis-beyond-modelbuilder-and-pythonwin/</link>
		<comments>http://www.super-cooper.com/archive/2008/11/15/python-and-gis-beyond-modelbuilder-and-pythonwin/#comments</comments>
		<pubDate>Sat, 15 Nov 2008 16:14:03 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[presentation]]></category>

		<guid isPermaLink="false">http://www.super-cooper.com/?p=62</guid>
		<description><![CDATA[This is a presentation I gave last February at the ESRI Petroleum User Group conference in Houston, TX. I just discovered SlideShare the other day. Python And GIS &#8211; Beyond Modelbuilder And Pythonwin View SlideShare presentation or Upload your own. (tags: esri pug)]]></description>
			<content:encoded><![CDATA[<p>This is a presentation I gave last February at the ESRI Petroleum User Group conference in Houston, TX. I just discovered <a href="http://www.slideshare.net">SlideShare</a> the other day.</p>
<div style="width:425px;text-align:left" id="__ss_716653"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/supercooper/python-and-gis-beyond-modelbuilder-and-pythonwin-presentation?type=powerpoint" title="Python And GIS - Beyond Modelbuilder And Pythonwin">Python And GIS &#8211; Beyond Modelbuilder And Pythonwin</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=pythonandgisbeyondmodelbuilderandpythonwin-1225719286857699-8&#038;rel=0&#038;stripped_title=python-and-gis-beyond-modelbuilder-and-pythonwin-presentation" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=pythonandgisbeyondmodelbuilderandpythonwin-1225719286857699-8&#038;rel=0&#038;stripped_title=python-and-gis-beyond-modelbuilder-and-pythonwin-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View SlideShare <a style="text-decoration:underline;" href="http://www.slideshare.net/supercooper/python-and-gis-beyond-modelbuilder-and-pythonwin-presentation?type=powerpoint" title="View Python And GIS - Beyond Modelbuilder And Pythonwin on SlideShare">presentation</a> or <a style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own. (tags: <a style="text-decoration:underline;" href="http://slideshare.net/tag/esri">esri</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/pug">pug</a>)</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/11/15/python-and-gis-beyond-modelbuilder-and-pythonwin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>pyArkansas 2008 a huge success</title>
		<link>http://www.super-cooper.com/archive/2008/10/30/pyarkansas-2008-a-huge-success/</link>
		<comments>http://www.super-cooper.com/archive/2008/10/30/pyarkansas-2008-a-huge-success/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 02:30:51 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.super-cooper.com/?p=61</guid>
		<description><![CDATA[I&#8217;m way behind on posting this, but here goes. The first annual pyArkansas Python conference was held by pyar^2, the Python Artists of Arkansas , on October 4th on the campus of the University of Central Arkansas in Conway. We were very graciously hosted by the Department of Computer Science in their very fine facilities. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m way behind on posting this, but here goes.</p>
<p>The first annual <a href="http://pycamp.python.org/Arkansas/HomePage">pyArkansas</a> Python conference was held by pyar^2, the <a href="http://mail.python.org/mailman/listinfo/pyar2">Python Artists of Arkansas</a> , on October 4th on the campus of the University of Central Arkansas in Conway. We were very graciously hosted by the <a href="http://www.cs.uca.edu/">Department of Computer Science</a> in their very fine facilities. To our surprise, 57 people attended. Honestly, when Greg Lindstrom and myself starting planning this conference earlier this year, I think we would&#8217;ve been shocked to have 25 attend. Our <a href="http://pycamp.python.org/Arkansas/Registration">registration</a> numbers actually went above 70 folks, but the weather turned bad that morning, so that might have held some people away. We had a nice mix of beginner and experienced Pythonistas. People came from Branson, MO, Dallas, TX, and all over the state of Arkansas.</p>
<p>In the morning, we had classes including introductory Python (taught by <a href="http://www.cs.gsu.edu/~cscbecx/">Dr. Chen of UCA</a> ), intermediate Python (taught of <a href="http://python-advocacy.blogspot.com/">Jeff Rush</a> ), and Python for systems administration (taught by <a href="http://noahgift.com/">Noah Gift</a> ). These classes were very well received. The afternoon consisted of talks on pyGame, text/file processing, One Laptop Per Child (OLPC), Python eggs, the Python standard library, and Python with Eclipse. <a href="http://www.companycasuals.com/elegantstitchesconway/start.jsp">Elegant Stitches</a> was on hand selling their great assortment of officially-licensed Python shirts and gear (thanks again for the shirt, Janet!). I highly recommend the Python logo long-sleeved easy-care oxford &#8211; go order one today.</p>
<p>We had great sponsorship for this event. Major monetary sponsors included the <a href="http://www.cityofconway.org/">Conway Area Chamber of Commerce</a> , <a href="http://www.swn.com">Southwestern Energy Company</a> , <a href="http://novasyshealth.com/">Novasys Health</a> , and the <a href="http://www.python.org/psf/">Python Software Foundation</a> . <a href="http://www.wingware.com/">Wingware</a> graciously provided THREE 3-OS Wingware IDE Professional seats for us to give as prizes &#8211; many thanks for those. <a href="http://oreilly.com/">O&#8217;Reilly</a> publishing gave us a box of about 15 books to give away. <a href="http://pymag.phparch.com/">Python Magazine</a> and <a href="http://www.esri.com/news/arcuser/index.html">ESRI&#8217;s ArcUser</a> both pitched in free issues of magazines for our swag bags.</p>
<p>We have received some <a href="http://businessfromthejohn.blogspot.com/2008/10/arkansas-gets-it.html">pretty</a> <a href="http://www.thecabin.net/stories/101608/loc_1016080005.shtml">good</a> <a href="http://pyfound.blogspot.com/2008/10/first-pyarkansas-unqualified-success.html">press</a> on the event as well. Overall, I&#8217;d have to say that for a first stab and for having 50 people, we pulled it off quite nicely. We are already planning next year&#8217;s conference, which will surely be bigger and better than this one was.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/10/30/pyarkansas-2008-a-huge-success/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I&#8217;m published in ArcUser!</title>
		<link>http://www.super-cooper.com/archive/2008/08/10/im-published-in-arcuser/</link>
		<comments>http://www.super-cooper.com/archive/2008/08/10/im-published-in-arcuser/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 14:46:16 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[publications]]></category>

		<guid isPermaLink="false">http://www.super-cooper.com/archive/2008/08/10/im-published-in-arcuser/</guid>
		<description><![CDATA[My (hopefully first of many) article on GIS and Python has been published in the Spring 2008 edition of ESRI&#8217;s ArcUser magazine. You can get the pdf here , and the code listings here .]]></description>
			<content:encoded><![CDATA[<p>My (hopefully first of many) article on GIS and Python has been published in the Spring 2008 edition of ESRI&#8217;s <a href="http://www.esri.com/news/arcuser/index.html">ArcUser</a> magazine. You can get the pdf <a href="http://www.esri.com/news/arcuser/0708/files/tappingpython.pdf">here</a> , and the code listings <a href="http://www.esri.com/news/arcuser/0708/files/tappingpython.txt">here</a> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/08/10/im-published-in-arcuser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>flickruploadr.py now in svn</title>
		<link>http://www.super-cooper.com/archive/2008/08/09/flickruploadrpy-now-in-svn/</link>
		<comments>http://www.super-cooper.com/archive/2008/08/09/flickruploadrpy-now-in-svn/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 04:48:45 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[photography]]></category>

		<guid isPermaLink="false">http://www.super-cooper.com/archive/2008/08/09/flickruploadrpy-now-in-svn/</guid>
		<description><![CDATA[I finally got around to getting a Subversion repository setup, so the latest development version of my flickuploadr.py can be checked out: svn co http://svn.super-cooper.com/flickruploadr/trunk or you can just get it at: http://svn.super-cooper.com/flickruploadr/trunk]]></description>
			<content:encoded><![CDATA[<p>I finally got around to getting a Subversion repository setup, so the latest development version of my flickuploadr.py can be checked out:</p>
<p><code>svn co http://svn.super-cooper.com/flickruploadr/trunk</code></p>
<p>or you can just get it at:</p>
<p><a href="http://svn.super-cooper.com/flickruploadr/trunk">http://svn.super-cooper.com/flickruploadr/trunk</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/08/09/flickruploadrpy-now-in-svn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flickr Uploadr for Mac sucks, Python and the Flickr API to the rescue!</title>
		<link>http://www.super-cooper.com/archive/2008/06/29/flickr-uploadr-for-mac-sucks-python-and-the-flickr-api-to-the-rescue/</link>
		<comments>http://www.super-cooper.com/archive/2008/06/29/flickr-uploadr-for-mac-sucks-python-and-the-flickr-api-to-the-rescue/#comments</comments>
		<pubDate>Sun, 29 Jun 2008 15:30:40 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[flickr]]></category>

		<guid isPermaLink="false">http://www.super-cooper.com/?p=55</guid>
		<description><![CDATA[I&#8217;ve attempted to use the Flickr Uploadr for the last few years, and it never has impressed me. It always fails, usually after only about 10 pictures, which really sucks when you are trying to upload hundreds of pictures, which I usually do. So last night, I had over 300 shots to upload, and after [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve attempted to use the <a title="Flickr Tools" href="http://www.flickr.com/tools/" target="_self" title="Flickr Tools">Flickr Uploadr</a> for the last few years, and it never has impressed me. It <strong>always</strong> fails, usually after only about 10 pictures, which really sucks when you are trying to upload hundreds of pictures, which I usually do. So last night, I had over <a href="http://www.flickr.com/photos/supercooper/sets/72157605866011200/">300 shots</a> to upload, and after several attempts, the Flickr Uploadr just kept on failing to upload for me. I&#8217;ve been working on  my own upload script (most of which is hacked from other peoples code, I must admit) for months now off and on, so I decided to give it a shot &#8211; and of course, it uploaded over 100 pics in one shot, without a single blip. As soon as I get a Subversion repository setup on my host server, I&#8217;ll get the code in there.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/06/29/flickr-uploadr-for-mac-sucks-python-and-the-flickr-api-to-the-rescue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OOPs</title>
		<link>http://www.super-cooper.com/archive/2008/04/23/oops/</link>
		<comments>http://www.super-cooper.com/archive/2008/04/23/oops/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 03:07:24 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.super-cooper.com/?p=54</guid>
		<description><![CDATA[Generally, when most people learn that I am a geologist by training, they are surprised. Maybe I just give off some sort of geeky aura, or maybe they are surprised that I&#8217;m not &#34;using my degree&#34; (actually I am in a way, but that is too convoluted a story to get into here). At any [...]]]></description>
			<content:encoded><![CDATA[<p>Generally, when most people learn that I am a geologist by training, they are surprised. Maybe I just give off some sort of geeky aura, or maybe they are surprised that I&#8217;m not &quot;using my degree&quot; (actually I am in a way, but that is too convoluted a story to get into here). At any rate, the point is that I am not a programmer by training. I&#8217;d say that at least 75%+ of what I know about programming I taught myself through the ole School of Hard Knocks. I&#8217;ve had my share of training courses, but the vast majority of my experience has been just sitting down and cranking out code over the last eight years or so. But I digress. Today was a good day. Today I wrote my first object-oriented Python script <em>from scratch</em> . And it works. It&#8217;s not much, about a 100-line geoprocessing script; but it works. And I understand it and now realize how much easier this makes programming in Python. Look out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/04/23/oops/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Move to WebFaction</title>
		<link>http://www.super-cooper.com/archive/2008/04/23/move-to-webfaction/</link>
		<comments>http://www.super-cooper.com/archive/2008/04/23/move-to-webfaction/#comments</comments>
		<pubDate>Thu, 24 Apr 2008 02:49:35 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[hosting]]></category>

		<guid isPermaLink="false">http://www.super-cooper.com/?p=53</guid>
		<description><![CDATA[Finding the right Web host isn&#8217;t easy. Google &#34;&#60;web host name&#62; review&#34; for virtually any host out there, and you will find a plethora of both positive and negative feedback. Chances are, you&#8217;re going to find more negative feedback than positive just about every time. A month or so ago, when I was looking for [...]]]></description>
			<content:encoded><![CDATA[<p>Finding the right Web host isn&#8217;t easy. Google &quot;&lt;web host name&gt; review&quot; for virtually any host out there, and you will find a plethora of both positive and negative feedback. Chances are, you&#8217;re going to find more negative feedback than positive just about every time. A month or so ago, when I was looking for a Web host for super-cooper.com, I spent alot, and I mean <em>alot</em> of time researching Web hosts. Apparently I didn&#8217;t do that great of a job the first time around. I chose <a href="http://www.anhosting.com/">AN Hosting</a> , mostly because they were recommended by WordPress (although rumor has it that the WP folks get a kickback from those recommendations, which would not surprise me at all) and also because the number of negative reviews I found about them was small. Don&#8217;t get me wrong, the service was OK, and their plans are well-stocked, but the reliability and the speed just weren&#8217;t there. So last week, when I came across <a href="http://www.protocolostomy.com/2008/04/16/need-a-new-web-host/">Brian&#8217;s post</a> where he asked for options on a new host, I realized from the comments that I had to look into <a href="http://www.webfaction.com/">WebFaction</a> &#8211; almost everyone who commented on his post recommended them. So I decided to switch. What a charm. Sign up was a breeze, and boy is this site faster. WebFaction claims to not &quot;max out&quot; their servers, and so far, I believe them. The list of what they provide is unique, so go <a href="http://www.webfaction.com/services/hosting">check it out</a> . I&#8217;m really dyin&#8217; to get my <a href="http://code.djangoproject.com/wiki/GeoDjango">GeoDjango</a> on&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/04/23/move-to-webfaction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mapping point locations with Python and Microsoft Live Search Maps</title>
		<link>http://www.super-cooper.com/archive/2008/04/15/mapping-point-locations-with-python-and-microsoft-live-search-maps/</link>
		<comments>http://www.super-cooper.com/archive/2008/04/15/mapping-point-locations-with-python-and-microsoft-live-search-maps/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 03:04:43 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[gis]]></category>
		<category><![CDATA[publications]]></category>
		<category><![CDATA[pymag]]></category>

		<guid isPermaLink="false">http://super-cooper.com/2008/04/15/mapping-point-locations-with-python-and-microsoft-live-search-maps/</guid>
		<description><![CDATA[This article was first published in the February 2008 issue of Python Magazine . It is being reproduced here with the permission of Marco Tabini and Associates . Requirements Python 2.4+ pyExcelerator module (http://sourceforge.net/projects/pyexcelerator/ ) Anthony Tuininga&#8217;s ceODBC module (http://sourceforge.net/html/ceODBC.html ) John Machin&#8217;s xlrd module (http://www.lexicon.net/sjmachin/xlrd.htm ) Michael Foord&#8217;s cgiutils module (http://www.voidspace.org.uk/python/cgiutils.html ) Lets face [...]]]></description>
			<content:encoded><![CDATA[<p><em><strong>This article was first published in the <a href="http://pymag.phparch.com/c/issue/view/68">February 2008</a> issue of <a href="http://pymag.phparch.com/">Python Magazine</a> . It is being reproduced here with the permission of <a href="http://tabini.ca/">Marco Tabini and Associates</a> .</strong> </em></p>
<p><strong>Requirements</strong></p>
<p>Python 2.4+<br />
pyExcelerator module (<a href="http://sourceforge.net/projects/pyexcelerator/">http://sourceforge.net/projects/pyexcelerator/</a> )<br />
Anthony Tuininga&#8217;s ceODBC module (<a href="http://sourceforge.net/html/ceODBC.html">http://sourceforge.net/html/ceODBC.html</a> )<br />
John Machin&#8217;s xlrd module (<a href="http://www.lexicon.net/sjmachin/xlrd.htm">http://www.lexicon.net/sjmachin/xlrd.htm</a> )<br />
Michael Foord&#8217;s cgiutils module (<a href="http://www.voidspace.org.uk/python/cgiutils.html">http://www.voidspace.org.uk/python/cgiutils.html</a> )</p>
<p><strong>Lets face it, using Python, we can pull data from virtually anywhere in the corporate enterprise &#8211; databases, text files, or other documents. But how can we easily visualize data that has <em>place</em> associated with it? Well, we turn to Python and the API of a popular web-mapping application, that&#8217;s how.</strong></p>
<p><span id="more-50"></span></p>
<p>I was recently tasked with finding a way to routinely (read daily) present a dataset of point locations on a onscreen map to our team of 40 or so people. <a href="http://www.super-cooper.com/images/pymag/figure1.jpg" rel="lightbox[50]"><img class="left" src="http://farm4.static.flickr.com/3035/2417154257_f1ff68e5c4_m.jpg" alt="figure1" width="240" height="195" /> </a> I needed a way to easily disseminate some sort of map product that would display the data, something that required no special software setup on PCs &#8211; and most importantly &#8211; something that would be easy and intuitive for our team members to use. I thought about providing a PDF map product &#8211; I would have to harvest the data, process it, plot it on a map using mapping software, and email the final product to my team members as an attachment. Doesn&#8217;t sound like much fun, does it? Oh, and did I mention that those would all be <em>manual</em> processes to be completed once per day? While pondering this not-so-desirable methodology, I ran across a clever method used by our Information Technology team that passed locational data in a URL to Microsoft Live Maps. Their process takes point locations (in the form of latitude and longitude) from SQL Server, and using VB.Net and the Microsoft Live Search Maps URL API, builds a URL that plots well locations on a Live Search Maps web map. This was it, I would harvest the data, process it, build my URL using the Live Search Maps URL API, and send out the URL to my team nightly in a email. And I would do all of this using Python.</p>
<p><strong>Example dataset</strong></p>
<p>The dataset I needed to map is a gas well drilling schedule stored in a Microsoft Office Excel 2003 workbook. Rows in the workbook represent natural gas wells on the schedule and each has attributes associated with it such as well name, latitude, longitude, and the date drilling commenced; or spud date, as it is called in the oil and gas industry. The schedule gets updated at least daily, and in this line of business, plans can change every hour &#8211; literally. However, it was decided that a process that mapped the locations of the wells on a daily basis would suffice. Also note that, as will be demonstrated later, you don&#8217;t necessarily need point locations with latitude and longitude to  benefit from this process; address locations can be used also.</p>
<p><strong>Choosing a web mapping application<em></em> </strong></p>
<p>When first exploring the option of using a existing web mapping service to plot my well locations, I looked into most of the popular services out there: Google Maps (http://maps.google.com/, my personal favorite for the up-to-date aerial photography and ability to save your own maps, among other things), Yahoo! Maps (http://maps.yahoo.com/), and Microsoft Live Search Maps (http://maps.live.com/ &#8211; Figure 1). As stated earlier, our IT team had chosen Live Search Maps for an earlier application, and I soon learned the reason in doing so is that at the time, Live Search Maps was the only service out there which provided the ability to pass in multiple point locations to plot via latitude and longitude through the URL string. This was very important to the process, as I want to simply pass in all of my well locations through the URL, and then provide this URL to my team members.</p>
<p><strong>Features of Microsoft Live Search Maps</strong></p>
<p>Aside from the already-discussed feature  of passing in multiple locations through the URL string, another great feature of Live Search Maps is the Scratch Pad &#8211; think of it as a &quot;table of contents&quot; for your map (Figure 2). <a href="http://www.super-cooper.com/images/pymag/figure2.png" rel="lightbox[50]"><img class="left" src="http://farm3.static.flickr.com/2260/2417972484_a718030ff0_m.jpg" alt="figure2" width="164" height="240" /> </a> The URL API (which will be discussed shortly) provides us the ability to create a scratch pad which lists each item and a description in a list on the right side of our map. Users can then see a scrollable list of all items that are currently plotted on the map. Also included in the Scratch Pad is the ability to zoom to street, city, or regional levels, send a location in an email, or obtain driving directions to or from a location. No other mapping service was able to provide these capabilities. So using Live Search Maps, my team members would be provided with a somewhat &quot;traditional&quot; web mapping interface that would be easy and intuitive to use, and with the Scratch Pad, they would be given a list of the mapped locations as well as the point locations plotted on the map.</p>
<p><strong>Microsoft Live Search Maps URL API</strong></p>
<p>The Live Search Maps Online Help (<a href="http://help.live.com/Help. aspx?market=en-US&amp;project=WL_Local&amp;querytype=topic&amp;query=WL_ LOCAL_PROC_BuildURL.htm">http://help.live.com/Help. aspx?market=en-US&amp;project=WL_Local&amp;querytype=topic&amp;query=WL_ LOCAL_PROC_BuildURL.htm</a> ) provides us with full documentation to the Live Search Maps URL API. I won&#8217;t go over everything, but I will cover what parts this process uses to build a URL &#8211; you can read the rest at your leisure. The API is fairly simple and straightforward. The first step is to build your standard Live Search Maps URL base &#8211; it&#8217;s always the same:</p>
<p><code>http://maps.live.com/default.aspx?</code></p>
<p>Next, you start to add your parameters. For us, that means set the map style. There are four options to choose from: aerial photo (a), road map (r), hybrid &#8211; aerial photo with labels and some roads (h), and oblique &#8211; commonly referred to as &quot;bird&#8217;s eye view&quot; (o). For this application I decided to use the road map view, since it would provide towns, cities, and major roads &#8211; all labeled &#8211; for users to orient themselves by:</p>
<p><code>http://maps.live.com/default.aspx?style=r</code></p>
<p>Next, we start to define and add our custom annotations to pass in and add to the Scratch Pad. For annotations, the form is:</p>
<p><code>sp=an.latitude_longitude_title_description</code></p>
<p>Latitude and longitude are obviously the locational information for the well, and you are given the option of adding a title and description (they end up on different lines in the scratch pad). So our URL now becomes something like so for the USA 1-18 well set to spud on 11/12/2007 and drilled by rig Smith #2 (note the encoding values used for the dash in the well name and the pound symbol in the rig name &#8211; don&#8217;t forget to encode all of your special characters in your URL string):</p>
<p><code><a href="http://maps.live.com/default.aspx?style=r&amp;sp=an.35.265638147_-93.5877380077_USA%201-18_11/12/2007%20-%20Smith%202">http://maps.live.com/default.aspx?style=r&amp;sp=an.35.265638147_-93.5877380077_USA%201-18_11/12/2007%20-%20Smith%202</a> </code></p>
<p>Basically, thats it! Copy and paste the URL above into your web browser and you will get a Live Search Maps map with the USA 1-18 well on the map and in the Scratch Pad. To add additional point locations to the URL, simply add a tilde and the next custom annotation(s):</p>
<p><code><a href="http://maps.live.com/default.aspx?style=r&amp;sp=an.35.265638147_-93.5877380077_USA%201-18_11/12/2007%20-%20Smith%202~an.35.0878763351_-93.5096775211_Jones%2013-13_11/01/2007%20-%20Smith%2035">http://maps.live.com/default.aspx?style=r&amp;sp=an.35.265638147_-93.5877380077_USA%201-18_11/12/2007%20-%20Smith<br />
%202~an.35.0878763351_-93.5096775211_Jones%2013-13_11/01/2007%20-%20Smith%2035</a> </code></p>
<p><strong>Harvesting and processing the Excel data</strong></p>
<p>Before we can build our map, we have to get the data out of our Excel workbook. As Figure 3 shows, the worksheet layout is fairly simple. The columns represent, from left to right, well name, spud date (date the well started drilling), total depth, or TD date (the date the well finished drilling and reached total depth), latitude, longitude, and drilling rig number. To harvest our data from the workbook, we will enlist the help of the <strong>PyExcelerator</strong> module (<a href="http://sourceforge.net/projects/pyexcelerator">http://sourceforge.net/projects/pyexcelerator</a> ) and a function that comes with the docs &#8211; which worked right out of the box! Essentially we read the Excel workbook and return a list of lists, where each nested list represents a row in our worksheet. The entire function for parsing the Excel workbook can be found in Listing 1.</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #0008E6;font-weight:bold;">import</span> pyExcelerator, <span style="color: #990000;">os</span>, <span style="color: #990000;">time</span>, <span style="color: #990000;">string</span>, <span style="color: #990000;">calendar</span>, <span style="color: #990000;">datetime</span></code></li>
<li value="2" class="tab0 even"><code><span style="color: #0008E6;font-weight:bold;">import</span> <span style="color: #990000;">smtplib</span>, cgiutils, xldate, DateTime, EmailRecips</code></li>
<li value="3" class="odd">&nbsp;</li>
<li value="4" class="tab0 even"><code><span style="color: #990000;font-weight:bold;">def</span> ExcelToList<span style="color: black;">&#40;</span>fname, worksheet=<span style="color: #FF0000; font-weight: bold;">0</span>, encoding=<span style="color: #2DB300;">'cp1251'</span><span style="color: black;">&#41;</span>:</code></li>
<li value="5" class="tab1 odd"><code>data = pyExcelerator.<span style="color: black;">parse_xls</span><span style="color: black;">&#40;</span>fname,encoding<span style="color: black;">&#41;</span></code></li>
<li value="6" class="tab1 even"><code>sheet_name=data<span style="color: black;">&#91;</span>worksheet<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">encode</span><span style="color: black;">&#40;</span>encoding<span style="color: black;">&#41;</span></code></li>
<li value="7" class="tab1 odd"><code>values = data<span style="color: black;">&#91;</span>worksheet<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span></code></li>
<li value="8" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> each <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:</code></li>
<li value="9" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">print</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span>:<span style="color: #FF0000; font-weight: bold;">-1</span><span style="color: black;">&#93;</span></code></li>
<li value="10" class="tab1 even"><code>vdict = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span></code></li>
<li value="11" class="tab1 odd"><code>row_idx_max = <span style="color: #FF0000; font-weight: bold;">0</span></code></li>
<li value="12" class="tab1 even"><code>col_idx_max = <span style="color: #FF0000; font-weight: bold;">0</span></code></li>
<li value="13" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> row_idx, col_idx <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>values.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:</code></li>
<li value="14" class="tab2 even"><code>row_idx_max = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>row_idx,row_idx_max<span style="color: black;">&#41;</span></code></li>
<li value="15" class="tab2 odd"><code>col_idx_max = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>col_idx,col_idx_max<span style="color: black;">&#41;</span></code></li>
<li value="16" class="tab2 even"><code>v = values<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row_idx, col_idx<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></code></li>
<li value="17" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>v, <span style="color: #008000;">unicode</span><span style="color: black;">&#41;</span>:</code></li>
<li value="18" class="tab3 even"><code>v = v.<span style="color: black;">encode</span><span style="color: black;">&#40;</span>encoding, <span style="color: #2DB300;">'backslashreplace'</span><span style="color: black;">&#41;</span></code></li>
<li value="19" class="tab2 odd"><code>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row_idx,col_idx<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> = v</code></li>
<li value="20" class="tab1 even"><code>vlist = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="21" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> row <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>row_idx_max<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span>:</code></li>
<li value="22" class="tab2 even"><code>vlist.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="23" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> col <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>col_idx_max<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span>:</code></li>
<li value="24" class="tab3 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span> <span style="color: #0008E6;font-weight:bold;">not</span> <span style="color: #0008E6;font-weight:bold;">in</span> vdict:</code></li>
<li value="25" class="tab4 odd"><code>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>=<span style="color: #008000;">None</span></code></li>
<li value="26" class="tab3 even"><code>vlist<span style="color: black;">&#91;</span>row<span style="color: black;">&#93;</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="27" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">return</span> vlist</code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/pymag/listing1.txt">listing1.txt</a></li>
</ol>
<p><a href="http://www.super-cooper.com/images/pymag/figure3.png" rel="lightbox[50]"><img class="left" src="http://farm4.static.flickr.com/3174/2417972468_ec4c259180_m.jpg" alt="figure3" width="240" height="112" /> </a></p>
<p>The first step in <strong>ExcelToList</strong> utilizes the parse_xls method of pyExcelerator, which returns a list of two-tuples; one tuple for each worksheet in the workbook where each tuple consists of the worksheet name and worksheet data. The worksheet data is a dictionary mapping each non-blank cell to its cell value:</p>
<p><code>import pyExcelerator, os, time, string, calendar, datetime,<br />
import smtplib, cgiutils, xldate, DateTime<br />
data = pyExcelerator.parse_xls(filename, encoding)</code></p>
<p>Which returns:</p>
<p><code>[('Sheet1', {(0, 1): 39412.0,<br />
(1, 2): 39437.0,<br />
(2, 4): -93.600387566799995,<br />
(0, 0): 'Smith #2-3',<br />
(2, 0): 'Coop #4-17',<br />
(2, 2): 39452.0,<br />
(1, 4): -94.856870378300002,<br />
(1, 1): 39421.0,<br />
(1, 5): 'Rig 4',<br />
(1, 3): 34.831162240499999,<br />
(0, 5): 'Rig 67',<br />
(2, 1): 39431.0,<br />
(2, 5): 'Rig 23',<br />
(0, 4): -97.340309266600002,<br />
(1, 0): 'Jones #1-19',<br />
(2, 3): 35.232594439099998,<br />
(0, 3): 35.276017337600003,<br />
(0, 2): 39430.0}),<br />
('Sheet2', {}),<br />
('Sheet3', {})]</code></p>
<p>Note that we returned a three-item list, but the dictionaries for Sheets 2 and 3 are empty, as there is no data in those worksheets. From this we get the dictionary for the worksheet we want out of the list data (where <code>worksheet=0</code> ):</p>
<p><code>values = data[worksheet][1]</code></p>
<p>Which returns:</p>
<p><code>{(0, 1): 39412.0,<br />
(1, 2): 39437.0,<br />
(2, 4): -93.600387566799995,<br />
(0, 0): 'Smith #2-3',<br />
(2, 0): 'Coop #4-17',<br />
(2, 2): 39452.0,<br />
(1, 4): -94.856870378300002,<br />
(1, 1): 39421.0,<br />
(1, 5): 'Rig 4',<br />
(1, 3): 34.831162240499999,<br />
(0, 5): 'Rig 67',<br />
(2, 1): 39431.0,<br />
(2, 5): 'Rig 23',<br />
(0, 4): -97.340309266600002,<br />
(1, 0): 'Jones #1-19',<br />
(2, 3): 35.232594439099998,<br />
(0, 3): 35.276017337600003,<br />
(0, 2): 39430.0}</code></p>
<p>Sorted, it&#8217;s much easier to see what&#8217;s going on:</p>
<p><code>for each in sorted(data[0][1].items()):<br />
print str(each)[1:-1]</code></p>
<p><code>(0, 0), 'Smith #2-3'<br />
(0, 1), 39412.0<br />
(0, 2), 39430.0<br />
(0, 3), 35.276017337600003<br />
(0, 4), -97.340309266600002<br />
(0, 5), 'Rig 67'<br />
(1, 0), 'Jones #1-19'<br />
(1, 1), 39421.0<br />
(1, 2), 39437.0<br />
(1, 3), 34.831162240499999<br />
(1, 4), -94.856870378300002<br />
(1, 5), 'Rig 4'<br />
(2, 0), 'Coop #4-17'<br />
(2, 1), 39431.0<br />
(2, 2), 39452.0<br />
(2, 3), 35.232594439099998<br />
(2, 4), -93.600387566799995<br />
(2, 5), 'Rig 23'</code></p>
<p>Here again, keys represent the cell mappings (Excel cell <code>A1 = (0,0)</code> ) and values represent the data within the cell. Next, we iterate through our <strong>values</strong> object, putting our key/value cell reference/cell value pairs into the <strong>vdict</strong> object and getting the maximum number of rows and colums (lines 10-19, Listing 1):</p>
<p>Here, our max is 2 rows and 5 columns, since it is zero- based. Finally, we iterate through our <strong>vdict</strong> object, converting it to a two-dimensional list with each list item representing a row in our Excel worksheet. Blank cells are represented by <code>None</code> :</p>
<p><code>vlist = []<br />
for row in range(row_idx_max+1):<br />
vlist.append([])<br />
for col in range(col_idx_max+1):<br />
if (row,col) not in vdict:<br />
vdict[(row,col)]=None<br />
vlist[row].append(vdict[(row,col)])</code></p>
<p>Our end product returned from <strong>ExcelToList</strong> looks like so:</p>
<p><code>[['Smith #2-3', 39412.0, 39430.0, 35.276017337600003, -97.340309266600002, 'Rig 67'],<br />
['Jones #1-19', 39421.0, 39437.0, 34.831162240499999, -94.856870378300002, 'Rig 4'],<br />
['Coop #4-17', 39431.0, 39452.0, 35.232594439099998, -93.600387566799995, 'Rig 23']]</code></p>
<p>Now we have a nice list that we can simply iterate through and process later.</p>
<p><strong>But Wait a Minute! My Data is in <em>&lt;insert your database engine here&gt;</em> ! How do I get it out to use for something like this?</strong></p>
<p>Never fear, if your data is in a RDBMS, you&#8217;re actually better off. If you don&#8217;t already have it, head on over to SourceForge and pick up Anthony Tuininga&#8217;s great ODBC module <strong>ceODBC</strong> (<a href="http://ceodbc.sourceforge.net/html/ceODBC.html">http://ceodbc.sourceforge.net/html/ceODBC.html</a> ) that will allow you to connect to your database. I tested it on SqlServer and DB2 with great success. Listing 2 demostrates how to use ceODBC with SqlServer.</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #0008E6;font-weight:bold;">import</span> ceODBC</code></li>
<li value="2" class="tab0 even"><code><span style="color: #66cc66;">&gt;&gt;&gt;</span> db=ceODBC.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'DSN=Wells'</span><span style="color: black;">&#41;</span></code></li>
<li value="3" class="tab0 odd"><code><span style="color: #66cc66;">&gt;&gt;&gt;</span> c=db.<span style="color: black;">cursor</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="4" class="tab0 even"><code><span style="color: #66cc66;">&gt;&gt;&gt;</span> c.<span style="color: black;">execute</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'select wellname, latitudedecimal,</span></code></li>
<li value="5" class="tab0 odd"><code>... <span style="color: black;">longitudedecimal</span> <span style="color: #0008E6;font-weight:bold;">from</span> dbo.<span style="color: black;">wells</span> where wellid <span style="color: #0008E6;font-weight:bold;">in</span></code></li>
<li value="6" class="tab0 even"><code>... <span style="color: black;"><span style="color: black;">&#40;</span></span><span style="color: #FF0000; font-weight: bold;">11587</span>,<span style="color: #FF0000; font-weight: bold;">11194</span>,<span style="color: #FF0000; font-weight: bold;">11157</span><span style="color: black;">&#41;</span><span style="color: #2DB300;">')</span></code></li>
<li value="7" class="tab0 odd"><code><span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #0008E6;font-weight:bold;">for</span> each <span style="color: #0008E6;font-weight:bold;">in</span> c.<span style="color: black;">fetchall</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:</code></li>
<li value="8" class="tab0 even"><code>... &nbsp; &nbsp; <span style="color: #0008E6;font-weight:bold;">print</span> each</code></li>
<li value="9" class="tab0 odd"><code>...</code></li>
<li value="10" class="tab0 even"><code><span style="color: black;">&#40;</span><span style="color: #2DB300;">'GILL #1-18'</span>, <span style="color: #FF0000; font-weight: bold;">33.095599</span>, <span style="color: #FF0000; font-weight: bold;">-92.38563</span><span style="color: black;">&#41;</span></code></li>
<li value="11" class="tab0 odd"><code><span style="color: black;">&#40;</span><span style="color: #2DB300;">'HOW #2-7'</span>, <span style="color: #FF0000; font-weight: bold;">35.10155</span>, <span style="color: #FF0000; font-weight: bold;">-91.48824</span><span style="color: black;">&#41;</span></code></li>
<li value="12" class="tab0 even"><code><span style="color: black;">&#40;</span><span style="color: #2DB300;">'JKK #11-13'</span>, <span style="color: #FF0000; font-weight: bold;">34.09130</span>, <span style="color: #FF0000; font-weight: bold;">-93.45256</span><span style="color: black;">&#41;</span></code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/pymag/listing2.txt">listing2.txt</a></li>
</ol>
<p>This method employs a User DSN I created in the Windows ODBC Administator which uses my Windows credentials to log on to SqlServer. Of course, there are a plethora of database connectivity modules out there, so use whichever you want.</p>
<p><strong>Building the Live Search Maps URL</strong></p>
<p>Now that we have all of our data from the Excel workbook (or RDBMS), we can use it to build Scratch Pad annotations and eventually our URL. Based on the URL API, this looks easy enough, but let&#8217;s perform a few other litle tricks that will make things display much nicer in the Scratch Pad. First, we need to set our URL base:</p>
<p><code>urlBase = 'http://maps.live.com/default.aspx?style=r'</code></p>
<p>Now we need to iterate through our well data list from our Excel workbook, place the list items into namespaces and perform some processing on some of them, then build a annotation string from each one. There are two functions we should discuss first. You may have noticed earlier that after we slurp our data out of our Excel workbook, we are left with date values that look like <strong>39430.0</strong> and <strong>39452.0</strong> . Huh? Many of you will recognize these as Excel dates. Excel stores dates as floating point numbers; the number of days (or fraction thereof) since 12/31/1899, to be exact. For example, 9/20/2006 is actually 38980 to Excel; Excel just formats it to look like a date for simplicity of viewing. To deal with Excel dates and turn them into something I could actually use, I turned to the <strong>xlrd</strong> module (<a href="http://www.lexicon.net/sjmachin/xlrd.htm">http://www.lexicon.net/sjmachin/xlrd.htm</a> ) and its function xldate_as_tuple. Also, to get the well status, we assume that anytime today&#8217;s date falls within the window greater than or equal to spud date (beginning of drilling) and less than or equal to td date (end of drilling), that well is currently drilling. We&#8217;d like to know this and denote it in the Scratch Pad, so we determine each wells status. And if indeed the well is drilling, we note it in our annotation (Listing 3).</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> GetWellStatus<span style="color: black;">&#40;</span>inSpudDt, inPrjTdDt<span style="color: black;">&#41;</span>:</code></li>
<li value="2" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>inSpudDt<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #FF0000; font-weight: bold;">0</span> <span style="color: #0008E6;font-weight:bold;">and</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>inPrjTdDt<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #FF0000; font-weight: bold;">0</span>:</code></li>
<li value="3" class="tab2 odd"><code>today1 = <span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%m/%d/%Y'</span>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="4" class="tab2 even"><code>today = <span style="color: black;">&#40;</span><span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,</code></li>
<li value="5" class="tab5 odd"><code><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,</code></li>
<li value="6" class="tab5 even"><code><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="7" class="tab2 odd"><code>spudDt = <span style="color: black;">&#40;</span><span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span>inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>,</code></li>
<li value="8" class="tab6 even"><code>inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="9" class="tab2 odd"><code>prjTdDt = <span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span>inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>,inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,</code></li>
<li value="10" class="tab8 even"><code>inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="11" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> today <span style="color: #66cc66;">&gt;</span> prjTdDt:</code></li>
<li value="12" class="tab3 even"><code>status = <span style="color: #2DB300;">'Drilled'</span></code></li>
<li value="13" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">elif</span> today <span style="color: #66cc66;">&gt;</span>= spudDt <span style="color: #0008E6;font-weight:bold;">and</span> today <span style="color: #66cc66;">&lt;</span>= prjTdDt:</code></li>
<li value="14" class="tab3 even"><code>status = <span style="color: #2DB300;">'Drilling'</span></code></li>
<li value="15" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">elif</span> today <span style="color: #66cc66;">&lt;</span> spudDt:</code></li>
<li value="16" class="tab3 even"><code>status = <span style="color: #2DB300;">'Proposed'</span></code></li>
<li value="17" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="18" class="tab3 even"><code>status = <span style="color: #2DB300;">'Unknown'</span></code></li>
<li value="19" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="20" class="tab2 even"><code>status = <span style="color: #2DB300;">'Undeterminable'</span></code></li>
<li value="21" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">return</span> status</code></li>
<li value="22" class="even">&nbsp;</li>
<li value="23" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> KillObject<span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span>:</code></li>
<li value="24" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span>:</code></li>
<li value="25" class="tab2 odd"><code><span style="color: #990000;">os</span>.<span style="color: black;">remove</span><span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span></code></li>
<li value="26" class="even">&nbsp;</li>
<li value="27" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> WriteOutput<span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, text<span style="color: black;">&#41;</span>:</code></li>
<li value="28" class="tab1 even"><code>writer = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, <span style="color: #2DB300;">'a'</span><span style="color: black;">&#41;</span></code></li>
<li value="29" class="tab1 odd"><code>writer.<span style="color: black;">write</span><span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span></code></li>
<li value="30" class="even">&nbsp;</li>
<li value="31" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> BuildLiveMapsUrl<span style="color: black;">&#40;</span>wells, ds<span style="color: black;">&#41;</span>:</code></li>
<li value="32" class="tab1 even"><code>urlBase = <span style="color: #2DB300;">'http://maps.live.com/default.aspx?style=r'</span></code></li>
<li value="33" class="tab1 odd"><code>wholeList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="34" class="tab1 even"><code><span style="color: #008000;">dict</span> = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span></code></li>
<li value="35" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> well <span style="color: #0008E6;font-weight:bold;">in</span> wells:</code></li>
<li value="36" class="tab2 even"><code>eachList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="37" class="tab2 odd"><code>name = <span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">' '</span>,<span style="color: #2DB300;">'%20'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'#'</span>,<span style="color: #2DB300;">'%23'</span><span style="color: black;">&#41;</span></code></li>
<li value="38" class="tab2 even"><code>spudDateTuple = xldate.<span style="color: black;">xldate_as_tuple</span><span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,<span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#41;</span></code></li>
<li value="39" class="tab2 odd"><code>spudDate = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="40" class="tab2 even"><code>tdDateTuple = xldate.<span style="color: black;">xldate_as_tuple</span><span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span>,<span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#41;</span></code></li>
<li value="41" class="tab2 odd"><code>tdDate = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="42" class="tab2 even"><code>lat = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">3</span><span style="color: black;">&#93;</span></code></li>
<li value="43" class="tab2 odd"><code><span style="color: #008000;">long</span> = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">4</span><span style="color: black;">&#93;</span></code></li>
<li value="44" class="tab2 even"><code>rig = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">5</span><span style="color: black;">&#93;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">' '</span>,<span style="color: #2DB300;">'%20'</span><span style="color: black;">&#41;</span></code></li>
<li value="45" class="tab2 odd"><code>status = GetWellStatus<span style="color: black;">&#40;</span>spudDateTuple, tdDateTuple<span style="color: black;">&#41;</span></code></li>
<li value="46" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> status == <span style="color: #2DB300;">'Drilling'</span>:</code></li>
<li value="47" class="tab3 odd"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'an.'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lat<span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">long</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + name + <span style="color: #2DB300;">'_'</span> + spudDate +</code></li>
<li value="48" class="tab3 even"><code><span style="color: #2DB300;">'%20-%20'</span> + rig + <span style="color: #2DB300;">'%20-%20'</span> + status.<span style="color: black;">upper</span><span style="color: black;">&#41;</span></code></li>
<li value="49" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="50" class="tab3 even"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'an.'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lat<span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">long</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + name + <span style="color: #2DB300;">'_'</span> + spudDate +</code></li>
<li value="51" class="tab3 odd"><code><span style="color: #2DB300;">'%20-%20'</span> + rig<span style="color: black;">&#41;</span></code></li>
<li value="52" class="tab2 even"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>spudDate<span style="color: black;">&#41;</span></code></li>
<li value="53" class="tab2 odd"><code>wholeList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>eachList<span style="color: black;">&#41;</span></code></li>
<li value="54" class="tab1 even"><code>wholeList.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: #0008E6;font-weight:bold;">lambda</span> x,y:<span style="color: #008000;">cmp</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,y<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="55" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> whole <span style="color: #0008E6;font-weight:bold;">in</span> wholeList:</code></li>
<li value="56" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">print</span> whole</code></li>
<li value="57" class="tab1 odd"><code>urlList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="58" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> each <span style="color: #0008E6;font-weight:bold;">in</span> wholeList:</code></li>
<li value="59" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">del</span> each<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span></code></li>
<li value="60" class="tab2 even"><code>wellString = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span>:<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: #FF0000; font-weight: bold;">-3</span><span style="color: black;">&#93;</span></code></li>
<li value="61" class="tab2 odd"><code>urlList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>wellString<span style="color: black;">&#41;</span></code></li>
<li value="62" class="tab1 even"><code>urlStringWells = <span style="color: #990000;">string</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>urlList,<span style="color: #2DB300;">'~'</span><span style="color: black;">&#41;</span></code></li>
<li value="63" class="tab1 odd"><code>masterUrl = urlBase + <span style="color: #2DB300;">'&amp;sp='</span> + urlStringWells + <span style="color: #2DB300;">'~an.36.1164211465469_-94.143074863021_SEECO%</span></code></li>
<li value="64" class="tab1 even"><code>20Fayetteville<span style="color: #66cc66;">%</span>20Office~an<span style="color: #FF0000; font-weight: bold;">.35</span>.513123_<span style="color: #FF0000; font-weight: bold;">-93</span>.834189_SWN<span style="color: #66cc66;">%</span>20Ozark<span style="color: #66cc66;">%</span>20Office~an<span style="color: #FF0000; font-weight: bold;">.35</span>.0685432008022_</code></li>
<li value="65" class="tab1 odd"><code><span style="color: #FF0000; font-weight: bold;">-92</span>.4189197874021_SWN<span style="color: #66cc66;">%</span>20Conway<span style="color: #66cc66;">%</span>20Office~an.<span style="color: #2DB300;">'</span></code></li>
<li value="66" class="tab1 even"><code>f = <span style="color: #2DB300;">'C:/temp/DS_Html_Email.html'</span></code></li>
<li value="67" class="tab1 odd"><code>t = <span style="color: #2DB300;">'C:/temp/DS_Text_Email.txt'</span></code></li>
<li value="68" class="tab1 even"><code>dsUpdated = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y, %I:%M %p'</span>, <span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">getmtime</span><span style="color: black;">&#40;</span>ds<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="69" class="tab1 odd"><code>KillObject<span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span></code></li>
<li value="70" class="tab1 even"><code>KillObject<span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span></code></li>
<li value="71" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;style type=&quot;text/css&quot;&gt;body,table {font-family:Verdana;<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="72" class="tab4 even"><code>font-size:10pt<span style="color: #66cc66;">;</span>empty-cells: show<span style="color: black;">&#125;</span>\n<span style="color: #66cc66;">&lt;</span>/style<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/head<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;</span>\n<span style="color: #2DB300;">')</span></code></li>
<li value="73" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'&lt;table style=&quot;width: 700px&quot;&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&lt;h3&gt;AAT Drill Schedule Mapper for '</span>\</code></li>
<li value="74" class="tab4 even"><code>+ <span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'&lt;/h3&gt;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span></code></li>
<li value="75" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;Drill schedule last updated: '</span> + dsUpdated + <span style="color: #2DB300;">'&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span>\</code></li>
<li value="76" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&amp;nbsp;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #FF6600;"># empty row</span></code></li>
<li value="77" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&lt;a href=&quot;'</span> + masterUrl + <span style="color: #2DB300;">'&quot;&gt;Click here for a map of the latest<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="78" class="tab4 even"><code>AAT drill schedule<span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;&lt;</span>/td<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/tr<span style="color: #66cc66;">&gt;</span><span style="color: #2DB300;">')</span></code></li>
<li value="79" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&amp;nbsp;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #FF6600;"># empty row</span></code></li>
<li value="80" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;*** THIS MESSAGE AUTO-GENERATED ***&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="81" class="tab4 odd"><code><span style="color: #66cc66;">***</span> PLEASE DO NOT REPLY TO THIS EMAIL <span style="color: #66cc66;">***&lt;</span>/td<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/tr<span style="color: #66cc66;">&gt;</span><span style="color: #2DB300;">')</span></code></li>
<li value="82" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;/table&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/html&gt;'</span><span style="color: black;">&#41;</span></code></li>
<li value="83" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'AAT Drill Schedule Mapper for '</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span>\</code></li>
<li value="84" class="tab4 even"><code>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="85" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Drill schedule last updated: '</span> + dsUpdated<span style="color: black;">&#41;</span></code></li>
<li value="86" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Copy and paste this address into your web broswer:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>'</span> + masterUrl<span style="color: black;">&#41;</span></code></li>
<li value="87" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>** This message auto-generated - please do not respond to this email ***'</span><span style="color: black;">&#41;</span></code></li>
<li value="88" class="even">&nbsp;</li>
<li value="89" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> SendEmail<span style="color: black;">&#40;</span>message, recipients<span style="color: black;">&#41;</span>:</code></li>
<li value="90" class="tab1 even"><code>sender = <span style="color: #2DB300;">'AAT_Drill_Schedule_Mapper'</span></code></li>
<li value="91" class="tab1 odd"><code>server = <span style="color: #990000;">smtplib</span>.<span style="color: black;">SMTP</span><span style="color: black;">&#40;</span>ip_address<span style="color: black;">&#41;</span></code></li>
<li value="92" class="tab1 even"><code>server.<span style="color: black;">sendmail</span><span style="color: black;">&#40;</span>sender, recipients, message<span style="color: black;">&#41;</span></code></li>
<li value="93" class="tab1 odd"><code>server.<span style="color: black;">quit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="94" class="even">&nbsp;</li>
<li value="95" class="tab0 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> __name__ == <span style="color: #2DB300;">'__main__'</span>:</code></li>
<li value="96" class="even">&nbsp;</li>
<li value="97" class="tab1 odd"><code>wells = ExcelToList<span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS.xls'</span><span style="color: black;">&#41;</span></code></li>
<li value="98" class="tab1 even"><code>BuildLiveMapsUrl<span style="color: black;">&#40;</span>wells, <span style="color: #2DB300;">'C:/temp/DS.xls'</span><span style="color: black;">&#41;</span></code></li>
<li value="99" class="tab1 odd"><code><span style="color: #FF6600;"># Build our email, using both HTML and plain-text inputs</span></code></li>
<li value="100" class="tab1 even"><code>fhtml = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS_Html_Email.html'</span>,<span style="color: #2DB300;">'r'</span><span style="color: black;">&#41;</span></code></li>
<li value="101" class="tab1 odd"><code>ftxt = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS_Text_Email.txt'</span>,<span style="color: #2DB300;">'r'</span><span style="color: black;">&#41;</span></code></li>
<li value="102" class="tab1 even"><code>html = fhtml.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="103" class="tab1 odd"><code>text = ftxt.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="104" class="tab1 even"><code>subject = <span style="color: #2DB300;">'AAT Drill Schedule Mapper - '</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>DateTime.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> + DateTime.\</code></li>
<li value="105" class="tab4 odd"><code>RelativeDateTime<span style="color: black;">&#40;</span>days=<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="106" class="tab1 even"><code><span style="color: #FF6600;"># Create the message with both HTML and text formats</span></code></li>
<li value="107" class="tab1 odd"><code>message = cgiutils.<span style="color: black;">createhtmlmail</span><span style="color: black;">&#40;</span>subject, html, text<span style="color: black;">&#41;</span></code></li>
<li value="108" class="tab1 even"><code><span style="color: #FF6600;"># Send the email out</span></code></li>
<li value="109" class="tab1 odd"><code>recips = <span style="color: black;">&#91;</span><span style="color: #2DB300;">'chad_cooper@swn.com'</span><span style="color: black;">&#93;</span> &nbsp;<span style="color: #FF6600;"># for testing</span></code></li>
<li value="110" class="tab1 even"><code><span style="color: #FF6600;">#recips = Dictionaries.aatEmails</span></code></li>
<li value="111" class="tab1 odd"><code>SendEmail<span style="color: black;">&#40;</span>message,recips<span style="color: black;">&#41;</span></code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/pymag/listing3.txt">listing3.txt</a></li>
</ol>
<p>In order to have the wells listed in the Scratch Pad in descending order by spud date (we want the ones drilling the soonest at the top of the list), we will create a list, <strong>eachList</strong> , and add the annotation string and the spud date to this list as items. As we iterate through the wells list, <strong>eachList</strong> gets appended to another list, <strong>wholeList</strong> , which ends up looking like so:</p>
<p><code>['an.35.2760173376_-97.3403092666_Smith%20%232-3_2007/11/21%20-%20Rig%2067%20-%20DRILLING', '2007/11/21'],<br />
['an.34.8311622405_-94.8568703783_Jones #1-19_12/05/2007%20-%20Rig 4', '12/05/2007'],<br />
['an.35.2325944391_-93.6003875668_Coop #4-17_12/15/2007%20-%20Rig 23', '12/15/2007']]</code></p>
<p>Next, we delete the date items from the list, since we no longer need them after the sort. We then build a string from our list elements and add that to our URL base. Finally, we add some of the Southwestern Energy office locations to the end of the URL, so users can get driving directions from any of our offices directly to a well location:</p>
<p><code>urlList = []<br />
for each in wholeList:<br />
del each[1]<br />
wellString = str(each)[3:len(each)-3]<br />
urlList.append(wellString)<br />
urlStringWells = string.join(urlList,'~')<br />
masterUrl=urlBase+'&amp;sp='+urlStringWells+'~an.36.1164211465469_-94.143074863021_SEECO%20Fayetteville%20Office<br />
~an.35.513123_-93.834189_SWN%20Ozark%20Office~an.35.0685432008022_-92.4189197874021_SWN%20Conway%20Office~an.'</code></p>
<p>And our final URL is:</p>
<p><code><a href="http://maps.live.com/default.aspx?style=r&amp;sp=an.35.2760173376_-97.3403092666_Smith%20%232-3_11/21/2007 %20-%20Rig%2067%20-%20DRILLING~an.34.8311622405_-94.8568703783_Jones%20%231-19_12/05/2007%20- %20Rig%204~an.35.2325944391_-93.6003875668_Coop%20%234-17_12/15/2007%20-%20Rig%2023~ an.36.1164211465469_-94.143074863021_SEECO%20Fayetteville%20Office~an.35.513123_-93.834189_SWN% 20Ozark%20Office~an.35.0685432008022_-92.4189197874021_SWN%20Conway%20Office~an.">http://maps.live.com/default.aspx?style=r&amp;sp=an.35.2760173376_-97.3403092666_Smith%20%232-3_11/21/2007<br />
%20-%20Rig%2067%20-%20DRILLING~an.34.8311622405_-94.8568703783_Jones%20%231-19_12/05/2007%20-<br />
%20Rig%204~an.35.2325944391_-93.6003875668_Coop%20%234-17_12/15/2007%20-%20Rig%2023~<br />
an.36.1164211465469_-94.143074863021_SEECO%20Fayetteville%20Office~an.35.513123_-93.834189_SWN%<br />
20Ozark%20Office~an.35.0685432008022_-92.4189197874021_SWN%20Conway%20Office~an.</a> </code></p>
<p>Our next step is to compose our email to send out to the team. In doing this we will write two versions, one for HTML-enabled clients that is styled and contains a clickable link to our map; and one version for text-only enabled email clients. This version is unstyled and provides the entire map URL that can be copy-pasted into a web browser. For our HTML email, we will create a simple HTML file, and write out code to it (Listing 3). Listing 4 shows the HTML output of Listing 3.</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code>&lt;html&gt;</code></li>
<li value="2" class="tab0 even"><code>&lt;head&gt;</code></li>
<li value="3" class="tab0 odd"><code>&lt;style type=&quot;text/css&quot;&gt;body,table {font-family:Verdana;font-size:10pt;empty-cells: show}</code></li>
<li value="4" class="tab0 even"><code>&lt;/style&gt;</code></li>
<li value="5" class="tab0 odd"><code>&lt;/head&gt;</code></li>
<li value="6" class="tab0 even"><code>&lt;body&gt;</code></li>
<li value="7" class="tab0 odd"><code>&lt;table style=&quot;width: 700px&quot;&gt;</code></li>
<li value="8" class="tab0 even"><code>&lt;tr&gt;</code></li>
<li value="9" class="tab0 odd"><code>&lt;td&gt;&lt;h3&gt;AAT Drill Schedule Mapper for Friday, 11/23/2007&lt;/h3&gt;&lt;/td&gt;</code></li>
<li value="10" class="tab0 even"><code>&lt;/tr&gt;</code></li>
<li value="11" class="tab0 odd"><code>&lt;tr&gt;</code></li>
<li value="12" class="tab0 even"><code>&lt;td&gt;Drill schedule last updated: Friday, 11/23/2007, 10:08 PM&lt;/td&gt;</code></li>
<li value="13" class="tab0 odd"><code>&lt;/tr&gt;</code></li>
<li value="14" class="tab0 even"><code>&lt;tr&gt;</code></li>
<li value="15" class="tab0 odd"><code>&lt;td&gt;&amp;nbsp;&lt;/td&gt;</code></li>
<li value="16" class="tab0 even"><code>&lt;/tr&gt;</code></li>
<li value="17" class="tab0 odd"><code>&lt;tr&gt;</code></li>
<li value="18" class="tab0 even"><code>&lt;td&gt;&lt;a href=&quot;http://maps.live.com/default.aspx?style=r&amp;sp=an.35.2760173376_-97.3403092666_</code></li>
<li value="19" class="tab0 odd"><code>Smith%20%232-3_2007/11/21%20-%20Rig%2067%20-%20DRILLING~an.35.2325944391_-93.6003875668_</code></li>
<li value="20" class="tab0 even"><code>Coop%20%234-17_2007/12/15%20-%20Rig%2023~an.34.8311622405_-94.8568703783_Jones%20%231-19_</code></li>
<li value="21" class="tab0 odd"><code>2007/12/5%20-%20Rig%204~an.36.1164211465469_-94.143074863021_SEECO%20Fayetteville%20Office</code></li>
<li value="22" class="tab0 even"><code>~an.35.513123_-93.834189_SWN%20Ozark%20Office~an.35.0685432008022_-92.4189197874021_SWN%20</code></li>
<li value="23" class="tab0 odd"><code>Conway%20Office~an.&quot;&gt;Click here for a map of the latest AAT drill schedule&lt;/a&gt;&lt;/td&gt;</code></li>
<li value="24" class="tab0 even"><code>&lt;/tr&gt;</code></li>
<li value="25" class="tab0 odd"><code>&lt;tr&gt;</code></li>
<li value="26" class="tab0 even"><code>&lt;td&gt;&amp;nbsp;&lt;/td&gt;</code></li>
<li value="27" class="tab0 odd"><code>&lt;/tr&gt;</code></li>
<li value="28" class="tab0 even"><code>&lt;tr&gt;</code></li>
<li value="29" class="tab0 odd"><code>&lt;td&gt;*** THIS MESSAGE AUTO-GENERATED ***&lt;/td&gt;</code></li>
<li value="30" class="tab0 even"><code>&lt;/tr&gt;</code></li>
<li value="31" class="tab0 odd"><code>&lt;tr&gt;</code></li>
<li value="32" class="tab0 even"><code>&lt;td&gt;*** PLEASE DO NOT REPLY TO THIS EMAIL ***&lt;/td&gt;</code></li>
<li value="33" class="tab0 odd"><code>&lt;/tr&gt;</code></li>
<li value="34" class="tab0 even"><code>&lt;/table&gt;</code></li>
<li value="35" class="tab0 odd"><code>&lt;/body&gt;</code></li>
<li value="36" class="tab0 even"><code>&lt;/html&gt;</code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/pymag/listing4.txt">listing4.txt</a></li>
</ol>
<p>Our text version is much simpler:</p>
<p><code>WriteOutput(t,'AAT Drill Schedule Mapper for ' + str(time.strftime('%A, %m/%d/%Y',time.localtime())))<br />
WriteOutput(t,'\n\nDrill schedule last updated: ' + dsUpdated)<br />
WriteOutput(t,'\n\nCopy and paste this address into your web broswer:\n\n' + masterUrl)<br />
WriteOutput(t,'\n\n** This message auto-generated - please do not respond to this email ***') </code></p>
<p>Which provides us with text output of:</p>
<p><code>AAT Drill Schedule Mapper for Friday, 11/23/2007</code></p>
<p><code>Drill schedule last updated: Friday, 11/23/2007, 10:08 PM</code></p>
<p><code>Copy and paste this address into your web broswer:</code></p>
<p><code>http://maps.live.com/default.aspx?style=r&amp;sp=an.35.2760173376_-97.3403092666_Smith%20%232-3_2007/11/21%20-<br />
%20Rig%2067%20-%20DRILLING~an.35.2325944391_-93.6003875668_Coop%20%234-17_2007/12/15%20-%20Rig%<br />
2023~an.34.8311622405_-94.8568703783_Jones%20%231-19_2007/12/5%20-%20Rig%204~an.36.1164211465469_<br />
-94.143074863021_SEECO%20Fayetteville%20Office~an.35.513123_-93.834189_SWN%20Ozark%20Office~an.<br />
35.0685432008022_-92.4189197874021_SWN%20Conway%20Office~an.</code></p>
<p><code>*** This message auto-generated - please do not respond to this email ***</code></p>
<p><strong>Disseminating the map to our team members</strong></p>
<p>Our final step in this process is to send out to the team the email containing the URL to the day&#8217;s drill schedule. To do this I enlisted the help of Michael Foord&#8217;s <strong>cgiutils</strong> module (<a href="http://www.voidspace.org.uk/python/cgiutils.html">http://www.voidspace.org.uk/python/cgiutils.html</a> ) and the <strong>createhtmlmail</strong> function (Listing 3). createhtmlmail takes our html and text files we just created and uses them as inputs to create a mime-message that will render as html or text, depending on the receiving email client. If no html is supplied, then the <strong>htmllib</strong> module is used to guess a text rendering. createhtmlmail returns us a message object which is passed into the <strong>SendEmail</strong> function; which also takes a list of email addresses of our team members as input. To send our email, we simply create a connection to our Outlook Exchange Server and pass in the sender, our list of recipients, and our html/text message to the smtplib.sendmail object. Finally, we terminate the SMTP session and close out the connection.</p>
<p><code>def SendEmail(message, recipients):<br />
sender = 'AAT_Drill_Schedule_Mapper'<br />
server = smtplib.SMTP(ip_address)<br />
server.sendmail(sender, recipients, message)<br />
server.quit()</code></p>
<p>And that&#8217;s it! I run this script as a Scheduled Task on Windows XP every night at 9PM, and a few minutes later, the email goes out to each of our team members (Figure 4). Listing 5 shows the process in its entirety.</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #0008E6;font-weight:bold;">import</span> pyExcelerator, <span style="color: #990000;">os</span>, <span style="color: #990000;">time</span>, <span style="color: #990000;">string</span>, <span style="color: #990000;">calendar</span>, <span style="color: #990000;">datetime</span></code></li>
<li value="2" class="tab0 even"><code><span style="color: #0008E6;font-weight:bold;">import</span> <span style="color: #990000;">smtplib</span>, cgiutils, xldate, DateTime, EmailRecips</code></li>
<li value="3" class="odd">&nbsp;</li>
<li value="4" class="tab0 even"><code><span style="color: #990000;font-weight:bold;">def</span> ExcelToList<span style="color: black;">&#40;</span>fname, worksheet=<span style="color: #FF0000; font-weight: bold;">0</span>, encoding=<span style="color: #2DB300;">'cp1251'</span><span style="color: black;">&#41;</span>:</code></li>
<li value="5" class="tab1 odd"><code>data = pyExcelerator.<span style="color: black;">parse_xls</span><span style="color: black;">&#40;</span>fname,encoding<span style="color: black;">&#41;</span></code></li>
<li value="6" class="tab1 even"><code>sheet_name=data<span style="color: black;">&#91;</span>worksheet<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">encode</span><span style="color: black;">&#40;</span>encoding<span style="color: black;">&#41;</span></code></li>
<li value="7" class="tab1 odd"><code>values = data<span style="color: black;">&#91;</span>worksheet<span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span></code></li>
<li value="8" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> each <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>.<span style="color: black;">items</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:</code></li>
<li value="9" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">print</span> <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span>:<span style="color: #FF0000; font-weight: bold;">-1</span><span style="color: black;">&#93;</span></code></li>
<li value="10" class="tab1 even"><code>vdict = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span></code></li>
<li value="11" class="tab1 odd"><code>row_idx_max = <span style="color: #FF0000; font-weight: bold;">0</span></code></li>
<li value="12" class="tab1 even"><code>col_idx_max = <span style="color: #FF0000; font-weight: bold;">0</span></code></li>
<li value="13" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> row_idx, col_idx <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">sorted</span><span style="color: black;">&#40;</span>values.<span style="color: black;">keys</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>:</code></li>
<li value="14" class="tab2 even"><code>row_idx_max = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>row_idx,row_idx_max<span style="color: black;">&#41;</span></code></li>
<li value="15" class="tab2 odd"><code>col_idx_max = <span style="color: #008000;">max</span><span style="color: black;">&#40;</span>col_idx,col_idx_max<span style="color: black;">&#41;</span></code></li>
<li value="16" class="tab2 even"><code>v = values<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row_idx, col_idx<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span></code></li>
<li value="17" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #008000;">isinstance</span><span style="color: black;">&#40;</span>v, <span style="color: #008000;">unicode</span><span style="color: black;">&#41;</span>:</code></li>
<li value="18" class="tab3 even"><code>v = v.<span style="color: black;">encode</span><span style="color: black;">&#40;</span>encoding, <span style="color: #2DB300;">'backslashreplace'</span><span style="color: black;">&#41;</span></code></li>
<li value="19" class="tab2 odd"><code>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row_idx,col_idx<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span> = v</code></li>
<li value="20" class="tab1 even"><code>vlist = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="21" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> row <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>row_idx_max<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span>:</code></li>
<li value="22" class="tab2 even"><code>vlist.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="23" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> col <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span>col_idx_max<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span>:</code></li>
<li value="24" class="tab3 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span> <span style="color: #0008E6;font-weight:bold;">not</span> <span style="color: #0008E6;font-weight:bold;">in</span> vdict:</code></li>
<li value="25" class="tab4 odd"><code>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span>=<span style="color: #008000;">None</span></code></li>
<li value="26" class="tab3 even"><code>vlist<span style="color: black;">&#91;</span>row<span style="color: black;">&#93;</span>.<span style="color: black;">append</span><span style="color: black;">&#40;</span>vdict<span style="color: black;">&#91;</span><span style="color: black;">&#40;</span>row,col<span style="color: black;">&#41;</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="27" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">return</span> vlist</code></li>
<li value="28" class="even">&nbsp;</li>
<li value="29" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> GetWellStatus<span style="color: black;">&#40;</span>inSpudDt, inPrjTdDt<span style="color: black;">&#41;</span>:</code></li>
<li value="30" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>inSpudDt<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #FF0000; font-weight: bold;">0</span> <span style="color: #0008E6;font-weight:bold;">and</span> <span style="color: #008000;">len</span><span style="color: black;">&#40;</span>inPrjTdDt<span style="color: black;">&#41;</span> <span style="color: #66cc66;">&gt;</span> <span style="color: #FF0000; font-weight: bold;">0</span>:</code></li>
<li value="31" class="tab2 odd"><code>today1 = <span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%m/%d/%Y'</span>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="32" class="tab2 even"><code>today = <span style="color: black;">&#40;</span><span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,</code></li>
<li value="33" class="tab5 odd"><code><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>,</code></li>
<li value="34" class="tab5 even"><code><span style="color: #008000;">int</span><span style="color: black;">&#40;</span>today1.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'/'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="35" class="tab2 odd"><code>spudDt = <span style="color: black;">&#40;</span><span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span>inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>,</code></li>
<li value="36" class="tab6 even"><code>inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,inSpudDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="37" class="tab2 odd"><code>prjTdDt = <span style="color: #990000;">datetime</span>.<span style="color: black;">date</span><span style="color: black;">&#40;</span>inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>,inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,</code></li>
<li value="38" class="tab8 even"><code>inPrjTdDt<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="39" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> today <span style="color: #66cc66;">&gt;</span> prjTdDt:</code></li>
<li value="40" class="tab3 even"><code>status = <span style="color: #2DB300;">'Drilled'</span></code></li>
<li value="41" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">elif</span> today <span style="color: #66cc66;">&gt;</span>= spudDt <span style="color: #0008E6;font-weight:bold;">and</span> today <span style="color: #66cc66;">&lt;</span>= prjTdDt:</code></li>
<li value="42" class="tab3 even"><code>status = <span style="color: #2DB300;">'Drilling'</span></code></li>
<li value="43" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">elif</span> today <span style="color: #66cc66;">&lt;</span> spudDt:</code></li>
<li value="44" class="tab3 even"><code>status = <span style="color: #2DB300;">'Proposed'</span></code></li>
<li value="45" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="46" class="tab3 even"><code>status = <span style="color: #2DB300;">'Unknown'</span></code></li>
<li value="47" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="48" class="tab2 even"><code>status = <span style="color: #2DB300;">'Undeterminable'</span></code></li>
<li value="49" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">return</span> status</code></li>
<li value="50" class="even">&nbsp;</li>
<li value="51" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> KillObject<span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span>:</code></li>
<li value="52" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span>:</code></li>
<li value="53" class="tab2 odd"><code><span style="color: #990000;">os</span>.<span style="color: black;">remove</span><span style="color: black;">&#40;</span>toBeKilled<span style="color: black;">&#41;</span></code></li>
<li value="54" class="even">&nbsp;</li>
<li value="55" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> WriteOutput<span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, text<span style="color: black;">&#41;</span>:</code></li>
<li value="56" class="tab1 even"><code>writer = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, <span style="color: #2DB300;">'a'</span><span style="color: black;">&#41;</span></code></li>
<li value="57" class="tab1 odd"><code>writer.<span style="color: black;">write</span><span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span></code></li>
<li value="58" class="even">&nbsp;</li>
<li value="59" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> BuildLiveMapsUrl<span style="color: black;">&#40;</span>wells, ds<span style="color: black;">&#41;</span>:</code></li>
<li value="60" class="tab1 even"><code>urlBase = <span style="color: #2DB300;">'http://maps.live.com/default.aspx?style=r'</span></code></li>
<li value="61" class="tab1 odd"><code>wholeList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="62" class="tab1 even"><code><span style="color: #008000;">dict</span> = <span style="color: black;">&#123;</span><span style="color: black;">&#125;</span></code></li>
<li value="63" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> well <span style="color: #0008E6;font-weight:bold;">in</span> wells:</code></li>
<li value="64" class="tab2 even"><code>eachList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="65" class="tab2 odd"><code>name = <span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">' '</span>,<span style="color: #2DB300;">'%20'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'#'</span>,<span style="color: #2DB300;">'%23'</span><span style="color: black;">&#41;</span></code></li>
<li value="66" class="tab2 even"><code>spudDateTuple = xldate.<span style="color: black;">xldate_as_tuple</span><span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,<span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#41;</span></code></li>
<li value="67" class="tab2 odd"><code>spudDate = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>spudDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="68" class="tab2 even"><code>tdDateTuple = xldate.<span style="color: black;">xldate_as_tuple</span><span style="color: black;">&#40;</span>well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span>,<span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#41;</span></code></li>
<li value="69" class="tab2 odd"><code>tdDate = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">0</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>+<span style="color: #2DB300;">'/'</span>+<span style="color: #008000;">str</span><span style="color: black;">&#40;</span>tdDateTuple<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span></code></li>
<li value="70" class="tab2 even"><code>lat = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">3</span><span style="color: black;">&#93;</span></code></li>
<li value="71" class="tab2 odd"><code><span style="color: #008000;">long</span> = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">4</span><span style="color: black;">&#93;</span></code></li>
<li value="72" class="tab2 even"><code>rig = well<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">5</span><span style="color: black;">&#93;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">' '</span>,<span style="color: #2DB300;">'%20'</span><span style="color: black;">&#41;</span></code></li>
<li value="73" class="tab2 odd"><code>status = GetWellStatus<span style="color: black;">&#40;</span>spudDateTuple, tdDateTuple<span style="color: black;">&#41;</span></code></li>
<li value="74" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> status == <span style="color: #2DB300;">'Drilling'</span>:</code></li>
<li value="75" class="tab3 odd"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'an.'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lat<span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">long</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + name + <span style="color: #2DB300;">'_'</span> + spudDate +</code></li>
<li value="76" class="tab3 even"><code><span style="color: #2DB300;">'%20-%20'</span> + rig + <span style="color: #2DB300;">'%20-%20'</span> + status.<span style="color: black;">upper</span><span style="color: black;">&#41;</span></code></li>
<li value="77" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">else</span>:</code></li>
<li value="78" class="tab3 even"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'an.'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>lat<span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #008000;">long</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'_'</span> + name + <span style="color: #2DB300;">'_'</span> + spudDate +</code></li>
<li value="79" class="tab3 odd"><code><span style="color: #2DB300;">'%20-%20'</span> + rig<span style="color: black;">&#41;</span></code></li>
<li value="80" class="tab2 even"><code>eachList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>spudDate<span style="color: black;">&#41;</span></code></li>
<li value="81" class="tab2 odd"><code>wholeList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>eachList<span style="color: black;">&#41;</span></code></li>
<li value="82" class="tab1 even"><code>wholeList.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: #0008E6;font-weight:bold;">lambda</span> x,y:<span style="color: #008000;">cmp</span><span style="color: black;">&#40;</span>x<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span>,y<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="83" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> whole <span style="color: #0008E6;font-weight:bold;">in</span> wholeList:</code></li>
<li value="84" class="tab2 even"><code><span style="color: #0008E6;font-weight:bold;">print</span> whole</code></li>
<li value="85" class="tab1 odd"><code>urlList = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="86" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> each <span style="color: #0008E6;font-weight:bold;">in</span> wholeList:</code></li>
<li value="87" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">del</span> each<span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">1</span><span style="color: black;">&#93;</span></code></li>
<li value="88" class="tab2 even"><code>wellString = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">2</span>:<span style="color: #008000;">len</span><span style="color: black;">&#40;</span>each<span style="color: black;">&#41;</span><span style="color: #FF0000; font-weight: bold;">-3</span><span style="color: black;">&#93;</span></code></li>
<li value="89" class="tab2 odd"><code>urlList.<span style="color: black;">append</span><span style="color: black;">&#40;</span>wellString<span style="color: black;">&#41;</span></code></li>
<li value="90" class="tab1 even"><code>urlStringWells = <span style="color: #990000;">string</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>urlList,<span style="color: #2DB300;">'~'</span><span style="color: black;">&#41;</span></code></li>
<li value="91" class="tab1 odd"><code>masterUrl = urlBase + <span style="color: #2DB300;">'&amp;sp='</span> + urlStringWells + <span style="color: #2DB300;">'~an.36.1164211465469_-94.143074863021_SEECO%</span></code></li>
<li value="92" class="tab1 even"><code>20Fayetteville<span style="color: #66cc66;">%</span>20Office~an<span style="color: #FF0000; font-weight: bold;">.35</span>.513123_<span style="color: #FF0000; font-weight: bold;">-93</span>.834189_SWN<span style="color: #66cc66;">%</span>20Ozark<span style="color: #66cc66;">%</span>20Office~an<span style="color: #FF0000; font-weight: bold;">.35</span>.0685432008022_</code></li>
<li value="93" class="tab1 odd"><code><span style="color: #FF0000; font-weight: bold;">-92</span>.4189197874021_SWN<span style="color: #66cc66;">%</span>20Conway<span style="color: #66cc66;">%</span>20Office~an.<span style="color: #2DB300;">'</span></code></li>
<li value="94" class="tab1 even"><code>f = <span style="color: #2DB300;">'C:/temp/DS_Html_Email.html'</span></code></li>
<li value="95" class="tab1 odd"><code>t = <span style="color: #2DB300;">'C:/temp/DS_Text_Email.txt'</span></code></li>
<li value="96" class="tab1 even"><code>dsUpdated = <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y, %I:%M %p'</span>, <span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">getmtime</span><span style="color: black;">&#40;</span>ds<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="97" class="tab1 odd"><code>KillObject<span style="color: black;">&#40;</span>f<span style="color: black;">&#41;</span></code></li>
<li value="98" class="tab1 even"><code>KillObject<span style="color: black;">&#40;</span>t<span style="color: black;">&#41;</span></code></li>
<li value="99" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;head&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;style type=&quot;text/css&quot;&gt;body,table {font-family:Verdana;<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="100" class="tab4 even"><code>font-size:10pt<span style="color: #66cc66;">;</span>empty-cells: show<span style="color: black;">&#125;</span>\n<span style="color: #66cc66;">&lt;</span>/style<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/head<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>body<span style="color: #66cc66;">&gt;</span>\n<span style="color: #2DB300;">')</span></code></li>
<li value="101" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'&lt;table style=&quot;width: 700px&quot;&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&lt;h3&gt;AAT Drill Schedule Mapper for '</span>\</code></li>
<li value="102" class="tab4 even"><code>+ <span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> + <span style="color: #2DB300;">'&lt;/h3&gt;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span></code></li>
<li value="103" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;Drill schedule last updated: '</span> + dsUpdated + <span style="color: #2DB300;">'&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span>\</code></li>
<li value="104" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&amp;nbsp;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #FF6600;"># empty row</span></code></li>
<li value="105" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&lt;a href=&quot;'</span> + masterUrl + <span style="color: #2DB300;">'&quot;&gt;Click here for a map of the latest<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="106" class="tab4 even"><code>AAT drill schedule<span style="color: #66cc66;">&lt;</span>/a<span style="color: #66cc66;">&gt;&lt;</span>/td<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/tr<span style="color: #66cc66;">&gt;</span><span style="color: #2DB300;">')</span></code></li>
<li value="107" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;&amp;nbsp;&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;'</span><span style="color: black;">&#41;</span> &nbsp;<span style="color: #FF6600;"># empty row</span></code></li>
<li value="108" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;*** THIS MESSAGE AUTO-GENERATED ***&lt;/td&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;tr&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;td&gt;<span style="color: #000099; font-weight: bold;">\</span></span></code></li>
<li value="109" class="tab4 odd"><code><span style="color: #66cc66;">***</span> PLEASE DO NOT REPLY TO THIS EMAIL <span style="color: #66cc66;">***&lt;</span>/td<span style="color: #66cc66;">&gt;</span>\n<span style="color: #66cc66;">&lt;</span>/tr<span style="color: #66cc66;">&gt;</span><span style="color: #2DB300;">')</span></code></li>
<li value="110" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>f,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span>&lt;/table&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/body&gt;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/html&gt;'</span><span style="color: black;">&#41;</span></code></li>
<li value="111" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'AAT Drill Schedule Mapper for '</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: #990000;">time</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span>\</code></li>
<li value="112" class="tab4 even"><code>,<span style="color: #990000;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="113" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Drill schedule last updated: '</span> + dsUpdated<span style="color: black;">&#41;</span></code></li>
<li value="114" class="tab1 even"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>Copy and paste this address into your web broswer:<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>'</span> + masterUrl<span style="color: black;">&#41;</span></code></li>
<li value="115" class="tab1 odd"><code>WriteOutput<span style="color: black;">&#40;</span>t,<span style="color: #2DB300;">'<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>** This message auto-generated - please do not respond to this email ***'</span><span style="color: black;">&#41;</span></code></li>
<li value="116" class="even">&nbsp;</li>
<li value="117" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> SendEmail<span style="color: black;">&#40;</span>message, recipients<span style="color: black;">&#41;</span>:</code></li>
<li value="118" class="tab1 even"><code>sender = <span style="color: #2DB300;">'AAT_Drill_Schedule_Mapper'</span></code></li>
<li value="119" class="tab1 odd"><code>server = <span style="color: #990000;">smtplib</span>.<span style="color: black;">SMTP</span><span style="color: black;">&#40;</span>ip_address<span style="color: black;">&#41;</span></code></li>
<li value="120" class="tab1 even"><code>server.<span style="color: black;">sendmail</span><span style="color: black;">&#40;</span>sender, recipients, message<span style="color: black;">&#41;</span></code></li>
<li value="121" class="tab1 odd"><code>server.<span style="color: black;">quit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="122" class="even">&nbsp;</li>
<li value="123" class="tab0 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> __name__ == <span style="color: #2DB300;">'__main__'</span>:</code></li>
<li value="124" class="even">&nbsp;</li>
<li value="125" class="tab1 odd"><code>wells = ExcelToList<span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS.xls'</span><span style="color: black;">&#41;</span></code></li>
<li value="126" class="tab1 even"><code>BuildLiveMapsUrl<span style="color: black;">&#40;</span>wells, <span style="color: #2DB300;">'C:/temp/DS.xls'</span><span style="color: black;">&#41;</span></code></li>
<li value="127" class="tab1 odd"><code><span style="color: #FF6600;"># Build our email, using both HTML and plain-text inputs</span></code></li>
<li value="128" class="tab1 even"><code>fhtml = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS_Html_Email.html'</span>,<span style="color: #2DB300;">'r'</span><span style="color: black;">&#41;</span></code></li>
<li value="129" class="tab1 odd"><code>ftxt = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'C:/temp/DS_Text_Email.txt'</span>,<span style="color: #2DB300;">'r'</span><span style="color: black;">&#41;</span></code></li>
<li value="130" class="tab1 even"><code>html = fhtml.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="131" class="tab1 odd"><code>text = ftxt.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="132" class="tab1 even"><code>subject = <span style="color: #2DB300;">'AAT Drill Schedule Mapper - '</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span>DateTime.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> + DateTime.\</code></li>
<li value="133" class="tab4 odd"><code>RelativeDateTime<span style="color: black;">&#40;</span>days=<span style="color: #FF0000; font-weight: bold;">+1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'%A, %m/%d/%Y'</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="134" class="tab1 even"><code><span style="color: #FF6600;"># Create the message with both HTML and text formats</span></code></li>
<li value="135" class="tab1 odd"><code>message = cgiutils.<span style="color: black;">createhtmlmail</span><span style="color: black;">&#40;</span>subject, html, text<span style="color: black;">&#41;</span></code></li>
<li value="136" class="tab1 even"><code><span style="color: #FF6600;"># Send the email out</span></code></li>
<li value="137" class="tab1 odd"><code>recips = <span style="color: black;">&#91;</span><span style="color: #2DB300;">'chad_cooper@swn.com'</span><span style="color: black;">&#93;</span> &nbsp;<span style="color: #FF6600;"># for testing</span></code></li>
<li value="138" class="tab1 even"><code><span style="color: #FF6600;">#recips = Dictionaries.aatEmails</span></code></li>
<li value="139" class="tab1 odd"><code>SendEmail<span style="color: black;">&#40;</span>message,recips<span style="color: black;">&#41;</span></code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/pymag/listing5.txt">listing5.txt</a></li>
</ol>
<p><a href="http://www.super-cooper.com/images/pymag/figure4.png" rel="lightbox[50]"><img class="left" src="http://farm3.static.flickr.com/2292/2417972450_476f5337d8_m.jpg" alt="figure4" width="240" height="163" /> </a></p>
<p><strong>Limitations and other Live Search Maps applications</strong></p>
<p>Internet Explorer imposes a strict limitation of 2,048 characters in the path portion of a URL. I have yet to run into this problem, as most of my URLs generated from this process are on the order of 400-600 characters long. All other modern web browsers (Firefox, Opera, or Safari) will give you no problems in this department.</p>
<p>The Live Search  Maps URL API also provides several other ways to plot locations on its maps. Let&#8217;s say for my application I need to supply a map of driving directions to each well location from our office in Fayetteville, Arkansas. No problem, the URL API provides us with the tools to do so. All we have to do is build a route string with the beginning waypoint (&quot;A&quot;) as the office in Fayetteville, and the end waypoint(s) (&quot;B&quot;) as the well locations:</p>
<p><code>http://maps.live.com/default.aspx?style=r&amp;rtp=adr.&quot;A&quot;~pos.&quot;B&quot;</code></p>
<p>Here, rtp defines the route, adr defines the start waypoint as an address, and pos defines the end waypoint as a specific point on the map. Our office location (&quot;A&quot;) remains static, but the dynamic end waypoints (&quot;B&quot;) can easily be added to the URL through a slight change in our BuildLiveMapsUrl function that adds them in the form of &quot;pos.latitude_longitude_name&quot; to the URL to create a end product such as:</p>
<p><code><a href="http://maps.live.com/default.aspx?style=r&amp;rtp=adr.1083%20East%20Sain%20Street%20Fayetteville,%20AR%2072703~pos.35.2760173376_-97.3403092666_Smith%20%232-3">http://maps.live.com/default.aspx?style=r&amp;rtp=adr.1083%20East%20Sain%20Street%20Fayetteville,%20AR%2072703~<br />
pos.35.2760173376_-97.3403092666_Smith%20%232-3</a> </code></p>
<p>We could easily loop through the original dataset and create a series of URLs similar to above and include them as clickable links in our email.</p>
<p><strong>Conclusion</strong></p>
<p>The Microsoft Live Search Maps URL API is a fairly simple, straightforward, and end-user friendly way to display point locations on a map. When combined with a minimal amount of Python code to simply create a URL to use in a existing cross-browser application, Live Search Maps becomes an indispensible tool that allows us to disseminate, view, understand, and interpret data that was once simply sitting around. I hope this article demonstrates how Python can be used to take once lifeless enterprise data and turn it into a dynamic, meaningful, and sexy end product.</p>
<p><strong>About the author</strong></p>
<p>Chad Cooper has been in the Geographic Information Systems field for 5 years, the last 3 of which have been with <a href="http://www.swn.com">Southwestern Energy Company</a> . Chad has been hacking up Python code for the past 2 years. He lives in Arkansas with his wife and two incredibly energetic young sons.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/04/15/mapping-point-locations-with-python-and-microsoft-live-search-maps/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Codeviewer plugin test</title>
		<link>http://www.super-cooper.com/archive/2008/04/11/codeviewer-plugin-test/</link>
		<comments>http://www.super-cooper.com/archive/2008/04/11/codeviewer-plugin-test/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 02:27:39 +0000</pubDate>
		<dc:creator>Chad</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://super-cooper.com/2008/04/11/codeviewer-plugin-test/</guid>
		<description><![CDATA[Back a few years ago, I used a code syntax highlighter called Code Viewer that was created by Aaron Schaefer at Elastic Dog. That has since been taken over by HÃ¥kan CarlstrÃ¶m. I spent too many hours this weekend getting this plugin setup to parse Python source code. It uses GeSHi to highlight the code [...]]]></description>
			<content:encoded><![CDATA[<p>Back a few years ago, I used a code syntax highlighter called Code Viewer that was created by Aaron Schaefer at <a href="http://elasticdog.com/">Elastic Dog</a>. That has since been taken over by <a href="http://www.familjencarlstrom.se/WordPress/2006/08/17/code-viewer/">HÃ¥kan CarlstrÃ¶m</a>. I spent too many hours this weekend getting this plugin setup to parse Python source code. It uses <a href="http://qbnz.com/highlighter/">GeSHi</a> to highlight the code syntax, and I had to hack up the GeSHi CSS and my own CSS to get the Python source code to look like I wanted, but it&#8217;s about there. I highly recommend this plugin if you are looking to highlight source code of virtually any modern language. The coolest part of it is that it links to a source code file and you just point to that file, you don&#8217;t have to include the code in the post. Below is a sampling of the output, with my own CSS styling applied.</p>
<link rel="stylesheet" href="http://www.super-cooper.com/wp-content/plugins/codeviewer.css" type="text/css" media="all" />
<ol class="codelist">
<li value="1" class="tab0 odd"><code><span style="color: #990000;font-weight:bold;">def</span> grabNewImages<span style="color: black;">&#40;</span> <span style="color: #008000;">self</span> <span style="color: black;">&#41;</span>:</code></li>
<li value="2" class="tab1 even"><code><span style="color: #FF6600;">&quot;&quot;&quot; Recurses thru directories and looks for images to upload. I only want to upload my '5-star' images, so we scan the IPTC tags for 'r5', my way of tagging my pics I really like (usually get prints of r5s) &quot;&quot;&quot;</span></code></li>
<li value="3" class="tab1 odd"><code>images = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span></code></li>
<li value="4" class="tab1 even"><code><span style="color: #0008E6;font-weight:bold;">for</span> dirpath, dirnames, filenames <span style="color: #0008E6;font-weight:bold;">in</span> <span style="color: #990000;">os</span>.<span style="color: black;">walk</span><span style="color: black;">&#40;</span>IMAGE_DIR<span style="color: black;">&#41;</span>:</code></li>
<li value="5" class="tab2 odd"><code><span style="color: #0008E6;font-weight:bold;">for</span> f <span style="color: #0008E6;font-weight:bold;">in</span> filenames :</code></li>
<li value="6" class="tab3 even"><code><span style="color: #FF6600;"># Grab IPTC keywords</span></code></li>
<li value="7" class="tab3 odd"><code>info = IPTCInfo<span style="color: black;">&#40;</span><span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>dirpath, f<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></code></li>
<li value="8" class="tab3 even"><code><span style="color: #FF6600;"># Is it a 5-star photo?</span></code></li>
<li value="9" class="tab3 odd"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: #2DB300;">'r5'</span> <span style="color: #0008E6;font-weight:bold;">in</span> info.<span style="color: black;">keywords</span>:</code></li>
<li value="10" class="tab4 even"><code><span style="color: #0008E6;font-weight:bold;">print</span> <span style="color: #2DB300;">'File to upload:'</span>,<span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">join</span><span style="color: black;">&#40;</span>dirpath, f<span style="color: black;">&#41;</span></code></li>
<li value="11" class="tab4 odd"><code>ext = f.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #2DB300;">'.'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #FF0000; font-weight: bold;">-1</span><span style="color: black;">&#93;</span></code></li>
<li value="12" class="tab4 even"><code><span style="color: #0008E6;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> ext == <span style="color: #2DB300;">'jpg'</span> <span style="color: #0008E6;font-weight:bold;">or</span> ext == <span style="color: #2DB300;">'gif'</span> <span style="color: #0008E6;font-weight:bold;">or</span> ext == <span style="color: #2DB300;">'png'</span> <span style="color: black;">&#41;</span>:</code></li>
<li value="13" class="tab5 odd"><code>images.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #990000;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">normpath</span><span style="color: black;">&#40;</span> dirpath + <span style="color: #2DB300;">'/'</span> + f <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span></code></li>
<li value="14" class="tab1 even"><code>images.<span style="color: black;">sort</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></code></li>
<li value="15" class="tab1 odd"><code><span style="color: #0008E6;font-weight:bold;">return</span> images</code></li>
<li class="sourcelink"><strong>Download this code:</strong> <a href="http://www.super-cooper.com/snippets/test.txt">test.txt</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.super-cooper.com/archive/2008/04/11/codeviewer-plugin-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
