Tag Archives: Lifestream

Last.fm activity now in Complexlife

Last.fm is one of the top, if not the best music service out there and it’s something I’ve been using for quite a while now. While last.fm includes things like groups, friends, forums and other aspects of a social network, your activities in these was never provided. In the latest version these activities (new friends, loved songs etc) were shown in the form of a little block in the sidebar but unfortunately there has been no way to grab that for use in Complexlife.

I knew there is a way to get these activities somehow as Friendfeed does show you when you love a track but having asked directly about it in the forum, I was told that getting this in a feed was just not an option.

Fortunately web-mastered stepped up and created a yahoo pipe which grabs the last.fm latest activities API and returns it as a feed. Very useful but unfrotunately I noticed that it wasn’t exactly in the format I needed. If I used that in Complexlife then you would only see the title (a generic “New activity from <username>”) and having no date info in the feed, b0rked the sort by date of Simplepie.

Thus I had to modify the pipe in a way that

  1. Made the content become the title of the post (removing any html which might break Complexlife)
  2. Provide the date in the RSS so that the item can be sorted

Creating the title

It took me a while to figure it out, but making the content become the title was the easiest part of it all. Since yahoo pipes provides a handy renaming function, all I needed to do is tell it to rename the content as the title

Renaming the content as Title
Renaming the content as Title

The first part copies the whole content as the date field. I will later use this get the date. The second part renames the current content to the title so that it is displayed in whole. If I didn’t do it, I would get only part of the content displayed with elipsis after 30 characters or so.

Now I need to remove all the html code the activity stream has in. As it includes links to my profile as well as to artists and tracks, this would break the link complexlife puts for each row. The only way to remove the unecessary parts is of course through regular expressions and yahoo pipes gives exactly that function.

Removing the unecessary parts from the content
Removing the unnecessary parts from the content

This part actually goes before the renaming/copying as I remove various parts I also don’t need from the date field. Thus when I copy, I save duplicating the work.
The most interesting part is the previous the last field, wherein I tell it to remove all html tags (anything between < and >) and all their settings (i.e. target=”_blank”). Thus I’m left with the title in plain text.

Creating the date

This was a more tricky part as not only does the last.fm activity stream API consider it a good idea to put the date on the content but it also puts it in as a relevant entry to the current date.

Putting the date in the correct field was the easy part as all I needed to do was copy the content in the date field and remove everything except the date. As right before the date there was a fullstop, it was fairly simple to use another regex to delete anything until the last fullstop

The regular expression removes everything until the last fullstop
With a little regex magic, anything except the date is gone

The more difficult part was to make the relevant fuzzy date to become something that is expected to be in an RSS feed, which is something very specific in time and format. Fortunately, I noticed that there is a specific module that does exactly that: Date builder. How convenient.

Unfortunately this module accepts only strings so I could not really parse my whole feed through it unless I had a loop. Oh wait…

With a loop I can make all date items in the correct format
With a loop I can make all date items in the correct format

Sweetness. Unfortunately one problem remains which is that because the date provided is always fuzzy, I end up getting a rolling date for the item each time the pipe is run. For example, an item which has a date of “one month ago” today will point to Aug 28, tomorrow on Aug 29 etc. There’s not much I can do about it other than wait until (and if) last.fm deems it worthy to give us a proper feed.

And now my new shiny feed is in exactly the format I need to have for Complexlife to use it. A little hacking later and version 0.9.8 is ready to go. The last.fm activity stream is finally lifestreamable 🙂

Reblog this post [with Zemanta]

ComplexLife

window peeksSo finally my very first WordPress plugin is accepted into the official plugins repository 🙂

This is a historic event. I’m certain that fame and fortune will not be very far back!

In case you haven’t seen my recent page about it and you don’t care to read it, Complexlife is a lifestreaming plugin which is a fork from SimpleLife (You see what I did there? 😛 ).

After adding a lot of features and options to it and seeing that Simplelife is not progressing I thought I’d go ahead and just upload it as a new version. This will allow me to have a more organised development and also have the help of anyone who wishes to improve it.

