nit: you can write 'head > link[rel="icon"][href="img/presence/%s.png" % state]', much more idiomatic in Python