Created
February 15, 2010 13:58
-
-
Save hron84/304668 to your computer and use it in GitHub Desktop.
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
BEGIN { | |
post_email="senki@sehol.se"; | |
post_pass="verysecret"; | |
# Optional, delete this line if empty | |
post_siteid="1234567"; | |
####################### DO NOT EDIT BELOW THIS ########################## | |
# Program name and URL | |
post_source = "GNU AWK"; | |
post_source_link = "http://www.gnu.org/software/gawk/gawk.html"; | |
# Initializing some wars | |
post_title=""; | |
post_body=""; | |
# Collecting title | |
for(i = 1; i < ARGC; i++) { | |
post_title = (post_title ARGV[i] " "); | |
} | |
# Flushing args | |
ARGC = 2; ARGV[1] = "-"; | |
gsub(/\s+$/, "", post_title); | |
} | |
function urlencode(string) { | |
s = string | |
gsub(/[ \t]/, "%20", s); | |
gsub(/+/, "%2B", s); | |
gsub(/\*/, "%2A", s); | |
gsub(/\//, "%2F", s); | |
gsub(/@/, "%40", s); | |
gsub(/=/, "%3D", s); | |
gsub(/!/, "%21", s); | |
gsub(/\n/, "%3Cbr/%3E", s); | |
return s; | |
} | |
{ | |
post_body = (post_body $0 "\n"); | |
} | |
END { | |
# Collecting command | |
cmd = ("curl --user " post_email ":" post_pass " -d \""); | |
if(post_siteid != "") { | |
cmd = (cmd "site_id=" post_siteid "&"); | |
} | |
cmd = (cmd "title=" post_title); | |
cmd = (cmd "&body=" urlencode(post_body)); | |
cmd = (cmd "&source=" post_source); | |
cmd = (cmd "&sourceLink=" post_source_link); | |
cmd = (cmd "\" http://posterous.com/api/newpost"); | |
while((cmd | getline line) > 0) { | |
if(line ~ /<err/) { | |
gsub(/<err/, "", line); | |
gsub(/"/, "", line); | |
split(line, a); | |
sub(/code=/, "", a[1]); | |
sub(/msg=/, "", a[2]); | |
print "An error occurred: " a[2] " (" a[1] ")"; | |
close(cmd); | |
break; | |
} else if(line ~ /<url>/) { | |
gsub(/<[^>]+>/, "", line); | |
gsub(/\s+/, " ", line); | |
print "Post succesfully sent, URL: " line; | |
close(cmd); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment