<?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>CrapFlingingMonkey.com &#187; Code</title>
	<atom:link href="http://crapflingingmonkey.com/wp/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://crapflingingmonkey.com/wp</link>
	<description>Coding to the beat, yo</description>
	<lastBuildDate>Fri, 22 Jul 2011 00:39:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3-aortic-dissection</generator>
		<item>
		<title>Bonus Coding</title>
		<link>http://crapflingingmonkey.com/wp/2011/07/bonus-coding/</link>
		<comments>http://crapflingingmonkey.com/wp/2011/07/bonus-coding/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 05:58:52 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Innovation]]></category>

		<guid isPermaLink="false">http://crapflingingmonkey.com/wp/?p=121</guid>
		<description><![CDATA[Last weekend I biked my first century.  It was an &#8220;easy&#8221; course and was supposed to be a beautiful day.  I wasn&#8217;t expecting anything to go wrong, but as luck would have it, a lot did.  I struggled to finish. Looking back, I think there are a few reasons why it wasn&#8217;t as easy as [...]]]></description>
			<content:encoded><![CDATA[<p>Last weekend I biked my first century.  It was an &#8220;easy&#8221; course and was supposed to be a beautiful day.  I wasn&#8217;t expecting anything to go wrong, but as luck would have it, a lot did.  I struggled to finish.</p>
<p>Looking back, I think there are a few reasons why it wasn&#8217;t as easy as I had hoped:</p>
<ul>
<li>I got 5 hours of sleep the night before</li>
<li>I didn&#8217;t train much</li>
<li>I didn&#8217;t drink enough water the night/week before</li>
<li>I got lost, and ended up biking an extra six miles</li>
</ul>
<p>Whoa, back up&#8230; what was that last one?</p>
<h2>&#8220;I ended up biking an extra six miles&#8221;</h2>
<p>I&#8217;d like to call these my &#8220;bonus miles&#8221;.  Even though I went off-course at the time, lost a few minutes off my time, and made the rest of the race a little harder&#8230; it forced me to push myself a further, get a better workout, and gave me the confidence that if needed, I can go even further.  It also taught me a valuable lesson &#8212; don&#8217;t get lost.  So even though it was a short-term loss, it ended up being a long-term gain.</p>
<h2>So how does this relate to programming?</h2>
<p>Bonus coding.  Sometimes we get lost in what we are programming.  Sometimes it&#8217;s a miscommunication.  Sometimes it&#8217;s a false assumption.  But often times we find ourselves in a place where we&#8217;ve coded for a long amount of time and end up having to <em>throw it all away</em>.  It&#8217;s not the best feeling in the world &#8212; it actually makes you feel like you&#8217;ve just wasted valuable time from your life.  But it&#8217;s more than that.  You&#8217;ve gained more experience in the <em>wrong</em> way to code.  Like biking, it&#8217;s a short-term loss, but a long-term gain.  Just learn from it and try not to repeat the same mistakes.</p>
<p>Just remember in your coding that your career isn&#8217;t a sprint, it&#8217;s a century &#8212; a marathon.  Go at a steady pace, learn from your mistakes, and don&#8217;t get yourself down at short-term losses.</p>
]]></content:encoded>
			<wfw:commentRss>http://crapflingingmonkey.com/wp/2011/07/bonus-coding/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>YUI-Magnifier Released</title>
		<link>http://crapflingingmonkey.com/wp/2009/12/yui-magnifier-released/</link>
		<comments>http://crapflingingmonkey.com/wp/2009/12/yui-magnifier-released/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 20:54:41 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[backcountry.com]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[work]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://crapflingingmonkey.com/wp/?p=47</guid>
		<description><![CDATA[A coworker of mine, Dustin McQuay, released the YUI Magnifier, a YUI implementation of other popular image zoom utilities.   We were actually surprised to see that nothing else like it already existed for YUI, so Dustin took the challenge of building his own, with the hopes that it might be included in other larger [...]]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.youtube.com/v/WRok8vencqE" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/WRok8vencqE"></embed></object></p>
<p>A coworker of mine, <a href="http://www.linkedin.com/in/dustinmcquay">Dustin McQuay</a>, released the <a href="http://github.com/dmcquay/YUI-Magnifier" target="_blank">YUI Magnifier</a>, a YUI implementation of other popular image zoom utilities.   We were actually surprised to see that nothing else like it already existed for YUI, so Dustin took the challenge of building his own, with the hopes that it might be included in other larger YUI libraries.</p>
<p>It boasts the features:</p>
<ul>
<li> Display a magnified portion of an image, which is controlled by where the mouse is hovering over the image</li>
<li>Control over styling</li>
<li>Control over location of magnification lens</li>
<li>Magnified image can be wrapped by a larger element</li>
</ul>
<p>Though the release wasn&#8217;t very public, it was still quite an accomplishment. It happens to be one of the first open-source releases from <a href="http://www.backcountry.com/">Backcountry.com</a> (preceded to my knowledge by only <a href="http://bucardo.org/">Bucardo</a>, a Postgres replication application written for Backcountry.com by <a href="http://www.endpoint.com/" target="_blank">Endpoint</a>).  It was originally designed to be used for our 900&#215;900 images, but got cut after development has essentially finished due to changed requirements.</p>
<p>It&#8217;s a pretty solid application, and hopefully the start of more open source to be coming out of Backcountry.com</p>
]]></content:encoded>
			<wfw:commentRss>http://crapflingingmonkey.com/wp/2009/12/yui-magnifier-released/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Python Script For Automated Voting</title>
		<link>http://crapflingingmonkey.com/wp/2008/07/python-script-for-automated-voting/</link>
		<comments>http://crapflingingmonkey.com/wp/2008/07/python-script-for-automated-voting/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 03:07:13 +0000</pubDate>
		<dc:creator>josh</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[automated voting]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://crapflingingmonkey.com/wp/?p=6</guid>
		<description><![CDATA[This was a python script created by me a while ago to automate voting for a particular user. It may not work anymore, as this script was written quite a while ago. It&#8217;s not commented or anything. Here is the original post: I created a small script to do the clearing of the cookies for [...]]]></description>
			<content:encoded><![CDATA[<p>This was a python script created by me a while ago to automate voting for a particular user.  It may not work anymore, as this script was written quite a while ago.  It&#8217;s not commented or anything. Here is the original post:</p>
<p>I created a small script to do the clearing of the cookies for you and everything. I tried to have it solve the captcha for you automagically, but it just wasn&#8217;t happening (I used ocrad and tesseract, and cleaning the image using imagemagick first). Anyways, you can sit there all day and enter the captchas to keep voting.</p>
<p>A few requirements:<br />
* I wrote it using python 2.5.1. Not sure what other version it will work on.<br />
* PIL required<br />
* mechanize required</p>
<p>both of the required modules are available in the ubuntu repositories. I think that&#8217;s all you need, let me know if you run into any troubles.</p>

<div class="wp_syntax"><div class="code"><pre class="python python" style="font-family:monospace;">sudo apt-get install python-imaging python-mechanize</pre></div></div>

<p>A couple notes about it:<br />
* You don&#8217;t have to hit &#8220;submit&#8221;, you can just press enter<br />
* check the console for updates on whether it was submitted ok or not</p>
<p>Let me know if you want help learning how to set it up.</p>

<div class="wp_syntax"><div class="code"><pre class="python python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/python</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Displays the Captcha from http://basketball.seniorclassaward.com/public/men/vote.aspx?usr=public&amp;amp;gen=M</span>
<span style="color: #808080; font-style: italic;"># so that you can enter it so that Jacee Carroll will win. It automagically keeps track/clears cookies (via mechanize)</span>
<span style="color: #808080; font-style: italic;"># so you can submit more than once every 24 hours</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Written by Josh</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> pygtk, gtk
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">StringIO</span>
<span style="color: #ff7700;font-weight:bold;">import</span> ImageFile
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">from</span> mechanize <span style="color: #ff7700;font-weight:bold;">import</span> Browser
pygtk.<span style="color: black;">require</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'2.0'</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># taken from http://www.daa.com.au/pipermail/pygtk/2003-June/005268.html</span>
<span style="color: #ff7700;font-weight:bold;">def</span> image_to_gtkpixbuf<span style="color: black;">&#40;</span>image<span style="color: black;">&#41;</span>:
    <span style="color: #008000;">file</span> = <span style="color: #dc143c;">StringIO</span>.<span style="color: #dc143c;">StringIO</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    image.<span style="color: black;">save</span> <span style="color: black;">&#40;</span><span style="color: #008000;">file</span>, <span style="color: #483d8b;">'ppm'</span><span style="color: black;">&#41;</span>
    contents = <span style="color: #008000;">file</span>.<span style="color: black;">getvalue</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #008000;">file</span>.<span style="color: black;">close</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    loader = gtk.<span style="color: black;">gdk</span>.<span style="color: black;">PixbufLoader</span> <span style="color: black;">&#40;</span><span style="color: #483d8b;">'pnm'</span><span style="color: black;">&#41;</span>
    loader.<span style="color: black;">write</span> <span style="color: black;">&#40;</span>contents, <span style="color: #008000;">len</span> <span style="color: black;">&#40;</span>contents<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    pixbuf = loader.<span style="color: black;">get_pixbuf</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    loader.<span style="color: black;">close</span> <span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> pixbuf
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Submitter:
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> get_image<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #808080; font-style: italic;"># Get the image</span>
        image_url = <span style="color: #483d8b;">'http://basketball.seniorclassaward.com/Captcha.aspx'</span>
&nbsp;
        image_response = <span style="color: #008000;">self</span>.<span style="color: black;">br</span>.<span style="color: black;">open_novisit</span><span style="color: black;">&#40;</span>image_url<span style="color: black;">&#41;</span>
&nbsp;
        p = ImageFile.<span style="color: black;">Parser</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #ff4500;">1</span>:
            data = image_response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1024</span><span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> data:
                <span style="color: #ff7700;font-weight:bold;">break</span>
            p.<span style="color: black;">feed</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
        image_response.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> p.<span style="color: black;">image</span>
&nbsp;
    <span style="color: #ff7700;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>:
        <span style="color: #008000;">self</span>.<span style="color: black;">br</span> = Browser<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">br</span>.<span style="color: black;">set_handle_robots</span><span style="color: black;">&#40;</span><span style="color: #008000;">False</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">url</span> = <span style="color: #483d8b;">'http://basketball.seniorclassaward.com/public/men/vote.aspx?usr=public&amp;amp;gen=M'</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">br</span>.<span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">url</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">captcha</span> = <span style="color: #008000;">self</span>.<span style="color: black;">get_image</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> submit<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, captcha_text<span style="color: black;">&#41;</span>:
        captcha_textbox = <span style="color: #483d8b;">'ctl00$DefaultContentPlaceholder$PublicBallot$CaptchaTextBox'</span>
        jaycee_checkbox = <span style="color: #483d8b;">'ctl00$DefaultContentPlaceholder$PublicBallot$BallotCheckBoxList$0'</span>
&nbsp;
        br = <span style="color: #008000;">self</span>.<span style="color: black;">br</span>
        br.<span style="color: black;">select_form</span><span style="color: black;">&#40;</span> name=<span style="color: #483d8b;">'aspnetForm'</span> <span style="color: black;">&#41;</span>
        br<span style="color: black;">&#91;</span>captcha_textbox<span style="color: black;">&#93;</span> = captcha_text
        br<span style="color: black;">&#91;</span>jaycee_checkbox<span style="color: black;">&#93;</span> = <span style="color: black;">&#91;</span><span style="color: #483d8b;">'on'</span><span style="color: black;">&#93;</span>
&nbsp;
        response = br.<span style="color: black;">submit</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        r = response.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;ATTENTION:<span style="color: #000099; font-weight: bold;">\\</span>n([^']+)'&quot;</span>, r<span style="color: black;">&#41;</span>:
            res = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;ATTENTION:<span style="color: #000099; font-weight: bold;">\\</span>n([^']+)'&quot;</span>, r<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Error submitting: &quot;</span> + res.<span style="color: black;">groups</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>0<span style="color: black;">&#93;</span>
            <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">False</span>
        <span style="color: #ff7700;font-weight:bold;">elif</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;COMPLETE:<span style="color: #000099; font-weight: bold;">\\</span>n([^']+)'&quot;</span>, r<span style="color: black;">&#41;</span>:
            res = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;COMPLETE:<span style="color: #000099; font-weight: bold;">\\</span>n([^']+)'&quot;</span>, r<span style="color: black;">&#41;</span>
            <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;SUCCESS! &quot;</span> + res.<span style="color: black;">groups</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>0<span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Control:
    <span style="color: #ff7700;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>:
        <span style="color: #008000;">self</span>.<span style="color: black;">window</span> = gtk.<span style="color: black;">Window</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">window</span>.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;destroy&quot;</span>, gtk.<span style="color: black;">main_quit</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">submitter</span> = Submitter<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">box</span> = gtk.<span style="color: black;">HBox</span><span style="color: black;">&#40;</span><span style="color: #008000;">False</span>, 0<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">window</span>.<span style="color: black;">add</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">box</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">submitButton</span> = gtk.<span style="color: black;">Button</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Submit&quot;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">submitButton</span>.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'clicked'</span>, <span style="color: #008000;">self</span>.<span style="color: black;">submit</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">box</span>.<span style="color: black;">pack_start</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">submitButton</span>, <span style="color: #008000;">True</span>, <span style="color: #008000;">True</span>, 0<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">submitButton</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">text</span> = gtk.<span style="color: black;">Entry</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">text</span>.<span style="color: black;">connect</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;activate&quot;</span>, <span style="color: #008000;">self</span>.<span style="color: black;">submit</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">box</span>.<span style="color: black;">pack_start</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">text</span>, <span style="color: #008000;">True</span>, <span style="color: #008000;">True</span>, 0<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">text</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">set_image</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">submitter</span>.<span style="color: black;">captcha</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">box</span>.<span style="color: black;">pack_start</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">image</span>, <span style="color: #008000;">True</span>, <span style="color: #008000;">True</span>, 0<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">image</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">box</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">window</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
        <span style="color: #008000;">self</span>.<span style="color: black;">text</span>.<span style="color: black;">grab_focus</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> set_image<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, image<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">image</span> = gtk.<span style="color: black;">Image</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">image</span>.<span style="color: black;">set_from_pixbuf</span><span style="color: black;">&#40;</span>
                image_to_gtkpixbuf<span style="color: black;">&#40;</span>image<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> change_image<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">box</span>.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> <span style="color: #008000;">self</span>.<span style="color: black;">image</span> <span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">set_image</span><span style="color: black;">&#40;</span> <span style="color: #008000;">self</span>.<span style="color: black;">submitter</span>.<span style="color: black;">get_image</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">box</span>.<span style="color: black;">pack_start</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>.<span style="color: black;">image</span>, <span style="color: #008000;">True</span>, <span style="color: #008000;">True</span>, 0<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">image</span>.<span style="color: black;">show</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> submit<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, evt<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #008000;">self</span>.<span style="color: black;">submitter</span>.<span style="color: black;">submit</span><span style="color: black;">&#40;</span> <span style="color: #008000;">self</span>.<span style="color: black;">text</span>.<span style="color: black;">get_text</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">upper</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>:
            <span style="color: #808080; font-style: italic;"># reset the submitter</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">submitter</span> = Submitter<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">change_image</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
            <span style="color: #008000;">self</span>.<span style="color: black;">text</span>.<span style="color: black;">set_text</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">''</span><span style="color: black;">&#41;</span>
            <span style="color: #008000;">self</span>.<span style="color: black;">text</span>.<span style="color: black;">grab_focus</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    gtk.<span style="color: black;">main</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> 0
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
    Control<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    main<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This was a just-for-fun thing for me, so I could test out some various web tools for python. I tried simple urllib/urllib2, ClientForm, ClientCookies, and mechanize, and found mechanize to be the most robust and easiest to use, although it was missing out on some features that I thought may be useful (as higher-level modules normally do).</p>
<p>Also, I didn&#8217;t like this:</p>

<div class="wp_syntax"><div class="code"><pre class="python python" style="font-family:monospace;">        <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;ATTENTION:<span style="color: #000099; font-weight: bold;">\\</span>n([^']+)'&quot;</span>, r<span style="color: black;">&#41;</span>:
            res = <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;ATTENTION:<span style="color: #000099; font-weight: bold;">\\</span>n([^']+)'&quot;</span>, r<span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://crapflingingmonkey.com/wp/2008/07/python-script-for-automated-voting/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