I’ve already got a few features I want to add and I’m also going to be merging changes from other places where I find them, i.e. the trumblog.

So if you’ve got a self-hosted WordPress blog, give it a go and let me know what you think. I’m eager for feedback.

An easier way to track your comments in your lifestream

I’ve been trying to find a better way to allow my lifestream to track my comments that would require less manual activity from me as well as allow me to track my own comments in my own site.

When I started using google reader to archive and extend my lifestream, I briefly considered using it to track my comments as well but I decided against it as I wanted first to see if comment services like Cocomments or co.mments might work (they didn’t). I also could not see a way so as to get it to track only the thread titles where I’ve placed a comment (so as to insert it in the areas I am commenting) or how to get my lifestream to display only my own comments.

However, after managing to set up google reader as an archive, I discovered how much more information an atom feed is providing, part or which is the author or each comment post. Just what I needed 🙂

I quickly cooked up a bit of code to just keep the comments left from me in each thread’s feed. This is something I was not able to achieve with Cocomments and co.mments as they don’t provide you with an actual feed of the whole thread but rather they copy the text and provide you with a raw html formatted to simply look separated.

There was also a little problem that many feeds included various words in the title like “Comments on:” which just looked bad when I appended my extra “Commented on:” text. I needed to find a way to remove them so a little search and the php solution appeared. Perfect!

Last step was to trigger it even if I happened to comment with differing case in my alias. the “if” statement is quite anal about cases that way. All in lowercase then.

The end result is this:

if ($feedurl == $greader_comment_feed) {
if ($author = $item->get_author()) {
$name = strtolower($author->get_name());
if ($name == get_option('greader_comments_author')) {
$item_title_crops = array('Comments on:', 'Comments for', 'Σχόλια στο:');
$item_title = str_replace($item_title_crops,'',$item->get_source()->get_title());}
else {continue;}}}

Finally, all you need to do is setup a google reader public tag where you’re grouping in all the thread feeds of any place you comment in. You can see mine here for example. Get the feed of it, put the number of items you want to see (the default is 20) by appending ?n=# in the end, where # is the number of items you want. In this case you should put something sufficiently large as this will also include comments from others.

Unfortunately, once this was setup, I realized a limitation of simplelife. It still could not limit the number of items you received by date. This is apparently on the “To Do” list but seeing how long it is taking for new versions to come out, my only option was to code it myself. And code it I did 🙂


if (get_option('simple_datelimit') > 0) {$date_limit = get_option('simple_datelimit')*86400;}
if ($item->get_date(U) < date(U)-$date_limit) {continue;}

Not only that, but I decided to try my hand at adding it as an option on the plugins config page in the WordPress admin panel. This is why the “get_option” exists instead of hard-coded entries :).

What it does it take the number of days the user submits and multiplies it by the number of seconds in a 24h day (86400). After that, for each entry, I get the date in a UNIX epoch format and compare if the day the item was recorded is within the number of days I’ve set. If not, I just skip the current iteration.

The new option to set how many days of history you need.

Finally, since I already managed to edit a new option in the config, I thought why not to create the option for the Google Reader feed as well. And lo! There was code.

The Google Reader Comments menu config

Since this wasn’t really hard, I’m planning now to prepare the plugin for general consumption and perhaps upload it to the Codex. I’ve was waiting for the 1.3 version to come out so that I could take that as it has some more improvements, but it just does not seem to be happening.

I also have some nice ideas to improve the config, like Ajax dynamic menus etc but that’s for the future.

Hacked Simplelife

At the request of a commenter who is also playing around with his simplelife plugin, I’m uploading my currently hacked version.

It’s not pretty so you won’t be able to change all options on the profile (only the ones included in the original) but I’ve included comments in the code so you should be able to figure out what is what.

You will need the Simplepie core WordPress plugin in order to use it.

Currently this version supports the following extras (Over the original simplelife)

