Google reader widget

From awesome
Jump to: navigation, search

Using curl

These several lines give you the count of unread item of your google reader account.

function hook_google_reader(username, password)
   f = io.popen('curl --connect-timeout 1 -fsn "https://www.google.com/accounts/ClientLogin?service=reader&Email=' .. username .. '&Passwd=' .. password .. '"')
   if not f then return 0 end
   cookie = f:read("*line")
   f:close()
   command = 'curl --connect-timeout 1 -s -X GET http://www.google.com/reader/api/0/unread-count?all=true --header "Cookie: ' .. cookie .. '"'
   f = io.popen(command)
   if (not f) then return 0 end
   line = f:read("*line")
   i,j = string.find(line,'reading%-list</string><number name="count">%d+</number>')
   line = string.sub(line,i,j)
   return string.gsub(line,"%D","")
end

greader.py

greader.py is a script which uses a separate .netrc for storing the username/password (like the vicious GMail widget) and which caches the login token to reduce updates to a single http query.

Create ~/.netrc if necessary, then add a line like this to it:

machine www.google.com login you@gmail.com password yourpassword

It's recommended that you use a generated password. Also, make sure to chmod 600 ~/.netrc.

Then put something like this in your rc.lua:

rsswidget = widget({type = "textbox" })
function update_reader()
  rsswidget.text = awful.util.pread("python " .. awful.util.getdir("config") .. "/greader.py")
end
awful.hooks.timer.register(300, update_reader)
update_reader()

Or as a vicious widget:

rsswidget = widget({type = "textbox" })
function update_reader()
  return awful.util.pread("python " .. awful.util.getdir("config") .. "/greader.py")
end
vicious.register(rsswidget, update_reader, "$1", 300)
Personal tools