-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet
executable file
·88 lines (76 loc) · 2.36 KB
/
tweet
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
url="http://consoletweet.herokuapp.com/"
#use to encode data send for curl request
function dataEncode() {
local tweet="$@"
local character=('%' ';' '?' '\/' ':' '#' '&' '=' '+' ',' ' ' '<' '>' '~' '!')
local replace=('%25' '%3B' '%3F' '%2F' '%3A' '%23' '%26' '%3D' '%2B' '%2C' '%20' '%3C' '%3E' '%7E' '%21')
for i in "${!character[@]}"
do
tweet=$(echo $tweet | sed -e "s/${character[$i]}/${replace[$i]}/g")
done
#can not return string
echo $tweet
}
#use to send tweet from console over curl
function tweetIt() {
local tweet="$@"
echo "ed3mo"
local oauth=`cat \demo.txt`
local query="oauth=$oauth&tweet=$tweet"
echo $query
echo $(curl http://consoletweet.herokuapp.com/sendtweet?$query)
#echo $(curl http://justunfollow.net:5000/sendtweet?$query)
}
function start() {
if [ "$1" == "-a" ]; then
#check if second argument present or not
if [ -z "$2" ]; then
{
#if second argument is not present then throw error message
echo "There has to be second argument"
exit 1
} || {
echo "please execute commond using sudo"
}
else
#store second argument in file
touch demo.txt
echo "$2" > demo.txt
fi
elif [ "$1" == "-l" ]; then
{ #try block
#open website url in default browser
xdg-open $url &
exit 1
} || { # your 'catch' block
#throw error message
echo 'we can login by visiting http://consoletweet.herokuapp.com/authtoken'
exit 1
}
elif [ "$1" == "-t" ]; then
#command use for tweeting text
i=0;
for var in "$@"
do
i=$(expr $i + 1)
# check first argument should not consider as tweet text
if [ "$i" != "1" ]; then
tweet="$tweet $var"
fi
done
#use to encode data
tweet=$( dataEncode $tweet )
echo "dfdf:$tweet"
#send tweet
tweetIt $tweet
elif [ "$1" == "--help" ]; then
echo "tweet -a oauthId [oauth id is given by our login system]"
echo "tweet -t tweet [tweet: text to be tweet]"
echo "tweet -l - use to login"
else
echo "commond not found try tweet --help"
fi
exit 1;
}
#calling start method
start "$@"