In order to make it work for your own lifefeeds, you will need to edit the php code directly. You will have to edit either the ones I’ve set up (for example, change your digg username) or add your own.

To add a new feed you need to do the following

  • Add the new class for it (Defining colour, background and icon)
  • Add a new variable for the feed url
  • Add a new variable for the title that will be used in the chart. Optionaly you can set it to something specific but if you don’t want to, the script will just draw it out of the feed
  • Add a new variable for the counter.
  • Add the new feed url variable in the SimplePie array. Your new feed will need dates so don’t use something like Ponyfish.
  • Create a new if statement (just follow my comments)
  • Optionally, if you’re using getboo or something similar, add a new switch for the subtags
  • Add the title and counter variables to the chart if you want them tracked. You’re better off copy-pasting one of the current entries in the middle and pasting it below. If you copy and paste to the bottom of the chart, you’ll probably add an extra comma where you shouldn’t. Don’t forget to change the small chart as well.

If you have any questions, let me know.

PS: I am currently waiting for version 1.3 to come out so that I can merge all my changes in the new code but it seems to be taking too long. I think I might as well start beatifying it in order to upload it as standalone.

Download the hacked version of the Simplelife WordPress plugin here.

How to track anything and everything in your lifestream

Usually, most lifestream services out there only allow you to track specific places and usually these places are only the most popular like facebook, flickr, del.icio.us etc. Furthermore they only give you limited control on the look.

This is mainly the reason why I went for my own hosted lifestream. It allows me to track anything I can get a feed for as well as modify it as much as I want to look the way I want it.

However there is always the problem of how to track things that do not provide a feed of some sort. Sure, you might be able to use co.mments to track you blog comments but what if you want to log the comments you left on a forum, in a bug tracker or in a private location? How about when you need to track something completely different than that, like an email of yours to a mailing list or a new torrent you’ve uploaded?

The answer is: Simple. Bookmarking.

All you need to do is utilize an online bookmarking service like del.icio.us or getboo to tag your actions and then use the tag feeds to import them into your lifestream. Not only then can you get a feed for the various actions of yours, but if you utilize extra tags, you can categorize it further afterwards, provided your lifestream services can play with categories.

For example, I am currently bookmarking all the comments I leave on the internet and tag them as “mycomments“. If you check these bookmarks you will also see that they are further tagged as “blogcomments”, “comment_start” etc. Once a comment is tagged, Getboo provides it as a tag feed which I import into my google reader lifestream (for archiving purposes). Finally, my lifestream takes that and depending on the original tag feed the item comes from, it formats it appropriately in the list. Thus you will see all the comments use the same icon & colour while the FSD actions another. However they are both in the same service (getboo) and in the same feed (Google reader lifestream).

Not only that, but if you look deeper you will see that even items from the same source have further differences. Under the FSD class you can see items marked as “Voted Up”, “Buried” or “Commented on”. They are all however coming from the same original getboo tag feed and this is where the tags/categories of a bookmarking service come especially handy. Using the amazing capabilities of SimplePie and some newfound php knowledge I’ve cooked up a method to query the categories of each lifestream item and further format them based on what I find.

At this point, (with only free software tools mind you: getboo, wordpress, simplepie and simplelife) I have a lifestream that is much more inclusive than, I believe, any other option out there, and the capabilities I have are truly endless.

Currently, I am planning to getting logs for mailing lists, bug fixings, wiki edits and whatever else I do on the intertubes. Once everything is ready, I just need to wrap everything up and give it to you as an enhanced WordPress plugin 😉

PS: I suggest getboo throughout this article because del.icio.us is already used by many other lifestreams out there already. If you start bookmarking your actions there, you’ll get them double unless you unregister del.icio.us totally it from your service. That will mean however that your normal bookmarks won’t be tracked anymore. By using an alternative, you avoid that fate and get the best of both worlds.

Oh, and did I mention that if you really have to, you can also host your own getboo? 😉

So what are you waiting for. Start tagging 😉

Using a Google Reader as a lifestream archive

