Posted: January 6, 2010 at 5:13 PM by jbuda
Tags: Coldfusion, Mango Blog
As I upload the majority of my images via my telephone to Twitpic, as opposed to Flickr. I decided to try and get a plugin to display images from my account, the Twitpic API only allows for uploading images and posting them to the site.
A bit of investigation pointed me to scraping the site to pick up the images posted by myself. Using Coldfusion this has been pretty simple and came up with this small script to get all the link tags wrapped around images.
<cfset urlstring = 'http://twitpic.com/photos/jbuda' /> <cfhttp url="#urlstring#" method="get" /> <cfset rawUrl = toString(cfhttp.filecontent) /> <cfset pos = 1 /> <cfset imageArray = arrayNew(1) /> <cfset regexp = '«div class="profile-photo-img">(.*?)</div>' /» <cfset found = refindnocase(regexp,rawUrl,pos,true) /> <cfloop condition="pos lt len(rawUrl)"> <cfset found = refindnocase(regexp,rawUrl,pos,true) /> <cfset pos = found.pos[1] + found.len[1] /> <cfif found.len[1] eq 0> <cfbreak /> <cfelse> <cfset img = mid(rawUrl,found.pos[2],found.len[2]) /> <cfset arrayAppend(imageArray,img) /> </cfif> </cfloop>
I have created a plugin for Mango Blog for this functionality, but there is still some bits i would like to refine and add custom css to it.
I will post the plugin onto Mango Blog once i have got it finished.

Jan 6, 2010 at 8:50 PM Sweet. I had this on my to-do list but never got around to it. Glad your getting it to work.
Jan 7, 2010 at 12:58 AM @mark Was pretty straightforward to get it extracting the images. Just think I need to think about page loading when retrieving the data from the twitpic website. Should have plugin sorted in the next couple of days.
Jan 7, 2010 at 6:35 AM inside your plugin you can cache the results so you don't have to scrape the twitpic site each time. Check out my Netflix plugin for an example on how to do that.
Jan 7, 2010 at 7:08 AM @mark Ah cool, think i will release this as a plugin first and then have a look at your Netflix example. I will release this in another version with the caching activated.