I’m not very web 2.0-sy.. I haven’t joined any social wobsite and while I do blag every once in a while, it’s not as frequent as all the hip people and it’s usually a lot less interesting.
Nonetheless, I’ve wanted something simple to toy with awesome 3.0 (it became 3.1 while I pondered) and the lua configuration thingie. To be honest, I preferred the old libconfuse-based config system – it was a lot easier to wrap my mind around it and it was a lot easier to debug when something went wrong. I’ve seen the various mpd widgets, volume widgets and many, many monitoring widgets but I wanted to play with something that, to the best of my knowledge, hadn’t been done before.
So I thought of making an awesome widget for Twitter. It was a stupid idea so I promptly went on with it.
The first minor snag I hit was that I’ve actually never used Twitter. That was easy to solve though. Now with moar web 2.0!
I quickly gave up on writing something to actually interface with Twitter. There are countless of scripts, language modules/libraries and whatnot for doing that and while lua seemed to lack a Twitter-library I didn’t want to try my luck at writing that since I seriously lack lua skills as well. So I used the Net::Twitter perl module and wrote a short wrapper script to do the job. All that was left then was the awesome configuration. All of the following lua-code goes somewhere in your rc.lua.
First of all, functions. It seems these has to be defined earlier in the file than where they’re called…
function updateTwits()
local twits = {}
local fh = io.open("/tmp/twitlist")
if not fh then
mytwitbox.text =
"<small><b>No twits present!</b> I suggest looking at the gentoo community</small>"
return
end
for line in fh:lines() do
table.insert(twits, line)
end
if #twits > 0 then
mytwitbox.text = awful.util.escape(twits[math.random(1, #twits)])
else
mytwitbox.text =
"<small><b>No twits present!</b> I suggest looking at the gentoo community</smal>"
end
end
function postTwit()
awful.prompt.run({ prompt = "Twit: " }, mytwitbox, function (msg)
os.execute("/home/arkanoid/bin/twit post \""..msg.."\" &")
mytwitbox.text = "Tweet posted! Go grab a cup of coffee ;-)"
end, function () return nil end)
end
The first function, updateTwits, grabs a random tweet from a list of tweets generated by the twit.pl script and updates the text of the twitter-widget. postTwit spawns a prompt and posts your tweet to twitter.
To actually use this we define a textbox widget and fill it.
mytwitbox = widget({ type = "textbox", align = "left" })
mytwitbox:buttons({ button({ }, 1, updateTwits),
button({ }, 3, postTwit) })
updateTwits()
This way a left mouse click on the textbox will fetch another tweet and a right click will give you a prompt so you can submit a new tweet.
Remember to add the widget to a wibox. In this case I added a second wibox (statusbar in pre-3.0 terminology) which is located at the bottom of the screen.
mysecondwibox = wibox({
position = "bottom",
fg = beautiful.fg_normal,
bg = beautiful.bg_normal
})
mysecondwibox.widgets = { mytwitbox }
mysecondwibox.screen = 1
I might as well make awesome fetch a new list of tweets from twitter as well.
awful.hooks.timer.register(60,
os.execute("/home/arkanoid/bin/twit friends >/tmp/twitlist &"))
The main reason for not doing this in updateTwits is that the command might take a few seconds and awesome would be frozen while it ran. So I grabbed an idea from the awesome wiki and made a second timer that ran the fetcher in the background.
Add another hook to update the twitter-widget at a reasonable interval:
awful.hooks.timer.register(20, updateTwits)
Lastly a keybinding to post a new tweet by pressing Mod4+Shift+t:
keybinding({ modkey, "Shift" }, "t", postTwit):add()
And you’re all set – one very classy awesome twitter-widget fully operational. It is in the lower left corner:

It’s a pity I really don’t give a damn about twitter and probably won’t use it for anything. But at least it served as an icebreaker to awesome and lua for me.
And as for awesome and lua… it seems a lot less silly now than it did five hours ago.