Posts Tagged ‘ twitter

Twitter Sparkline Generator using Unicode

NB: This post uses examples of Unicode that may not show up in some browsers.

One of my main gripes with twitter is the ability to add only text. People often have the desire to share small snippets of data, but to no avail. The ideal idea to share data in such tiny chunks of data Edward Tufte idea of a Sparklines.

For those of you disinclined to read the wikipedia page, sparklines are “data-intense, design-simple, word-sized graphics”, designed to be entered inline with text, at similar height to help illustrate an idea.

Now I am not the first person to suggest entering sparklines in to twitter, in fact the second entry for a google search for sparkline turns up Alex Kerin’s article. However, there are two slight problems with Kerin’s implementation. Firstly, the unicode block characters he is using are not designed to be lined up, and examples that are shown on his page demonstrate this. To be fair, this isn’t his fault at all as unicode compliance isn’t 100%. The second is that a bar and a line can provide two very different perceptions: bar charts generally being used to display discrete data (or continuous data being shown as discrete) and line charts being used to show continuous data – for the record there is no good time to use a pie chart.

To this end I have created a tool for producing two different types of sparkline from an input data source – A crude line graph and a 5-figure box-plot.

Here is an example showing this are using the June 30th 2010 Perth weather data from the Bureau of Meterology, with bars delimiting 3 hour blocks:

The weather yesterday in Perth was quite cool (4.1┣▇▇|▇━━┫17.7) with a maximum of 17.7 degrees occuring around 2pm, before quickly cooling down until 3pm. (⣤⣤⣀⎸⣀⣀⣀⎸⣀⣀⡤⎸⠴⠚⠛⎸⠛⠛⠙⎸⠒⠒⠒⎸⠒⠲⠶⎸⠶⠶⠶).

Limiting this example further, restricting ourselves to the 140 characters of twitter:

Perth 30/06/10: Cool (4.1┣▇▇|▇━━┫17.7), max at 2pm, cooling to around 13°C after 3pm, steady afterwards. (⣤⣤⣀⎸⣀⣀⣀⎸⣀⣀⡤⎸⠴⠚⠛⎸⠛⠛⠙⎸⠒⠒⠒⎸⠒⠲⠶⎸⠶⠶⠶)

This is a 115 character weather report leaving 25 characters for a url to the full data. This may be for temperature only, but it shows the potential and can place 2 dataset in a twitter post with commentary.

I think the boxplots look quite good, however the tool does take a few liberties with the braille layout, relying on people to see a pair of vertical dots as a value in between the two, but it helps convey the message quite well in a limited, text-based format.

Release Day – Perl/Email/Twitter Gateway

Today is the alpha release day of PET-Gateway. A clunky interface to translate between a pair of email addresses and twitter (written in Perl, wouldn’t you guess). At the moment it has far too little documentation, but this will be corrected after I get back from the slopes.

However, the short version is:

Firstly, download the script from Google Code, and its numerous dependencies from CPAN.

Then, setup two emails, one as the twitter-server proxy and a second as the twitter-client proxy (you may already have this, like your work email thats hidden behind an oppressive  or an email you can access in an even more oppressive dictator regime).

In the poorly documented config file you at the smtp and pop3 details (IMAP coming later), and the client proxy as the “to email” and the add the server proxy username and password under email.

At this stage the pop3 and smtp servers both need to support ssl and use the same details, again this will be updated at a later stage.

Now, copy the .rc file with the same name to your home directory and run the script. It will ask to be oAuthed against Twitter using a URL and the returned PIN code. Make sure you are logged into to Twitter when you browse to the given URL.

After that you are all setup, just add a cron job with a command like:

*/2 * * * * ~/path_to_pet-gateway/pet-gateway.pl >> ~/.pet-gateway.log

to make the process run as often as you need and you are all set to tweet to your hearts content, even when you can’t access Twitter!

When you send to the server email address, it only posts the message body upto the first line break, splitting it across tweets if it has too, and also looks for attached images to upload to imgur.com. Also, if you want to reply to another tweet, reply to the email the server-proxy sends you, and the it prepends the sending users username automatically, and sends the update properly including the originating tweets ID so the tweets thread correctly.

This was kind of rushed out the door so I could still Tweet on my upcoming holiday, but there should be a fair bit of development when I get back either on this or a python rewrite that should have less dependencies and be easier to distribute and run.

If you find this useful, add a comment here, or on PET-Gateways main page and let me know, and if you find issues with my code feel free to submit a bug, path, diff or complain on the google code page.