Skip to content

Instantly share code, notes, and snippets.

@hron84
Created January 12, 2010 17:37
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/275392 to your computer and use it in GitHub Desktop.
Save hron84/275392 to your computer and use it in GitHub Desktop.
Twitter2.awk
#!/usr/bin/awk -f
BEGIN {
twuser="user"
twpass="secret"
status = "";
}
{
status = status " " $0;
}
END {
if(twuser == "" || twpass == "") {
print "No twitter username or password defined";
exit 1;
}
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;
}
}
}
# vim: ts=4 sw=4 et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment