Skip to content

Instantly share code, notes, and snippets.

@hron84
Created January 12, 2010 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hron84/275390 to your computer and use it in GitHub Desktop.
Save hron84/275390 to your computer and use it in GitHub Desktop.
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