API Zugang zu üäx.de Linkshorter mit Zenity

Shellscript  (08.06.2010 11:40) Eine Bash-Schnittstelle zum Linkshorter üäx.de mit Zenity

Quellcode (ausblenden | aufklappen)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# ueaex.sh
 
LC_ALL="de_DE.UTF-8"
 
API_URL="http://xn--x-zfa5e.de/api/"
API_KEY="<api key>"
OUTPUT="xml"
 
ERR=""
RESP=""
API_URL=${API_URL}${API_KEY}"/"${OUTPUT}"/"
 
 
function add()
{
    POST="url="$1
    BUF=`curl -s -d "$POST" ${API_URL}"add/"`
    ERR=`echo $BUF | sed -n 's|\(.*\)<error_code>\(.*\)</error_code>\(.*\)|\2|p'`
    if [ "$ERR" = "no_error" ]; then
        RESP=$(echo $BUF | sed -n 's|\(.*\)<short_url>\(.*\)</short_url>\(.*\)|\2|p')
    else
        RESP=$(echo $BUF | sed -n 's|\(.*\)<error_message>\(.*\)</error_message>\(.*\)|\2|p')
    fi
}
 
function get()
{
    POST="url_code="$1
    BUF=`curl -s -d "$POST" ${API_URL}"get/"`
    ERR=`echo $BUF | sed -n 's|\(.*\)<error_code>\(.*\)</error_code>\(.*\)|\2|p'`
    if [ "$ERR" = "no_error" ]; then
        RESP=$(echo $BUF | sed -n 's|\(.*\)<url>\(.*\)</url>\(.*\)|\2|p')
    else
        RESP=$(echo $BUF | sed -n 's|\(.*\)<error_message>\(.*\)</error_message>\(.*\)|\2|p')
    fi
}
 
 
URL=""
while true; do
 
   URL=$(zenity --entry --text="Bitte eine gueltige URL eingeben:" --entry-text="$URL" --width=600)
   if [ ! "$URL" == "" ]; then
      add $(perl -MURI::Escape -e "print uri_escape('$URL');")
      if [ "$ERR" == "no_error" ]; then
         zenity --entry --text="Die URL:" --entry-text="$RESP" --width=600
         exit 0;
      else
         zenity --error --text="$RESP"
      fi
   else
      exit 0;
   fi
 
done;