.
Aurium.Colivre.Coop.br Esse site é Legal Demais para Internet Explorer

Aurium :: IdenticaNotifier

Últimas blogadas:

%HEADLINES{"http://softwarelivre.org/aurium/blog/feed" refresh="600" header="SoftwareLivre.org" limit="15" format=" * $title" }% %HEADLINES{"http://cirandas.net/aurium/blog/feed" refresh="600" header="Cirandas.net" limit="15" format=" * $title" }%



The identi.ca Notifier is a script to show as desktop notification your followed microblogging posts. Receive identi.ca notifications without a web browser.

You only need to run the identica-notifier script with your username.
To me the line is:
$ identica-notifier aurium

The post balloon will be on your screen by one minute (giving you time to read), but you may click on this to close.

Get the script:
#!/bin/bash

#  identi.ca Notifier is a microblogging desktop notification service
#  Copyright (C) 2009 Aurélio A. Heckert <aurium(a)gmail:com>
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program. If not, see <http://www.gnu.org/licenses/>.

APP_VERSION=0.4

user=$1
if test -z "$user"; then
  echo "
  You must to define a identi.ca username to get the notifications.

  Usage:
    $(basename "$0") <user>
  "
  exit 1
fi

if ! xmlstarlet --version >/dev/null 2>&1; then
  echo "
  You must to install the miraculous XMLStarlet.
  May you only need to run this command line:
  sudo apt-get install xmlstarlet
  "
  exit 1
fi
if ! notify-send --version >/dev/null 2>&1; then
  echo "
  You must to install the fantastic libNotify.
  May you only need to run this command line:
  sudo apt-get install libnotify-bin
  "
  exit 1
fi

work_dir="$( mktemp -d )"
conf_dir="$HOME/.identica-notifier"
test -e "$conf_dir" || mkdir "$conf_dir"

last_notice="$conf_dir/last-notice"
function notice_is_new() {
  testing_id=$1
  if ! test -e "$last_notice"; then
    echo 0 > "$last_notice"
  fi
  if [ $(cat "$last_notice") -lt $testing_id ]; then
    return 0  # YES
  else
    return 1  # NO
  fi
}

function pangofy() {
  sed -r 's/&lt;/</g; s/&gt;/>/g; s/&quot;/"/g; s/&amp;/\&/g;
          s/ (rel|class|title|id)="[^"]*"//g; s/<\/?span[^>]*>//g'
}

pics_dir="$conf_dir/person-pics"
test -e "$pics_dir" || mkdir "$pics_dir"
function person_pic() {
  item_num=$1
  url="$( cat "$rss" | xmlstarlet sel -t -v "//item[position()=$item_num]/postIcon/@resource" )"
  img="$pics_dir/$( echo -n "$url" | sed -r 's/http:\/\///; s/\//_/g' )"
  if ! test -e "$img"; then
    wget "$url" -O "$img"
  fi
  echo -n "$img"
}

# TODO: clear old pics on start.

function show_notice() {
  item_num=$1
  echo $id > "$last_notice"
  title="$( cat "$rss" | xmlstarlet sel -t -v "//item[position()=$item_num]/creator" ) -- identi.ca"
  text="$( cat "$rss" | xmlstarlet sel -t -v "//item[position()=$item_num]/encoded" | pangofy )"
  notify-send -t 60000 -i "$( person_pic $item_num )" "$title" "$text $esp"
  echo -e "\n$title\n$text\n"
  sleep 4
}


trap "stop=true" SIGINT SIGTERM
stop=false

rss="$work_dir/personal.rss"

while ! $stop; do

  # Get Identi.ca Notifications:
  if ! wget http://identi.ca/$user/all/rss -O "$rss"; then

    echo ">> ERROR while trying to fetch the RSS."

  else

    # clear namespace declarations for a XMLStarlet bug workarround:
    sed -ri 's/<rdf:rdf [^>]+>/<RDF>/i; s/(<\/?| )[^ :;<>"]+:/\1/g' "$rss"

    #rss=/tmp/tmp.ZrtovhBrEO/personal.rss

    # XMLStarlet supports only one namespace, and we need more to parse the RSS:
    # https://sourceforge.net/tracker/index.php?func=detail&aid=1722425&group_id=66612&atid=515106
    # XMLStarlet example using namespaces:
    # xmlstarlet sel -N rss=http://purl.org/rss/1.0/ -t -v "//rss:item[position() = 1]"

    total_itens=$( cat "$rss" | xmlstarlet sel -t -c "count(//item)" )
    echo ">> RSS Total Itens: $total_itens"

    for current in $( seq $total_itens -1 1 ); do
      echo -n ">> Analizing item $current..."
      id=$( basename $( cat "$rss" | xmlstarlet sel -t -v "//item[position()=$current]/link" ) )
      if notice_is_new $id; then
        echo " Showing!"
        show_notice $current
      else
        echo " Old."
      fi
    done
    
    echo ">> End this list. Waiting to fetch again."

  fi # end wget got the RSS

  $stop || sleep $((120+$RANDOM%30))

done

echo ">> Saindo..."
rm -r "$work_dir"

This script uses XMLStarlet and notify-send. If you don't have one of this software you may install with this command line:

$ sudo aptitude install libnotify-bin xmlstarlet

If the post links don't work for you, please comment this bug report:
http://trac.galago-project.org/ticket/191


DiggThis

Copyright © 2004 - 2019 Aurélio A. Heckert
Conteúdo licenciado sob Creative Commons by-nc-sa