Friday, March 28, 2008

Uploading Images to Flickr using flickcurl and Groovy

For the latest Groosh release I created an more elaborate example of how to use Groovy and Groosh. This example shows how to upload Images to a Flickr account using Groovy, Groosh and flickcurl.

import static groosh.Groosh.groosh
import static org.codehaus.groovy.groosh.stream.DevNull.devnull

ids = [:]
shell = groosh()

//get all images in this folder and upload it to flickr
//remember the photo id we get from flickr
shell.ls().grep(~/.*jpg/).each {
println "Uploading file $it to flickr"
flickcurl = shell.flickcurl("upload",it,"friend","family")
.useError(true)
id = flickcurl.grep(~/.*Photo ID.*/)[0].split(":")[1].trim()
ids[it] = id
println "Photo ID is: $id"
}
//we need to know the first photo id
firstKey = ids.keySet().toList()[0]

//create a set with the name of the directory we are in right now
//use the id of the first photo as set cover
setName = shell.pwd().text.split("/")[-1]
println "Creating set: $setName"
flickcurl = shell.flickcurl("photosets.create",setName,setName,ids[firstKey])
.useError(true)
id = flickcurl.grep(~/.*Photoset.*/)[0].split(" ")[2].trim()
println "Photoset ID is: $id"

//make a backup of the ids in a file for later reference
println "Writing ids to a file"
file = new File(shell.pwd().text.trim() + "/.flickrset")
file << "Photoset:" << id << "\n"
ids.each {
file << it.key << ":" << it.value << "\n"
}

//the first photo is allready part of the photo set so lets remove it
ids.remove(firstKey)

//add the remaining photos to the photo set
ids.each {
println "Adding photo to set at flickr: $it"
shell.flickcurl("photosets.addPhoto",id,it.value) | devnull()
}

println "DONE"

Groosh 0.3.0 released

Version 0.3.0 of Groosh released

Groosh (http://groovy.codehaus.org/Groosh) provides shell-like capability for handling external processes for Groovy.

Version 0.3.0 comes with several bug fixes and new features like:

  • The error stream of a process is now usable the same way as the output stream (useError()).
  • A grep method was added which can be used to filter the lines returned by a process.
  • A to List method was added which creates a list out of the lines returned by a process.
  • A eachLine method was added which iterates over the lines returned by a process.
  • The exit values of a process are now accessible. (Thx to Bill Burdick)
  • left shift and right shift operators are overloaded for processes and stream sinks.
  • the pipe operator was overloaded to allow chaining of processes

For more information on Groosh and examples of its use see:
http://groovy.codehaus.org/Groosh

Groosh 0.3.0 can be downloaded from

http://svn.codehaus.org/groovy-contrib/groosh/releases/

OpenSUSE RPM packages are available from

http://download.opensuse.org/repositories/home:/eggeral/openSUSE_10.3/
and
http://download.opensuse.org/repositories/home:/eggeral/openSUSE_10.2/

Friday, March 21, 2008

Setting up openSuse build service for the generation of javac dependent packages

I have my own little openSuse build service account for the generation of same Java related packages. Mainly Groovy stuff.

If you want to use javac in the build process you need to add the build requirement to java-devel. Unfortunately this package is not available in the openSUSE_10.2 and openSUSE_10.3 standard repositories. They are available in the openSUSE_10.2:NonFree and openSUSE_10.2:NonFree repositories, but there is no option in the web interface of the build service which allows to configure this.

You have to use the build service API do change this configuration. Which is in fact very easy because the API is a REST like service which can be used for example with kwrite.

So

kwrite https://api.opensuse.org/source/home:eggeral/_meta

allows you do edit the configuration of the repositories. Just add

<path project="openSUSE:10.3:NonFree" repository="standard">

and you have access to the Sun Java rpms.

See

http://news.opensuse.org/2007/07/18/nice-trick-to-use-apiopensuseorg-native-with-kde-apps/

for more information on the openSuse build service API.