📜 ⬆️ ⬇️

karma widget for awesome wm

Not much kick, just decided to share.
We write an xml parser that will pull in data about karma and habrassil:
 #! / usr / bin / perl

 use XML :: Simple;
 use Net :: HTTP;

 my $ s = Net :: HTTP-> new (Host => "habrahabr.ru") ||  die $ @;
 # change to your username
 $ s-> write_request (GET => "/ api / profile /% username% /", 'User-Agent' => "Mozilla / 5.0 (+ http: //www.reid.ru/freebsd/? page_id = 15 ) ");
 my ($ code, $ mess,% h) = $ s-> read_response_headers;

 while (1) {
     my $ buf;
     my $ n = $ s-> read_entity_body ($ buf, 1024);
     die "read failed: $!"  unless defined $ n;
     last unless $ n;
     $ data = $ buf;
 }

 my $ s = XMLin ($ data);
 $ karm = $ s -> {karma};
 $ rating = $ s -> {rating};
 print "$ karm \ / $ rating";


In rc.lua we write:
 - define the widget
 karma_text = widget ({type = "textbox", align = "right"})
 function get_karm ()
  - specify the path to the script
  local karm = awful.util.pread ("~ / .config / awesome / zoom / bin / karma")
  karma_text.text = "" .. setFg ("# e8ef1b", karm) .. ""
 end
 ...
 - specify where it should be located
 mywibox [s] .widgets = {
 ...
  karma_text
 ...
 }
 - call it when you start awesome
 get_karm ()
 - and call every 15 minutes
 awful.hooks.timer.register (900, function () get_karm () end)


Result (for completeness, I show the whole tray):
image
')
Carefully read the rules of the API habr.

Source: https://habr.com/ru/post/64709/


All Articles