After I set up my lifestream to track a host of custom actions (like comments on other blogs, or votes on FSD) I discovered that many of the feeds I was using were having a item limit (from 10 to 20). That meant that if I made, say, 11 or more comments in various other blogs, the older ones would dissapear from the list, even if the date was still in the limit I’ve set. Only the newer 10 would always be shown and it would seem as If I made no comments below that date.

It was not a bigg issue but I really wanted it to work right so as to get a more accurate overall idea of where I am spending my time (graphs and so).

I remembered then, that Google Reader seems to always have the option to go back into older posts in the feed, up to the time that you made the subscription through it. This meant that it archives everything in that feed and stores it in its own server (Damn that Google storage is endless). Also, Google Reader has the option to put various subscriptions under a specific folder/tag, allowing you to read all the subscriptions together.

It also allows you to make that tag public. A Public tag allows anyone to see the feeds that you share through it but also gives you a feed to subscribe in turn. This feed, unlike the original ones, can provide feeds data as far back as the time you made the Google Reader subscription (and even further if someone else had subscribed to it before you, I believe). All I needed to to is append ?n=# at the end of my google reader feed where # is the number of items I want to see each time the feed is polled. (I selected 100)

So there I had it. An easy way to make an arvhive of my tracked activities without setting up my own database.

The only problem now was to make the lifestream plugin recognise from which feed in turn each item comes and then assign it the correct class. This was a more challenging question as my previous method to compare the original feed with the current item’s could not work. I discovered that I could filter by the items target link but since I wanted to use the same service to track different activites, it would always filter them the same way. In case you’re wondering, I use Getboo to bookmark pages that I commented on as well as FSD articles I’ve voted up, down or commented (Since, unfortunately, FSD does not provide such feeds by itself until now). The number of things I track through Getboo will only increase as I find more actions that don’t provide feeds.

Thus I needed some way to the original feed through my Google Reader lifestream feed.

Well, how very fortunate of me that Google Reader publishes an Atom feed and not only that but it includes the source of the original feed for your convenience. 😀

A little trial & error with the (truly excellent) SimplePie APIs, and I’d managed to find and write the code that I needed to use.


if ($feedurl == $greader_lifestream_feed) {
if ($source = $item->get_source()) {$source_url = $source->get_permalink();}
if (stripos($source_url, 'twitter') !== false) {
$class = 'twitter';
$tf_counter = $tf_counter+1;
$current_title = 'Status Update (Twitter)';
}
if (stripos($source_url, 'mycomments') !== false) {
$class = 'comments';
$extra_text = 'Commented on: ';
$getboo_comment_feed_counter = $getboo_comment_feed_counter+1;
$current_title = 'Comments Elsewhere';
}
if (stripos($source_url, 'fsd') !== false) {
$class = 'fsd';
$extra_text = 'Voted up: ';
$fsd_counter = $fsd_counter+1;
$current_title = 'Votes up on Free Software Daily Article';
}
}

And yes. I’m proud of my little code snippet. 😀

So now, if I have any feed with a sufficiently low item limit, all I need to do is subscribe to it through Google Reader and add the appropriate if statement in my plugin code and presto! Instant archiving. There is only a (very) slight problem in the sense that the lifestream update is delayed by the time it takes for google reader to refresh the original feed and then update the public tag.

All I need to do now is figure out a way to separate items in the google reader feed through the category tags that getboo provides. That would be sweet as it would cut down on line number but unfortunately the get_category() simplepie function does not seem to work as intended for me 🙁

Charted life

I’m not the one to pat himself on the back for the smallest thing, but I must say that I feed quite proud about my latest little hack in my lifestream.

I was initially inspired by yahooza’s lifestream (via the lifestream blog) after I saw that little chart on the right side. He used the google charts API to achieve which seems quite easy to use and very impressive for online use. Thus I digged in my Simplelife plugin and started hacking around.

You can see the result below. For my limited php knowledge, this was quite a achievement 🙂

My personal pie chart

