<?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>Odie5533 &#187; Programming</title>
	<atom:link href="http://odie5533.com/category/programming/feed" rel="self" type="application/rss+xml" />
	<link>http://odie5533.com</link>
	<description></description>
	<lastBuildDate>Mon, 06 Sep 2010 01:31:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>VarisCite: Zotero-based Citation Generation for Google Chrome</title>
		<link>http://odie5533.com/406-variscite-zotero-based-citation-generation-for-google-chrome</link>
		<comments>http://odie5533.com/406-variscite-zotero-based-citation-generation-for-google-chrome#comments</comments>
		<pubDate>Thu, 19 Aug 2010 05:02:47 +0000</pubDate>
		<dc:creator>odie5533</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Zotero]]></category>

		<guid isPermaLink="false">http://odie5533.com/?p=406</guid>
		<description><![CDATA[VarisCite is a native citation generator for Google Chrome and is based on Zotero&#8217;s JavaScript translator structure. VarisCite creates a Chrome page action which, when clicked, will use a Zotero-style translator to generate a citation from the current webpage. Currently, VarisCite only supports IGN.com for citation generation and it does not support multiple Zotero translators [...]]]></description>
			<content:encoded><![CDATA[<p><strong>VarisCite</strong> is a native citation generator for Google Chrome and is based on <a href="http://www.zotero.org/">Zotero&#8217;s</a> JavaScript translator structure. VarisCite creates a <a href="http://code.google.com/chrome/extensions/pageAction.html">Chrome page action</a> which, when clicked, will use a Zotero-style translator to generate a citation from the current webpage. Currently, VarisCite only supports IGN.com for citation generation and it does not support multiple Zotero translators at the same time (yet). I offer this program as a proof of concept, both as the first external application to use Zotero&#8217;s translators that I know of, and to hopefully push for the expansion of Zotero or a Zotero-like application outside of Firefox. I want to release it in its working state because I often get side-tracked and end up writing some widget and never releasing it (I have a few sitting on the nearly-ready-for-release pile). I have more I would like to say regarding Zotero-like applications but I will leave that for another time and another post.</p>

<p><img src="http://i35.tinypic.com/292r40k.png"/></p>

<p><a href="/programs/VarisCite/VarisCite.crx">Install VarisCite PoC</a>. Now go to an article on <a href="http://pc.ign.com/articles/111/1114139p1.html">IGN</a> to test it.</p>

<p>If you want the source, right-click save as. Crx files are zip files with the extension change from zip to crx.</p>
]]></content:encoded>
			<wfw:commentRss>http://odie5533.com/406-variscite-zotero-based-citation-generation-for-google-chrome/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>jQuery RSS Parser in 7 Lines</title>
		<link>http://odie5533.com/373-jquery-rss-parser-in-7-lines</link>
		<comments>http://odie5533.com/373-jquery-rss-parser-in-7-lines#comments</comments>
		<pubDate>Sun, 15 Aug 2010 06:33:25 +0000</pubDate>
		<dc:creator>odie5533</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Snippet]]></category>

		<guid isPermaLink="false">http://odie5533.com/?p=373</guid>
		<description><![CDATA[&#8220;He&#8217;d fly through the feed with the greatest of ease, That daring young parser on the flying trapeze.&#8221; /* Trapeze RSS parser in 7 lines */ function parseRSS&#40;d&#41; &#123; return $&#40;d&#41;.find&#40;'item'&#41;.map&#40;function&#40;&#41; &#123; var i = new Object&#40;&#41;; $&#40;this&#41;.children&#40;&#41;.each&#40;function&#40;&#41;&#123;i&#91;this.tagName&#93;= this.textContent;&#125;&#41;; return i; &#125;&#41;; &#125; Called with a return document from an ajax request, this function returns [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;He&#8217;d fly through the <em>feed</em> with the greatest of ease,
That daring young <em>parser</em> on the flying trapeze.&#8221;</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* Trapeze RSS parser in 7 lines */</span>
<span style="color: #003366; font-weight: bold;">function</span> parseRSS<span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> $<span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'item'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">map</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Object<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>i<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">tagName</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">textContent</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> i<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<p>Called with a return document from an ajax request, this function returns an array of items which are associative arrays from the feed&#8217;s items.</p>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Here's an example</span>
$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span>your<span style="color: #339933;">-</span>rss<span style="color: #339933;">-</span>feed<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    parseRSS<span style="color: #009900;">&#40;</span>d<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;a&gt;&lt;/a&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">title</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'href'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">link</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;br/&gt;'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'body'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://odie5533.com/373-jquery-rss-parser-in-7-lines/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twisted Python RDT/RTSP Library and Stream Downloader</title>
		<link>http://odie5533.com/346-twisted-python-rdt-rtsp-library-and-stream-downloader</link>
		<comments>http://odie5533.com/346-twisted-python-rdt-rtsp-library-and-stream-downloader#comments</comments>
		<pubDate>Tue, 01 Jun 2010 03:09:51 +0000</pubDate>
		<dc:creator>odie5533</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://odie5533.com/?p=346</guid>
		<description><![CDATA[Twisted is a great framework for Python, but they don&#8217;t support RDT or RTSP protocol used for streaming Real video. The RDT/RTSP handler in MPlayer is a bit buggy and suffers from disconnect problems when receiving RTSP packets after switching to raw mode for RDT (though perhaps such occurrences are out of specification, they do [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://twistedmatrix.com/trac/">Twisted</a> is a great framework for Python, but they don&#8217;t support <a href="http://en.wikipedia.org/wiki/Real_Data_Transport">RDT</a> or <a href="http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol">RTSP</a> protocol used for streaming Real video. The RDT/RTSP handler in <a href="http://en.wikipedia.org/wiki/MPlayer">MPlayer</a> is a bit buggy and suffers from disconnect problems when receiving RTSP packets after switching to raw mode for RDT (though perhaps such occurrences are out of specification, they do still occur). Thus, I set off to create my own.</p>

<p>The library includes support for RTSP, RDT, <a href="http://en.wikipedia.org/wiki/Session_Description_Protocol">SDPP</a>, ASMRP, and <a href="https://common.helixcommunity.org/2003/HCS_SDK_r5/htmfiles/rmff.htm">RMFF</a>, and it is all in pure Python and Pythonically coded where possible (see sdpp.py). It requires Python 2.6 and the Twisted Python library. The library has only one known bug, and I can&#8217;t for the life of me find it. Perhaps another set of eyes will effect a solution.</p>

<p>To use the library to simply download an RTSP stream:
<code>python rdt.py -u &lt;URL&gt; -f &lt;FILENAME&gt;</code></p>

<p>If you like this post, <b>please comment</b>. Commenting is fast, anonymous, and greatly appreciated.
<a href="/programs/RDT-RTSP/Twisted RDT-RTSP Library 2010-07-05.zip">Download the Twisted Python RDT-RTSP Library here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://odie5533.com/346-twisted-python-rdt-rtsp-library-and-stream-downloader/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Automatically Download Songs from Grooveshark</title>
		<link>http://odie5533.com/334-automatically-download-songs-from-grooveshark</link>
		<comments>http://odie5533.com/334-automatically-download-songs-from-grooveshark#comments</comments>
		<pubDate>Mon, 31 May 2010 01:11:42 +0000</pubDate>
		<dc:creator>odie5533</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://odie5533.com/?p=334</guid>
		<description><![CDATA[Because manually downloading songs from Grooveshark is too tedious, here&#8217;s a nice process to automatically save all the songs you listen to on Grooveshark. Unlike other methods, this does not use any extra bandwidth so you don&#8217;t need to listen to the song and download it, once is enough. Update After doing some searching, I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>Because <a href="http://odie5533.com/downloading-mp3-songs-from-grooveshark-322">manually downloading songs from Grooveshark</a> is too tedious, here&#8217;s a nice process to automatically save all the songs you listen to on Grooveshark. Unlike other methods, this does not use any extra bandwidth so you don&#8217;t need to listen to the song and download it, once is enough.<span id="more-334"></span></p>

<p><font color="red">Update</font> After doing some searching, I&#8217;ve found a FireFox plugin caled <a href="https://addons.mozilla.org/en-US/firefox/addon/3006/">Video DownloadHelper</a> which performs much the same function as the program I&#8217;ve written, but is more stable and integrated directly into FireFox. Its only downside is that it doesn&#8217;t automatically download the songs as you listen, you need to start downloading the ones you want. But it is more stable than my program and much more user friendly. Be sure to use Mp3tag (listed below) to quickly rename all the files you&#8217;ve downloaded.</p>

<p>Download and install the following pre-requisites:
<ol><li>Python 2.6.5 &#8211; <a href="http://www.python.org/ftp/python/2.6.5/python-2.6.5.msi">http://www.python.org/ftp/python/2.6.5/python-2.6.5.msi</a></li>
<li>dpkt 1.7 &#8211; <a href="http://dpkt.googlecode.com/files/dpkt-1.7.win32.exe">http://dpkt.googlecode.com/files/dpkt-1.7.win32.exe</a></li>
<li>pypcap 1.1 &#8211; <a href="/programs/Grooveshark/pcap-1.1.win32-py2.6.exe">pcap-1.1.win32-py2.6.exe</a></li>
</ol></p>

<p>Save this Python program into a folder of its own: <a href="/programs/Grooveshark/groovegrab.py">groovegrab.py</a></p>

<p>Run the program using <code>python groovegrab.py</code></p>

<p>As you listen to songs on Grooveshark, the folder will populate with mp3 files. Each are named Track_X.mp3. But there&#8217;s a really neat, easy way to rename them. Download <a href="http://www.mp3tag.de/en/download.html">Mp3tag</a> and in the program go to File > Change Directory and choose the directory where the mp3 files are. Select all the mp3 files in the main pane and go to Convert > Tag to Filename.</p>

<p>Enjoy your perfectly named mp3 files from a Grooveshark listening session.</p>

<p>Thanks to dugsong for <a href="http://code.google.com/p/dpkt/">dpkt</a> and <a href="http://code.google.com/p/pypcap/">pypcap</a>, and thanks to Andrew Brampton for his <a href="http://bramp.net/blog/follow-http-stream-with-decompression">tutorial on dpkt/pypcap</a>!</p>

<p>If you liked this post, please comment. Commeting is fast, anonymous, and greatly appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://odie5533.com/334-automatically-download-songs-from-grooveshark/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>GIMP Resize and Match DPI in Scheme</title>
		<link>http://odie5533.com/304-gimp-resize-and-match-dpi-in-scheme</link>
		<comments>http://odie5533.com/304-gimp-resize-and-match-dpi-in-scheme#comments</comments>
		<pubDate>Mon, 17 May 2010 03:33:29 +0000</pubDate>
		<dc:creator>odie5533</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[GIMP]]></category>
		<category><![CDATA[Scheme]]></category>

		<guid isPermaLink="false">http://odie5533.com/?p=304</guid>
		<description><![CDATA[Resize-match-dpi is a GIMP Script-Fu script written in Scheme to resize or scale an image along with scaling the DPI. Let&#8217;s consider an image being scanned which is 4.75&#8243; x 4.70&#8243;. We scan the image at 300 DPI with a pixel resolution of 1425 x 1409 and we want to scale it down to 1280&#215;1266. [...]]]></description>
			<content:encoded><![CDATA[<p>Resize-match-dpi is a GIMP Script-Fu script written in Scheme to resize or scale an image along with scaling the DPI. Let&#8217;s consider an image being scanned which is 4.75&#8243; x 4.70&#8243;. We scan the image at 300 DPI with a pixel resolution of 1425 x 1409 and we want to scale it down to 1280&#215;1266. Using IrfanView, XNView, GIMP, and other programs will rescale the image, but the DPI will still be 300. This means when the image is viewed on a monitor or printed out it will appear too small (4.27&#8243; x 4.22&#8243;). This script scales the DPI to match the new pixel resolution so it will still appear as 4.75&#8243; x 4.70&#8243;.</p>

<p>If you like this post, please comment. Commenting is fast, anonymous, and greatly appreciated.<span id="more-304"></span></p>

<p>To install the script, save it as resize-match-dpi.scm into C:\Users\Odie&#46;gimp-2.6\scripts&#46; Open up GIMP and the script will appear under the Script-Fu menu at the top of an image window. If you are really adventurous, I&#8217;ve included a small wrapper allowing the script to be called from the console as follows:
<pre>"C:\Program Files\GIMP-2.0\bin\gimp-console-2.6" -i -b "(resize<em>match</em>dpi \"input.bmp\" \"output.bmp\" 1280 0)" -b "(gimp-quit 0)"</pre></p>

<p>resize-match-dpi.scm:</p>


<div class="wp_syntax"><div class="code"><pre class="scheme" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">; Released under the GNU GPL 3.0 or later</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>resize<span style="color: #66cc66;">-</span>match<span style="color: #66cc66;">-</span>dpi image drawable newwidth newheight<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let*</span> <span style="color: #66cc66;">&#40;</span>
	 <span style="color: #66cc66;">&#40;</span>oldwidth <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>width image<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	 <span style="color: #66cc66;">&#40;</span>oldheight <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>height image<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	 <span style="color: #66cc66;">&#40;</span>newdpi <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> newheight <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> newheight <span style="color: #66cc66;">&#40;</span>round <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">/</span> oldheight oldwidth<span style="color: #66cc66;">&#41;</span> newwidth<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">=</span> newwidth <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> newwidth <span style="color: #66cc66;">&#40;</span>round <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">/</span> oldwidth oldheight<span style="color: #66cc66;">&#41;</span> newheight<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> newdpi <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">/</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">*</span> newwidth <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>get<span style="color: #66cc66;">-</span>resolution image<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> oldwidth<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>undo<span style="color: #66cc66;">-</span>group<span style="color: #66cc66;">-</span>start image<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>scale image newwidth newheight<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>set<span style="color: #66cc66;">-</span>resolution image newdpi newdpi<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>undo<span style="color: #66cc66;">-</span>group<span style="color: #66cc66;">-</span>end image<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>resize_match_dpi filename output newwidth newheight<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>image    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>file<span style="color: #66cc66;">-</span><span style="color: #b1b100;">load</span> RUN<span style="color: #66cc66;">-</span>NONINTERACTIVE filename filename<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
         <span style="color: #66cc66;">&#40;</span>drawable <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>get<span style="color: #66cc66;">-</span>active<span style="color: #66cc66;">-</span>layer image<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
        <span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>resize<span style="color: #66cc66;">-</span>match<span style="color: #66cc66;">-</span>dpi image drawable newwidth newheight<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>file<span style="color: #66cc66;">-</span>save RUN<span style="color: #66cc66;">-</span>NONINTERACTIVE image drawable output output<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>delete image<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">define</span> <span style="color: #66cc66;">&#40;</span>resize_match_dpi_multi pattern outdir newwidth newheight<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>filelist <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cadr</span> <span style="color: #66cc66;">&#40;</span>file<span style="color: #66cc66;">-</span>glob pattern <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>while <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">not</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">null?</span> filelist<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	   <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let*</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>filename <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> filelist<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		  <span style="color: #66cc66;">&#40;</span>image    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>file<span style="color: #66cc66;">-</span><span style="color: #b1b100;">load</span> RUN<span style="color: #66cc66;">-</span>NONINTERACTIVE
						 filename filename<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		  <span style="color: #66cc66;">&#40;</span>drawable <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>get<span style="color: #66cc66;">-</span>active<span style="color: #66cc66;">-</span>layer image<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
		  <span style="color: #66cc66;">&#40;</span>outf <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">string-append</span> outdir <span style="color: #ff0000;">&quot;/&quot;</span> filename<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	     <span style="color: #66cc66;">&#40;</span>resize<span style="color: #66cc66;">-</span>match<span style="color: #66cc66;">-</span>dpi image drawable newwidth newheight<span style="color: #66cc66;">&#41;</span>
	     <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>file<span style="color: #66cc66;">-</span>save RUN<span style="color: #66cc66;">-</span>NONINTERACTIVE image drawable outf outf<span style="color: #66cc66;">&#41;</span>
	     <span style="color: #66cc66;">&#40;</span>gimp<span style="color: #66cc66;">-</span>image<span style="color: #66cc66;">-</span>delete image<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
	   <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">set!</span> filelist <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> filelist<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>script<span style="color: #66cc66;">-</span>fu<span style="color: #66cc66;">-</span>register <span style="color: #ff0000;">&quot;resize-match-dpi&quot;</span>
  <span style="color: #ff0000;">&quot;&lt;Image&gt;/Script-Fu/Resize Match DPI&quot;</span>
  <span style="color: #ff0000;">&quot;Resize and match DPI&quot;</span>
  <span style="color: #ff0000;">&quot;odie5533&quot;</span>
  <span style="color: #ff0000;">&quot;odie5533&quot;</span>
  <span style="color: #ff0000;">&quot;2010-05-16&quot;</span>
  <span style="color: #ff0000;">&quot;RGB*&quot;</span>
  SF<span style="color: #66cc66;">-</span>IMAGE <span style="color: #ff0000;">&quot;Image&quot;</span>  <span style="color: #cc66cc;">0</span>
  SF<span style="color: #66cc66;">-</span>DRAWABLE <span style="color: #ff0000;">&quot;Drawable&quot;</span> <span style="color: #cc66cc;">0</span>
&nbsp;
  SF<span style="color: #66cc66;">-</span>VALUE  <span style="color: #ff0000;">&quot;New width&quot;</span> <span style="color: #ff0000;">&quot;1280&quot;</span>
  SF<span style="color: #66cc66;">-</span>VALUE  <span style="color: #ff0000;">&quot;New height&quot;</span> <span style="color: #ff0000;">&quot;0&quot;</span>
<span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://odie5533.com/304-gimp-resize-and-match-dpi-in-scheme/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TinyPic Command Line Uploader in AWK</title>
		<link>http://odie5533.com/286-tinypic-command-line-uploader-in-awk</link>
		<comments>http://odie5533.com/286-tinypic-command-line-uploader-in-awk#comments</comments>
		<pubDate>Wed, 05 May 2010 15:05:37 +0000</pubDate>
		<dc:creator>odie5533</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Awk]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[TinyPic]]></category>

		<guid isPermaLink="false">http://odie5533.com/?p=286</guid>
		<description><![CDATA[This AWK script uploads an image to TinyPic.com and returns the direct url to the uploaded image. Example script usage: $ awk -f tinypic.awk The_Grass_Snake_-_Natrix_natrix.jpg http://i39.tinypic.com/dlnb6r.jpg Let me start by saying I have no idea why I wrote this in AWK. I&#8217;ve only used AWK once before for a very short one-liner. I find AWK [...]]]></description>
			<content:encoded><![CDATA[<p>This AWK script uploads an image to <a href="http://tinypic.com">TinyPic.com</a> and returns the direct url to the uploaded image.</p>

<p>Example script usage:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-f</span> tinypic.awk The_Grass_Snake_-_Natrix_natrix.jpg
http:<span style="color: #000000; font-weight: bold;">//</span>i39.tinypic.com<span style="color: #000000; font-weight: bold;">/</span>dlnb6r.jpg</pre></div></div>


<p>Let me start by saying I have no idea why I wrote this in AWK. I&#8217;ve only used AWK once before for a very short one-liner. I find AWK to be better than Perl, but worse than Python. It does make for a light and portable language: the Windows AWK executable (<a href="http://gnuwin32.sourceforge.net/packages/gawk.htm">available here</a>) is only 345 KB, combine with Windows cURL (<a href="http://curl.haxx.se/download.html#Win32">available here</a>) which is 405 KB and you&#8217;re still under a meg for both. My bloated Python install is over 100 MB and I just installed <a href="http://strawberryperl.com/">Strawberry Perl</a> which is 174 MB.</p>

<p>If you like this post, please comment. Commenting is fast, anonymous, and much appreciated.<span id="more-286"></span></p>

<p>Here&#8217;s the script. Save as tinypic.awk</p>


<div class="wp_syntax"><div class="code"><pre class="awk" style="font-family:monospace;"><span style="color: #C20CB9; font-weight: bold;">BEGIN</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    file = <span style="color: #4107D5; font-weight: bold;">ARGV</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
    <span style="color:#808080;"># parse file extension</span>
    <span style="color: #07D589; font-weight: bold;">split</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>file, arr, <span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;
    file_ext = arr<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #07D589; font-weight: bold;">length</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>arr<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
&nbsp;
    url = <span style="color: #ff0000;">&quot;http://plugin.tinypic.com/plugin/index.php?popts=c,url<span style="color: #000099; font-weight: bold;">\\</span>|s,false&quot;</span>;
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;curl -s &quot;</span> url | <span style="color: #0BD507; font-weight: bold;">getline</span> <span style="color:#000088;">$0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color:black;">&gt;</span> <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color:#808080;"># parse necessary post variables from the HTML page</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #07D589; font-weight: bold;">match</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color:#000088;">$0</span>, <span style="color: #ff0000;">&quot;form action=<span style="color: #000099; font-weight: bold;">\&quot;</span>http://s(.)&quot;</span>, arr<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            server = arr<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #07D589; font-weight: bold;">match</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color:#000088;">$0</span>, <span style="color:black;">/</span>id=<span style="color: #ff0000;">&quot;uid&quot;</span> value=<span style="color: #ff0000;">&quot;([^&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color:black;">+</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color:black;">/</span>, arr<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            uid = arr<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
        <span style="color: #000000; font-weight: bold;">if</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color:black;">!</span>uid <span style="color:black;">&amp;&amp;</span> <span style="color: #07D589; font-weight: bold;">match</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color:#000088;">$0</span>, <span style="color:black;">/</span>name=<span style="color: #ff0000;">&quot;UPLOAD_IDENTIFIER&quot;</span> value=<span style="color: #ff0000;">&quot;([^&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color:black;">+</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color:black;">/</span>, arr<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            uid = arr<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #07D589; font-weight: bold;">match</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color:#000088;">$0</span>, <span style="color:black;">/</span>name=<span style="color: #ff0000;">&quot;upk&quot;</span> value=<span style="color: #ff0000;">&quot;([^&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color:black;">+</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color:black;">/</span>, arr<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            upk = arr<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
    <span style="color:#808080;"># compile curl command to upload the file</span>
    curl_cmd = <span style="color: #07D589; font-weight: bold;">sprintf</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;curl -s -L -F UPLOAD_IDENTIFIER=<span style="color: #000099; font-weight: bold;">\&quot;</span>%s<span style="color: #000099; font-weight: bold;">\&quot;</span> -F upk=<span style="color: #000099; font-weight: bold;">\&quot;</span>%s<span style="color: #000099; font-weight: bold;">\&quot;</span> -F domain_lang=<span style="color: #000099; font-weight: bold;">\&quot;</span>en<span style="color: #000099; font-weight: bold;">\&quot;</span> -F action=<span style="color: #000099; font-weight: bold;">\&quot;</span>upload<span style="color: #000099; font-weight: bold;">\&quot;</span> -F MAX_FILE_SIZE=<span style="color: #000099; font-weight: bold;">\&quot;</span>500000000<span style="color: #000099; font-weight: bold;">\&quot;</span> -F shareopt=<span style="color: #000099; font-weight: bold;">\&quot;</span>true<span style="color: #000099; font-weight: bold;">\&quot;</span> -F the_file=<span style="color: #000099; font-weight: bold;">\&quot;</span>@%s<span style="color: #000099; font-weight: bold;">\&quot;</span> -F file_type=<span style="color: #000099; font-weight: bold;">\&quot;</span>image<span style="color: #000099; font-weight: bold;">\&quot;</span> -F dimension=<span style="color: #000099; font-weight: bold;">\&quot;</span>1600<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\&quot;</span>http://s%s.tinypic.com/plugin/upload.php<span style="color: #000099; font-weight: bold;">\&quot;</span> -H <span style="color: #000099; font-weight: bold;">\&quot;</span>Expect:<span style="color: #000099; font-weight: bold;">\&quot;</span> -e <span style="color: #000099; font-weight: bold;">\&quot;</span>http://plugin.tinypic.com/plugin/index.php<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span>, uid, upk, file, server<span style="color: #7a0874; font-weight: bold;">&#41;</span>;
&nbsp;
    <span style="color:#808080;"># upload the picture and parse the picture URL</span>
    <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>curl_cmd | <span style="color: #0BD507; font-weight: bold;">getline</span> <span style="color:#000088;">$0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color:black;">&gt;</span> <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #07D589; font-weight: bold;">match</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color:#000088;">$0</span>, <span style="color:black;">/</span>name=<span style="color: #ff0000;">&quot;pic&quot;</span> value=<span style="color: #ff0000;">&quot;([^&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color:black;">+</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color:black;">/</span>, arr<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            img = arr<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #07D589; font-weight: bold;">match</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color:#000088;">$0</span>, <span style="color:black;">/</span>name=<span style="color: #ff0000;">&quot;ival&quot;</span> value=<span style="color: #ff0000;">&quot;([^&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color:black;">+</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color:black;">/</span>, arr<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            ival = arr<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">1</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>img <span style="color:black;">&amp;&amp;</span> ival<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #0BD507; font-weight: bold;">printf</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #ff0000;">&quot;http://i%s.tinypic.com/%s%s&quot;</span>, ival, img, <span style="color: #ff0000;">&quot;.&quot;</span> file_ext<span style="color: #7a0874; font-weight: bold;">&#41;</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #0BD507; font-weight: bold;">print</span> <span style="color: #ff0000;">&quot;Unable to parse the return page.&quot;</span>;
    <span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://odie5533.com/286-tinypic-command-line-uploader-in-awk/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wiki Parser v0.1 &#8211; Read Wikipedia Offline</title>
		<link>http://odie5533.com/236-wikiparserv01-read-wikipedia-offline</link>
		<comments>http://odie5533.com/236-wikiparserv01-read-wikipedia-offline#comments</comments>
		<pubDate>Thu, 15 Apr 2010 04:13:00 +0000</pubDate>
		<dc:creator>odie5533</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Wiki]]></category>

		<guid isPermaLink="false">http://odie5533.com/?p=236</guid>
		<description><![CDATA[Wiki Parser is a Python program which takes a Wikipedia dump and hosts it locally, offline. To save disk space, Wiki Parser keeps the dump compressed and serves articles to a web browser without decompressing the entire file. I originally created it to serve up Wikipedia articles from a compressed version, but seek times on [...]]]></description>
			<content:encoded><![CDATA[<p>Wiki Parser is a Python program which takes a Wikipedia dump and hosts it locally, offline. To save disk space, Wiki Parser keeps the dump compressed and serves articles to a web browser without decompressing the entire file. I originally created it to serve up Wikipedia articles from a compressed version, but seek times on the compressed file were too great and the program really only works on smaller Wikipedias such as the Simple English Wikipedia.</p>

<p><a href="http://download.wikimedia.org/simplewiki/20100401/">Download the latest dump of Simple English Wikipedia here</a>
<a href="programs/WikiParser/Wiki Parser v0.1.zip">Download Wiki Parser v0.1 here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://odie5533.com/236-wikiparserv01-read-wikipedia-offline/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Twisted Python library to replicate packets</title>
		<link>http://odie5533.com/195-using-twisted-python-library-to-replicate-packets</link>
		<comments>http://odie5533.com/195-using-twisted-python-library-to-replicate-packets#comments</comments>
		<pubDate>Sat, 01 Aug 2009 13:43:54 +0000</pubDate>
		<dc:creator>odie5533</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Twisted]]></category>

		<guid isPermaLink="false">http://odie5533.com/?p=195</guid>
		<description><![CDATA[Most of the programming I do is packet replication and automation. My workflow is to first analyze the handshakes and protocols in FireFox with the Tamper Data add-on. I use WireShark to nail down the interaction details. Finally, I recreate everything using the Twisted library in Python. Here&#8217;s a boilerplate to quickly recreate packets using [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the programming I do is packet replication and automation. My workflow is to first analyze the handshakes and protocols in FireFox with the <a href="http://tamperdata.mozdev.org/">Tamper Data add-on</a>. I use <a href="http://www.wireshark.org/">WireShark</a> to nail down the interaction details. Finally, I recreate everything using the <a href="http://twistedmatrix.com/trac/">Twisted</a> library in Python.</p>

<p>Here&#8217;s a boilerplate to quickly recreate packets using Twisted. It requests and saves a copy of Google.com. Simply replace with your favorite URL, or un-comment the two lines and comment the other getPage to send a POST request.</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">web</span> <span style="color: #ff7700;font-weight:bold;">import</span> client
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">internet</span> <span style="color: #ff7700;font-weight:bold;">import</span> reactor
&nbsp;
agent = <span style="color: #483d8b;">&quot;Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.12) Gecko/2009070611 Firefox/3.0.12 (.NET CLR 3.5.30729)&quot;</span>
headers = <span style="color: black;">&#123;</span><span style="color: #483d8b;">'Accept'</span>:<span style="color: #483d8b;">'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'</span>, <span style="color: #483d8b;">'Accept-Language'</span>:<span style="color: #483d8b;">'en-us,en;q=0.5'</span>, <span style="color: #483d8b;">'Accept-Charset'</span>:<span style="color: #483d8b;">'ISO-8859-1,utf-8;q=0.7'</span><span style="color: black;">&#125;</span>
headers_post = headers.<span style="color: #dc143c;">copy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
headers_post<span style="color: black;">&#91;</span><span style="color: #483d8b;">'Content-Type'</span><span style="color: black;">&#93;</span> = <span style="color: #483d8b;">'application/x-www-form-urlencoded'</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> success<span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Success!&quot;</span>
    f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'save.html'</span>,<span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
    f.<span style="color: black;">write</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
    f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    reactor.<span style="color: black;">stop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> failure<span style="color: black;">&#40;</span>fail<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> fail.<span style="color: black;">getErrorMessage</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    reactor.<span style="color: black;">stop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> request<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    url = <span style="color: #483d8b;">&quot;http://google.com/&quot;</span>
    d = client.<span style="color: black;">getPage</span><span style="color: black;">&#40;</span>url, headers=headers, agent=agent<span style="color: black;">&#41;</span>
    <span style="color: #808080; font-style: italic;">#post_data = &quot;&quot;</span>
    <span style="color: #808080; font-style: italic;">#d = client.getPage(url, postdata=post_data, method=&quot;POST&quot;, headers=headers_post, agent=agent)</span>
    d.<span style="color: black;">addCallback</span><span style="color: black;">&#40;</span>success<span style="color: black;">&#41;</span>.<span style="color: black;">addErrback</span><span style="color: black;">&#40;</span>failure<span style="color: black;">&#41;</span>
&nbsp;
request<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
reactor.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>


<p>To make it continually request the same page, change the success method to this:</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> success<span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Success!&quot;</span>
    f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'save.html'</span>,<span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
    f.<span style="color: black;">write</span><span style="color: black;">&#40;</span>data<span style="color: black;">&#41;</span>
    f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    reactor.<span style="color: black;">callLater</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">0.5</span>, request<span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://odie5533.com/195-using-twisted-python-library-to-replicate-packets/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Async Download with Curl in Irssi Perl Scripting</title>
		<link>http://odie5533.com/180-async-download-with-curl-in-irssi-perl-scripting</link>
		<comments>http://odie5533.com/180-async-download-with-curl-in-irssi-perl-scripting#comments</comments>
		<pubDate>Sun, 11 Jan 2009 03:17:03 +0000</pubDate>
		<dc:creator>odie5533</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[IRC]]></category>
		<category><![CDATA[irssi]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://odie5533.com/?p=180</guid>
		<description><![CDATA[When downloading a file from Perl, there’s many ways to go about it. You can use LWP, libcurl, wget, curl the program, etc. My shell hoster doesn’t include many perl bindings so I can’t use LWP or libcurl. I use curl -s $url to download urls. The only problem with using any of the above [...]]]></description>
			<content:encoded><![CDATA[<p>When downloading a file from Perl, there’s many ways to go about it. You can use LWP, libcurl, wget, curl the program, etc. My shell hoster doesn’t include many perl bindings so I can’t use LWP or libcurl. I use <code>curl -s $url</code> to download urls. The only problem with using any of the above mentioned methods is that they all block Irssi until the page is downloaded. That means the client freezes and doesn’t respond to pings during this time. To remedy this, fork can be used. But fork is rather screwy in Irssi; if you use it wrong, it will create 2 instances of Irssi.</p>

<p>The fix? Use someone else&#8217;s code that works. Here&#8217;s mine, released under the GNU GPL. It can easily be adapted, and should be, to use LWP or libcurl if your client supports those.</p>


<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Irssi<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> POSIX<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> async_curl <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$$</span><span style="color: #0000ff;">$)</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$geturl</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$callback</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$argref</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$reader</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$writer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">pipe</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$reader</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$writer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$pid</span> <span style="color: #339933;">=</span> <span style="color: #000066;">fork</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$pid</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$writer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                Irssi<span style="color: #339933;">::</span><span style="color: #006600;">pidwait_add</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$pid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$pipetag</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@pargs</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$reader</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">\$pipetag</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$callback</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$argref</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #0000ff;">$pipetag</span> <span style="color: #339933;">=</span> Irssi<span style="color: #339933;">::</span><span style="color: #006600;">input_add</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">fileno</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$reader</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> INPUT_READ<span style="color: #339933;">,</span> <span style="color: #0000ff;">\&amp;pipe_input</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">\@pargs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$content</span><span style="color: #339933;">;</span>
          <span style="color: #000066;">eval</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$data</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`curl -s &quot;$geturl&quot;`</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$writer</span> <span style="color: #0000ff;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$writer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
          POSIX<span style="color: #339933;">::</span>_exit<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> pipe_input <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$$</span><span style="color: #0000ff;">$$</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$reader</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$pipetag</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$callback</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$argref</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$_</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@lines</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&lt;</span><span style="color: #0000ff;">$reader</span><span style="color: #339933;">&gt;;</span>
        <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$reader</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        Irssi<span style="color: #339933;">::</span><span style="color: #006600;">input_remove</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$$pipetag</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$text</span> <span style="color: #339933;">=</span> <span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@lines</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$callback</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$text</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$argref</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>


<p>Using this code is very simple. Here’s a quick example:</p>


<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">sub</span> callback_method <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$content</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$argref</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$arg1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$arg2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$argref</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;"># Here we have the $content from the url</span>
        <span style="color: #666666; font-style: italic;"># and the two args we wanted back</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Gather up any arguments we want to piggy-back onto the callback</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@args</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'test1'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'test2'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># Call async_curl with a reference to our callback method</span>
<span style="color: #666666; font-style: italic;"># and a reference to our piggy-back args</span>
async_curl<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;http://www.google.com/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">\&amp;callback_method</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">\@args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://odie5533.com/180-async-download-with-curl-in-irssi-perl-scripting/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Python FTP upload using Twisted</title>
		<link>http://odie5533.com/187-python-ftp-upload-using-twisted</link>
		<comments>http://odie5533.com/187-python-ftp-upload-using-twisted#comments</comments>
		<pubDate>Mon, 22 Dec 2008 03:23:01 +0000</pubDate>
		<dc:creator>odie5533</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[Twisted]]></category>

		<guid isPermaLink="false">http://odie5533.com/?p=187</guid>
		<description><![CDATA[Here’s a snippet for uploading a file via FTP using the Twisted Python library available from TwistedMatrix. from twisted.protocols.basic import FileSender from twisted.protocols.ftp import FTPClient from twisted.internet.protocol import ClientCreator from twisted.internet import reactor &#160; def fileTransferFail&#40;failure&#41;: failure.printTraceback&#40;&#41; reactor.stop&#40;&#41; &#160; def cbStore&#40;consumer, filename&#41;: fs = FileSender&#40;&#41; d = fs.beginFileTransfer&#40;open&#40;filename, 'r'&#41;, consumer&#41; d.addCallback&#40;lambda _: consumer.finish&#40;&#41;&#41;.addErrback&#40;fileTransferFail&#41; return d [...]]]></description>
			<content:encoded><![CDATA[<p>Here’s a snippet for uploading a file via FTP using the Twisted Python library available from <a href="http://twistedmatrix.com/">TwistedMatrix</a>.</p>


<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">protocols</span>.<span style="color: black;">basic</span> <span style="color: #ff7700;font-weight:bold;">import</span> FileSender
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">protocols</span>.<span style="color: black;">ftp</span> <span style="color: #ff7700;font-weight:bold;">import</span> FTPClient
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">internet</span>.<span style="color: black;">protocol</span> <span style="color: #ff7700;font-weight:bold;">import</span> ClientCreator
<span style="color: #ff7700;font-weight:bold;">from</span> twisted.<span style="color: black;">internet</span> <span style="color: #ff7700;font-weight:bold;">import</span> reactor
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> fileTransferFail<span style="color: black;">&#40;</span>failure<span style="color: black;">&#41;</span>:
    failure.<span style="color: black;">printTraceback</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    reactor.<span style="color: black;">stop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> cbStore<span style="color: black;">&#40;</span>consumer, filename<span style="color: black;">&#41;</span>:
    fs = FileSender<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    d = fs.<span style="color: black;">beginFileTransfer</span><span style="color: black;">&#40;</span><span style="color: #008000;">open</span><span style="color: black;">&#40;</span>filename, <span style="color: #483d8b;">'r'</span><span style="color: black;">&#41;</span>, consumer<span style="color: black;">&#41;</span>
    d.<span style="color: black;">addCallback</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> _: consumer.<span style="color: black;">finish</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">addErrback</span><span style="color: black;">&#40;</span>fileTransferFail<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> d
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> connectionMade<span style="color: black;">&#40;</span>ftpClient, filename, uploadpath = <span style="color: #008000;">None</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">if</span> uploadpath <span style="color: #ff7700;font-weight:bold;">is</span> <span style="color: #008000;">None</span>:
        uploadpath = filename
    d1, d2 = ftpClient.<span style="color: black;">storeFile</span><span style="color: black;">&#40;</span>uploadpath<span style="color: black;">&#41;</span>
    d1.<span style="color: black;">addCallback</span><span style="color: black;">&#40;</span>cbStore, filename<span style="color: black;">&#41;</span>.<span style="color: black;">addErrback</span><span style="color: black;">&#40;</span>fileTransferFail<span style="color: black;">&#41;</span>
    d2.<span style="color: black;">addCallback</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> _: reactor.<span style="color: black;">stop</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> d2
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> sendFile<span style="color: black;">&#40;</span>host, port, username, password, filename, uploadpath<span style="color: black;">&#41;</span>:
    creator = ClientCreator<span style="color: black;">&#40;</span>reactor, FTPClient, username, password<span style="color: black;">&#41;</span>
    d = creator.<span style="color: black;">connectTCP</span><span style="color: black;">&#40;</span>host, port<span style="color: black;">&#41;</span>
    d.<span style="color: black;">addCallback</span><span style="color: black;">&#40;</span>connectionMade, filename, uploadpath<span style="color: black;">&#41;</span>.<span style="color: black;">addErrback</span><span style="color: black;">&#40;</span>fileTransferFail<span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">return</span> d
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">'__main__'</span>:
    username = <span style="color: #483d8b;">'GoogleUser'</span>
    password = <span style="color: #483d8b;">'GoogleSuperSecretPassword'</span>
    host = <span style="color: #483d8b;">'google.com'</span>
    port = <span style="color: #ff4500;">21</span>
    filename = <span style="color: #483d8b;">'index.html'</span>
    uploadto = <span style="color: #483d8b;">'/public_html/index.html'</span>
    sendFile<span style="color: black;">&#40;</span>host, port, username, password, filename, uploadto<span style="color: black;">&#41;</span>
    reactor.<span style="color: black;">run</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://odie5533.com/187-python-ftp-upload-using-twisted/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
