This repository has been archived by the owner on Feb 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.sh
57 lines (46 loc) · 1.5 KB
/
api.sh
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
#You can always change it to something else(like wget). This function is only not to hardcore curl as the only network engine.
function request {
curl -s $1
}
function getvalue {
grep $2 $1 | sed -e 's/<[^>]*>//g'
}
function status.set {
request "$api/status.set.xml?text=$2&v=$API_V&access_token=$1" > /dev/null
}
function friends.get {
request "$api/friends.get.xml?user_id=$2&fields=nickname&v=$API_V&access_token=$1" > $tmp_dir/friends_$2.txt
getvalue $tmp_dir/friends_$2.txt "<id>"
getvalue $tmp_dir/friends_$2.txt first_name | tr -d " " > $tmp_dir/friends_$2_firstname.txt
getvalue $tmp_dir/friends_$2.txt last_name | tr -d " "> $tmp_dir/friends_$2_lastname.txt
}
function status.get.user {
request "$api/status.get.xml?user_id=$2&v=$API_V&access_token=$1" > $tmp_dir/status_$2.txt
getvalue $tmp_dir/status_$2.txt text
}
function status.get.group {
request "$api/status.get.xml?group_id=$2&v=$API_V&access_token=$1" > $tmp_dir/status_group_$2.txt
getvalue $tmp_dir/status_group_$2.txt text
}
function messages.send {
request "$api/messages.send.xml?user_id=$2&message=$3&v=$API_V&access_token=$1" > /dev/null
}
function url.struct {
count=1
while [[ $(grep = <<< $var) || "$count" -eq "1" ]]
do
[ "$count" -eq "1" ] || echo "$var"
var=$(echo $1 | cut -d "#" -f2 | cut -d "&" -f$count)
(( count++ ))
done
}
function url.getvar {
url.struct $1 | grep $2 | cut -d "=" -f2
}
function notify {
tput cup $[$(tput lines)-1] 0
printf "%$(tput cols)s" ""
tput cup $[$(tput lines)-1] $[$(tput cols)-${#1}]
printf "$@"
}