Created
January 12, 2010 17:37
-
-
Save hron84/275392 to your computer and use it in GitHub Desktop.
Twitter2.awk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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