Of course the above is a static image, but within my lifestream page, this is updated dynamically every time the page loads. I like 😀

Of course, this will soon be available to you all since the Simplelife v1.4 is coming out soon and the author would like to implement some of my ideas in it.

Now all I need to do is to find a way to get the dynamic image in a format that I can put in other places without having to run the script along with it 😀

Where're my damn icons?

I don’t get it. My lifestream icons are not loading for some reason even though you will see in the page source that they are loaded as part of the class. For some reason, initially the last.fm and facebook icons stopped loading after I hacked the SimpleLife plugin to make it play with all kinds of feeds. Then, I discovered why the colours of the custom feeds were not being used (a missing colon) and fixed it, and now <a>all</a> my icons are gone…

Grrr!

Nothing I do seems to fix this and I just cannot see why it is happening. There does not seem to be an obvious error in the code and the rest of the css class (text, background colours) are loading just fine. In the source of the page, you can see the css clearly loading correclty


a.lastfm {
background: 0c0c0c url(http://dbzer0.com/wp-content/plugins/simplelife/lastfm.png) no-repeat 10px 50% !important;
border-top: 1px solid 0c0c0c !important;
border-bottom: 1px solid 0c0c0c !important;
color: #BFBFBF !important;
}

And then the item call

<li class=”item”><a href=”http://www.last.fm/music/Machinae+Supremacy/_/Stand” class=”lastfm” title=”db0’s Recently Played Tracks”><span class=”timesf”>09:48</span> Machinae Supremacy – Stand</a></li>

And the icon exists…
Anyone have any idea what is going on?

At least now I can have feeds from any source (feedburner, del.icio.us, google reader) without losing formatting. I just need to wait for the next plugin version to add options for more streams 🙂

UPDATE: Nevermind. I found the culprit. Apparently I’m blind…

Mighty plugin hacking

Well…for my newbie standards at least 😛

I’ve been playing around with the SimpleLife WordPress plugin, trying to create a simple lifestream I can embed in my about page and perhaps in my sidebar as well. It turned out that this was a job which needed a bit more attempt to make it work.

Below are the changes I did in order to wrangle it.

  • Had to edit the plugin in order to get it to diplay correctly in the plugins page. For some reason it floods the screen with it’s contents. Apparently editing and saving should solve it but in my case I needed to delete some newlines as well.
  • Changed the classes .date and .time to .datesf and .timesf and modified where they were called. Leaving them as they were, they were screwing with other css classes on my site under the same name
  • Changed the if statement for last.fm to look for the string ‘last.fm‘ instead of ‘last‘ since that string may be a part of any other url.
  • Put three new if statements, similar to the ones that check for last.fm and facebook, that check if the link goes to this blog, the ACP or the Wesnoth Journals. Then set the class according to that. The way the plugin is setup, it does not assign the class depending on the feed url bur rather according to the current link url. This means that you cannot use feedburner as your feeds address as it will never trigger an if statement[1]. I actully find the way this is handled a bit weird as it would serve much better to check the feed url and assign a class, rather than check the current link. I’ll have to check if that’s actually feasible…
  • Commented away the if statements for the first three feeds. I’m using the custom ones instead now.
  • Manually set the colour of the last two feeds within the plugin. For some reason even though the php call takes the variable I’ve set in the plugin configuration page (I can see it in the source code of the page) the colour is not being used and the text stays black. Weirdly enough, the background colour is changed well enough and the “blog feed” works just fine.
  • I didn’t want all my delicious feeds to be posted because I seem to be doing an awful lot of them. I prefer to log only the ones that signify my comments for which I use the mycomments tag. Fortunately I’ve discovered that you can use a del.icio.us tag by using the form: username/tagname
  • Created a new page template and inserted the php code there.

All-in-all, the plugin seems very promising and it already seems to work fine for me. However it does seem quite error-prone and lots of people most likely won’t be able to use it yet. Fortunately this will be fixed in the short future.

Now I just have to see if I can add more stuff for it to track.