<?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>coding &#187; flickr</title>
	<atom:link href="http://www.coding.com.br/tag/flickr/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coding.com.br</link>
	<description>have you coded today?</description>
	<lastBuildDate>Fri, 10 Sep 2010 00:18:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Download photos from Flickr!</title>
		<link>http://www.coding.com.br/programacao/download-photos-from-flickr/</link>
		<comments>http://www.coding.com.br/programacao/download-photos-from-flickr/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 01:35:22 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[programação]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=783</guid>
		<description><![CDATA[I think that one problem regarding creating a script to download photos form Flickr is getting copyrighted material. Suppose that you want all photos from Itajubá city. You can use Flickr API or an YQL request, as follows:
select * from flickr.photos.search where text="itajubá"
My first try to get license information was showing the pertinent part of [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">I think that one problem regarding creating a <em>script</em> to download photos form Flickr is getting copyrighted material. Suppose that you want all photos from Itajubá city. You can use Flickr API or an YQL request, as follows:</p>
<pre>select * from flickr.photos.search where text="itajubá"</pre>
<p style="text-align: justify;">My first try to get license information was showing the pertinent part of JSON output. You could see that there isn&#8217;t a field telling that, but if you look at documentation there&#8217;s a &#8220;license&#8221; parameter.</p>
<blockquote><p>&#8220;farm&#8221;: &#8220;5&#8243;,<br />
&#8220;id&#8221;: &#8220;4458853758&#8243;,<br />
&#8220;isfamily&#8221;: &#8220;0&#8243;,<br />
&#8220;isfriend&#8221;: &#8220;0&#8243;,<br />
&#8220;ispublic&#8221;: &#8220;1&#8243;,<br />
&#8220;owner&#8221;: &#8220;76062736@N00&#8243;,<br />
&#8220;secret&#8221;: &#8220;9edcd7aea8&#8243;,<br />
&#8220;server&#8221;: &#8220;4003&#8243;,<br />
&#8220;title&#8221;: &#8220;Clube&#8221;</p></blockquote>
<p>Flickr! has seven options to licensing your photo (again I didn&#8217;t found in documentation, I tried each one)</p>
<ul>
<li>None (All rights reserved) [ license="0" ]</li>
<li>Attribution-NonCommercial-ShareAlike Creative Commons [ license="1" ]</li>
<li>Attribution-NonCommercial Creative Commons [ license="2" ]</li>
<li>Attribution-NonCommercial-NoDerivs Creative Commons [ license="3" ]</li>
<li>Attribution Creative Commons [ license="4" ]</li>
<li>Attribution-ShareAlike Creative Commons [ license="5" ]</li>
<li>Attribution-NoDerivs Creative Commons [ license="6" ]</li>
</ul>
<p>My friend was looking to a way to download all photos from Yahoo! Open Hack Brazil so I decided to create a quick way to get theses photos (respecting copyrighted material). My <a href="http://developer.yahoo.com/yql/console/?q=select%20*%20from%20flickr.photos.search%20where%20text%3D%22Cat%22%20limit%200#h=select%20*%20from%20flickr.photos.search%280%2C2000%29%20where%20tags%3D%22brhackday%22%20and%20license%3D%221%2C2%2C3%2C4%2C5%2C6%22">query</a> looks like:</p>
<pre>select * from flickr.photos.search(0,2000) where tags="brhackday" and license="1,2,3,4,5,6"</pre>
<p style="text-align: justify;">After tests I put the URL from YQL virtual console in my Python code (that parses JSON) and generate a Shell Script to download (using curl/wget)</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> simplejson
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">urllib</span> 
&nbsp;
f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;download.sh&quot;</span>,<span style="color: #483d8b;">&quot;w+&quot;</span><span style="color: black;">&#41;</span>
f.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;#!/bin/sh<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: black;">&#41;</span>
i = <span style="color: #ff4500;">0</span>
<span style="color: #ff7700;font-weight:bold;">while</span> <span style="color: #008000;">True</span>:
&nbsp;
	url_base=<span style="color: #483d8b;">&quot;http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20flickr.photos.search(&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> 
+ <span style="color: #483d8b;">&quot;%2C&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>i+<span style="color: #ff4500;">100</span><span style="color: black;">&#41;</span> +<span style="color: #483d8b;">&quot;)%20where%20tags%3D%22brhackday%22%20and%20license%3D%221%2C2%2C3%2C4%2C5%2C6%22
&amp;format=json&quot;</span> 	
&nbsp;
	rest = simplejson.<span style="color: black;">load</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">urllib</span>.<span style="color: black;">urlopen</span><span style="color: black;">&#40;</span>url_base<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'query'</span><span style="color: black;">&#93;</span>
&nbsp;
        <span style="color: #ff7700;font-weight:bold;">if</span> rest<span style="color: black;">&#91;</span><span style="color: #483d8b;">'count'</span><span style="color: black;">&#93;</span> == <span style="color: #483d8b;">'0'</span>:
		f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
		exit<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> 
&nbsp;
	photos = rest<span style="color: black;">&#91;</span><span style="color: #483d8b;">'results'</span><span style="color: black;">&#93;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'photo'</span><span style="color: black;">&#93;</span> 
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">for</span> photo <span style="color: #ff7700;font-weight:bold;">in</span> photos:
		<span style="color: #008000;">id</span> = photo<span style="color: black;">&#91;</span><span style="color: #483d8b;">'id'</span><span style="color: black;">&#93;</span>
		owner = photo<span style="color: black;">&#91;</span><span style="color: #483d8b;">'owner'</span><span style="color: black;">&#93;</span>
		d = <span style="color: #483d8b;">&quot;curl -s http://www.flickr.com/photos/%s/%s/sizes/o 
| egrep <span style="color: #000099; font-weight: bold;">\&quot;</span>&lt;p&gt;&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span> 
| sed 's/&lt;p&gt;//g ; s/&lt;br <span style="color: #000099; font-weight: bold;">\/</span>&gt;//g ; s/&lt;<span style="color: #000099; font-weight: bold;">\/</span>p&gt;//g ; s/&lt;img src=<span style="color: #000099; font-weight: bold;">\&quot;</span>//g ; s/<span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\/</span>&gt;//g' 
| xargs wget ;&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>owner, <span style="color: #008000;">id</span><span style="color: black;">&#41;</span>
		f.<span style="color: black;">write</span><span style="color: black;">&#40;</span>d+<span style="color: #483d8b;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span><span style="color: black;">&#41;</span>
		i += <span style="color: #ff4500;">100</span>
&nbsp;
f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p style="text-align: justify;">Probably If you cut &amp; paste the code they will not work due some indentation issue, so I published in gist <a href="http://gist.github.com/346413">here</a>.</p>
<p>The usage I simple:</p>
<pre>$ python flickr-d.py
$ sh download.sh</pre>
<p>This was a extremely simple workaround but I expect you enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/programacao/download-photos-from-flickr/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Uploads de fotos no Flickr! usando API e Python</title>
		<link>http://www.coding.com.br/programacao/uploads-de-fotos-no-flickr-usando-api-e-python/</link>
		<comments>http://www.coding.com.br/programacao/uploads-de-fotos-no-flickr-usando-api-e-python/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 04:10:23 +0000</pubDate>
		<dc:creator>Tiago Maluta</dc:creator>
				<category><![CDATA[programação]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.coding.com.br/?p=663</guid>
		<description><![CDATA[A API (Interface de Programação de Aplicativo) do Flickr! é bem documetada e rapidamente você pode fazer bastante coisa. Se você desejar usar a linguagem Python como método de acesso, em linhas gerais você precisa.

Criar uma chave na API do Flickr!
Download do binding para acesso a API (flickrapi)

Nas distribuições Linux, um dos jeitos de instalar [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">A API (Interface de Programação de Aplicativo) do <a href="www.flickr.com" target="_blank">Flickr!</a> é bem <a href="http://www.flickr.com/services/api/" target="_blank">documetada</a> e rapidamente você pode fazer bastante coisa. Se você desejar usar a linguagem Python como método de acesso, em linhas gerais você precisa.</p>
<ol>
<li><a href="http://www.flickr.com/services/apps/create/" target="_blank">Criar</a> uma chave na API do Flickr!</li>
<li>Download do <em>binding</em> para acesso a API (<a href="http://pypi.python.org/pypi/flickrapi" target="_blank">flickrapi</a>)</li>
</ol>
<p>Nas distribuições Linux, um dos jeitos de instalar é usar o easy_install</p>
<pre>easy_install flickrapi</pre>
<p align="justify">
Um modo eficaz para fazer o <em>upload</em> das fotos no serviço seria um <em>script</em> que varre e submete todas as imagens, por exemplo, de uma pasta definida. O exemplo abaixo recebe como parâmetro um diretório e busca por todos os arquivos com extensão .jpg. A função <em>status</em> é apenas para mostrar o andamento do <em>upload</em> e é executada como uma chamada <em>callback</em> no método flickr.upload(). Nos meus testes, precisei pegar o número definido na variável <em>token</em>, antes, executando na interface de linha de comando do Python os seguintes passos:
</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #66cc66;">&gt;&gt;&gt;</span> api_key = <span style="color: #483d8b;">&quot;&lt;API&gt;&quot;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> secret = <span style="color: #483d8b;">&quot;&lt;CHAVE SECRETA&gt;&quot;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> username = <span style="color: #483d8b;">&quot;&lt;USER&gt;&quot;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> flickr = flickrapi.<span style="color: black;">FlickrAPI</span><span style="color: black;">&#40;</span>api_key,secret,username<span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: black;">&#40;</span><span style="color: #dc143c;">token</span>, frob<span style="color: black;">&#41;</span> = flickr.<span style="color: black;">get_token_part_one</span><span style="color: black;">&#40;</span>perms=<span style="color: #483d8b;">&quot;write&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">token</span>
<span style="color: #66cc66;">&gt;&gt;&gt;</span> <span style="color: #ff7700;font-weight:bold;">print</span> frob</pre></div></div>

<p>Na hora o <em>browser</em> padrão irá abrir e pedir para você confirmar o uso do aplicativo.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># -*- coding: utf-8 -*-</span>
<span style="color: #808080; font-style: italic;">#/bin/python </span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">glob</span> 
<span style="color: #ff7700;font-weight:bold;">import</span> flickrapi
&nbsp;
api_key = <span style="color: #483d8b;">&quot;&lt;API&gt;&quot;</span>
secret = <span style="color: #483d8b;">&quot;&lt;CHAVE SECRETA&gt;&quot;</span>
username = <span style="color: #483d8b;">&quot;&lt;USER&gt;&quot;</span>
&nbsp;
<span style="color: #dc143c;">token</span>=<span style="color: #483d8b;">&quot;&lt;TOKEN&gt;&quot;</span>
frob=<span style="color: #008000;">None</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> status<span style="color: black;">&#40;</span>progress, done<span style="color: black;">&#41;</span>:
	<span style="color: #ff7700;font-weight:bold;">if</span> done:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Finished ;-)&quot;</span>
	<span style="color: #ff7700;font-weight:bold;">else</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;At %s%%&quot;</span> <span style="color: #66cc66;">%</span> progress
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> upload<span style="color: black;">&#40;</span>photo<span style="color: black;">&#41;</span>:
	flickr.<span style="color: black;">upload</span><span style="color: black;">&#40;</span>photo, callback=status<span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> __name__ == <span style="color: #483d8b;">&quot;__main__&quot;</span>:
&nbsp;
        flickr = flickrapi.<span style="color: black;">FlickrAPI</span><span style="color: black;">&#40;</span>api_key,secret,username<span style="color: black;">&#41;</span>
        flickr.<span style="color: black;">get_token_part_two</span><span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">token</span>,frob<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
&nbsp;
        photos = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>+<span style="color: #483d8b;">&quot;*.jpg&quot;</span>
&nbsp;
	<span style="color: #ff7700;font-weight:bold;">for</span> photo <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #dc143c;">glob</span>.<span style="color: #dc143c;">glob</span><span style="color: black;">&#40;</span>photos<span style="color: black;">&#41;</span>:
		<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;Uploading: &quot;</span>,photo
		upload<span style="color: black;">&#40;</span>photo<span style="color: black;">&#41;</span></pre></div></div>

<p>Um exemplo de uso:</p>
<pre>
python upload.py /Fotos
</pre>
<p>Utilize sua criatividade para extender essa idéia e criar aplicativos que ensinem e facilite sua vida. <img src='http://www.coding.com.br/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.coding.com.br/programacao/uploads-de-fotos-no-flickr-usando-api-e-python/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
