Skip to content

Instantly share code, notes, and snippets.

@hron84 hron84/gist:275390
Created Jan 12, 2010

Embed
What would you like to do?
Twitter1.awk
#!/usr/bin/awk -f
BEGIN {
twuser="user"
twpass="secret"
status = "";
if(twuser == "" || twpass == "") {
print "No twitter username or password defined";
exit 1;
}
print "Type your Twitter message:"
while((getline line < "/dev/stdin") > 0) {
status = (status " " line);
}
status = substr(status, 1, 140);
sub(/^ +/, "", status);
cmd = "curl -s -u " twuser ":" twpass " -d status=\"" status "\" http://twitter.com/statuses/update.xml";
while((cmd | getline line) > 0) {
if(line ~ /<error /) {
gsub(/<[^>]+>/, "", line);
sub(/^ +/, "", line);
print "An error occurred: " line;
close(cmd);
break;
} else if (line ~ /<id>/) {
gsub(/<[^>]+>/, "", line);
sub(/^ +/, "", line);
print "Status updated: http://twitter.com/" twuser "/statuses/" line;
close(cmd);
break;
}
}
exit 0;
}
# vim: ts=4 sw=4 et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.