Atrixnet Code Share and Geek Resources | Can you grok it?

TAG | curl

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
#!/bin/bash
# AUTHOR:   Tommy Butler $ echo PGFjZUB0b21teWJ1dGxlci5tZT4K|base64
# DATE:     Tue Apr 28 11:39:28 CDT 2009
# VERSION:  1.0
# USAGE:    tweetpic "your tweet message here" "/path/to/image/file.jpg"
# PREREQ:   you need to have curl and gpg installed
 
# SUMMARY:
# Upload to twitpic and post to twitter in one go from the command line with
# this script  I wrote.  Prerequisites- gpg encrypt (with ascii-armor option)
# a text file with your  username and password, each  on its own line (\escape
# any spaces in your password); save the text file as ~/twitter-credentials.asc
# I guess if you can't figure out how to use gpg, ask someone who does or...
# RTFM: man gpg.
# PS - chmod 0600 your twitter-credentials file ;)
 
cd # start in homedir
 
# check if there's any input
if [[ "$1" == "" || "$2" == "" ]]; then
	cat <<usage
Usage:
`basename $0` "your tweet message here" "/path/to/image/file.jpg"
USAGE
	exit 1;
fi
 
# check if image exists
if [[ ! -e "$2" ]]; then
	echo "That file (\"$2\") doesn't exist.  Try again."
	exit 1;
fi
 
# check if ~/twitter-credentials.asc exists
if [[ ! -e "twitter-credentials.asc" ]]; then
	echo "Can't find ~/twitter-credentials.asc"
	exit 1;
fi
 
# best keep your gpg-agent running...
cred=( $( gpg -d twitter-credentials.asc 2>/dev/null ) )
 
# BAM!  Do it. Upload the photo to tweetpic and post the tweet.
/usr/bin/curl --form username="${cred[0]}" --form password="${cred[1]}" \
--form media="@$2" --form-string "message=$1" \
https://twitpic.com/api/uploadAndPost
 
exit $?
 
# BUGS: email bugs/patches to the email address provided on line 2

· · · · ·

Atrixnet is owned and operated by me, Tommy Butler. Sometimes I do contract networking/programming jobs. Contact me for my résumé

 

Atrixnet is
Atrixnet is Linux Powered! - click to visit www.linux.com
Wikipedia Affiliate Button