Friday, May 06, 2016

A Poem on your Wrist. Sort Of.

My latest Pebble hack came to me in two phases. First, I read about the poetry vending machine. It's a terrifically low tech idea: write out poems, put them in little capsules, put said capsules in a capsule vending machine and put the vending machine in a public place. Enjoy!

Second, it occurred to me last night as I was sitting on the pot without any reading material, that for all the apps I have on my Pebble Watch none of them provide content. A bathroom trip with nothing to read? The horror!

My initial thought was I should find a news app for my watch; that would at least get the latest headlines. But with the poetry idea as a spark, I realized it would be far more valuable to get a random poem on my watch. So that became my mission.

Poetry is a good candidate for displaying on a watch because it can be quite compact. From Twitter Poetry to Haiku, a few words can go a long way. Additionally, many well known poems are in the public domain. Project Gutenberg has a wonderful collection of poetry just waiting to be put to use. This collection looks especially promising.

The problem I ran into though, was I didn't really have the time to parse all this poetry into a nice, clean web service. I wanted poetry on my watch, but I also wanted to have it there within the next 20 minutes. As usual, I turned to Unix to save the day. Specifically to fortune. The fortune command spits out a random a quote or random witty message. It's not exactly T.S. Elliot or Emily Dickinson, but it is *something*.

The first step was to put fortune online so my phone could grab a fresh bit of text. This PHP script does the trick:

<?
header("Content-Type: text/plain");
$fortune = shell_exec("/usr/bin/fortune -s");
$fortune = str_replace("\t\t--", "  --", $fortune);
echo $fortune;
?>

From there, I just needed to create a simple Tasker action that invokes the above script and pushes the output to my watch:

Pebble Fortune (85)
 A1: HTTP Get [ 
  Server:Port:code.benjisimon.com Path:/fortune.php 
  Attributes: Cookies: User Agent: Timeout:10
  Mime Type: Output File: Trust Any Certificate:Off
  ]

 A2: AutoPebble Text Screen [ 
  Configuration:Full Screen: false
     Title: So, yeah...
     Text: %HTTPD
     No Prefix if Command: false
     Do Not Disturb: false
     Clear History: false
     Open Phone App: false
     Save Scren: false
     Don't Send Screen: false
     Go Back: false
     Go Back Multi: false Timeout (Seconds):120
 ] 

Finally, I added a Auto Pebble task to listen for requests from the watch to show a fortune, and that was pretty much it.

Now, when I want some brilliant inspiration, I need only click a button or two my watch. Here it is in action:

It's not world class poetry, but it will do for now. Next bathroom trip I'll be prepared!

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails