also available in rss format
04/04/09 @ 10:50:51
you may (or most likely may not) have noticed i've had a few problems with twitpic and twitxr of late. not that either of the services aren't admirable and thoroughly decent but for my purposes neither quite hit the mark. twitpic's xml feed changed since they switched to new servers (basically destroying my uberFeed call no matter how much fiddling i did to fix) and twitxr seems to have an issue with the shortening of urls when posted to your linked twitter account (if you post in the region of 120chars + url) - this was all much to the annoyance of some of my followers who were quick to pick me up on the fact that my boring snapshots had failed - nice one Dean / Tim / Rob!
if you want a job doing, do it yourself - the old adage runs true, at least this way i'd have full control over the output and not be reliant on a third party who might change their setup without warning and subsequently break my code.
the snapping of a scene and sending it to twitter with my mobile phone has so far quenched my prattling needs so that method needed to be followed with the new system. first off i needed an account i could access with coldfusion and being an avid google fanboy i set one up. after a bit of poking around it would seem CF7 doesn't directly support google's pop3 implementation over SSL but after some in depth research (we all know what that means) i found a nice stub of code which when placed before the cfpop tag utilises the underlying java to enable it:
<!--- set some java properties to enable ssl use with gmail --->
<cfset javaSystem = createObject("java", "java.lang.System") />
<cfset jProps = javaSystem.getProperties() />
<cfset jProps.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory") />
<cfset jProps.setproperty("mail.pop3.port",995) />
<cfset jProps.setProperty("mail.pop3.socketFactory.port", 995) />
the cfpop tag did its thing and looping over the data produced some fine header information about what was sitting in the box. it's at this point we really should consider security, you don't afterall want spammers emailing you obscene material only to find your autoEmail process has published it under your name for all the world to see. the best way to deal with it i concluded would be to only process emails that came from a reputable source ie me :) so a quick check before processing that the current email record's 'from' was from me did the trick.
using a second cfpop tag to get at the current message via it's uniqueId (uid) provided some more data to work with including checking for an extension of 'jpg' on the extracted attachment (not foolproof of course but enough for a single user). at this point we can be fairly confident the message isn't bogus and the real processing can begin:
<cfset thisTimeStamp = #dateFormat(Now(),'DDMMYY')# & #timeFormat(Now(),'HHMMSS')#>
<cfset thisFile = "posted_" & thisTimeStamp & ".jpg">
<cffile action="rename" source="#expandPath('./')#images\#email.attachments#" destination="#thisFile#">
<cfset thisPath = expandPath('./') & "images\" & thisFile>
<cfset thisUrl = siteUrl & "?post=" & thisTimeStamp>
<cfset thisSubject = email.subject>
<cfset thisSubjectLen = len(thisSubject)>
this little lot just renames the attachment to something unique (dateTime) and gives us the url which we'll ultimately be sending visitors to (that page is just one that's waiting for a post= url parameter to display the pic). please note #siteUrl# is a global variable and #email.xx# variables were provided by the cfpop query. now, why do you think we've set #thisSubjectLen#? because, frankly it matters if we want to update twitter with our new status since it has a 140chars limit - you'll see it later on.
now we move into the final exciting stages and API (application programming interface) goodness.
this was very simple but pleasing chunk of code for setting up the final status ready for sending to twitter:
<cfhttp method="Get" url="http://is.gd/api.php?longurl=#thisUrl#" result="shortUrl">
<cfset shortUrl = trim(shortUrl.fileContent)>
<cfset shortUrlLen = len(shortUrl)>
<cfif shortUrlLen thisSubjectLen GT 137>
<cfset status = left(thisSubject,thisSubjectLen-shortUrlLen-4) & " - " & shortUrl>
<cfelse>
<cfset status = thisSubject & " - " & shortUrl>
</cfif>
firstly a 'cfhttp get' to http://is.gd (url shortening service's API - i use the term loosely in this instance) and pass it our created url, then grab the newly shortened url from the fileContent returned and tack it onto the end of the email's subject. you may notice a basic calculation in there for making sure the subject and the hypen sandwiched by spaces + the url doesn't go over the 140 limit - something twitxr would be wise implement!
finally the status package is sent to twitter via it's own API and BAM! the job is complete!
<cfhttp url="http://twitter.com/statuses/update.xml" method="post" username="#twitterUser#" password="#twitterPass#"
<cfhttpparam name="status" value="#status#" type="formfield" />
</cfhttp>
i'd recommend setting up a test twitter account before you go live with this bit since you're likely to irritate any followers with test status updates.
don't forget to add your cf template to the cfschedule for processing every so often, if you don't the script won't ever check that bulging pop3 box of yours.
summing up
in short we've done all the following:
- checked a pop3 account for messages
- looped over each message check it's from a trusted source
- extracted a jpg attachment and created a url to it
- shortened the url
- appended the shortened url to the email's subject
- sent the status update to twitter

on 05/09/10 @ 10:23:11 posted from twitter
is dukenukem forever really gonna happen in 2011? linkage bring it on!

on 02/09/10 @ 19:15:28 posted from twitter
google's new artificial intelligence API linkage (aka skynet!)

on 17/08/10 @ 21:17:04 posted from google news
oh yes! stay on target.

on 03/08/10 @ 21:29:57 posted from google news
been using this for a while, can say it's rather excellent.

on 23/07/10 @ 16:54:02 posted from google news
believe it or not, whilst reading this - i got distracted :-/

on 23/07/10 @ 16:41:25 posted from google news
i'd missed this... how many more variations on the size of panel do we need?

on 02/06/10 @ 17:31:38 posted from google news
the classic DB5 up for auction, yeah - i'll be bidding...

on 28/04/10 @ 14:12:45 posted from newWord
bigot - a prejudiced person who is intolerant of any opinions differing from their own

on 04/04/10 @ 12:00:00 posted from picasa
an Easter bank holiday weekend away in Devon
5 photos after the jump!

on 07/03/10 @ 19:33:43 posted from picasa
a week's holiday in the Canaries, March 2010
33 photos after the jump!

on 11/02/10 @ 13:00:00 posted from picasa
a bunch of random photos taken when out and about
7 photos after the jump!

on 09/01/10 @ 17:51:42 posted from picasa
a chilly walk out across the Studland beach in Dorset
18 photos after the jump!

on 23/12/09 @ 16:21:46 posted from picasa
good ol' family xmas in Sparsholt, Oxfordshire 2009
17 photos after the jump!

on 05/10/09 @ 11:51:32 posted from youtube
time lapse test of me sat at my desk for a couple of hours (not exciting!). taken using sheado.net 'time-lapse' application on Android phone
42 second clip after the jump!

on 25/08/09 @ 06:44:33 posted from youtube
the stunning Eurofighter Typhoon seen at Bournemouth Air Festival 2009
170 second clip after the jump!

on 24/07/09 @ 17:39:54 posted from youtube
This video was uploaded from an Android phone.
20 second clip after the jump!

on 17/07/09 @ 13:35:48 posted from youtube
This video was uploaded from an Android phone.
14 second clip after the jump!

on 15/03/09 @ 21:23:31 posted from youtube
the lovely Durdle seen from the cliff above on a sunny Sunday in March
65 second clip after the jump!
Coldfusion
- a much faster homepage
- pop3 picture extraction and API fun
- lukes uberfeed
Random
- download festival 2009
- hashtag invented
- learn some new words
- xmas messages