Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Here's the other half of the pair of utils: ljpost lets you write a

livejournal post.
  • Loading branch information...
commit 13ec9e750790c03ca3df1b4d2be5cd70c5410d3f 1 parent 6af0333
@dagbrown authored Dave Brown committed
Showing with 35 additions and 0 deletions.
  1. +35 −0 bin/ljpost
View
35 bin/ljpost
@@ -0,0 +1,35 @@
+#!/opt/bin/ruby
+
+LJPOSTDIR=ENV["HOME"]+"/.ljpost"
+
+require "tempfile"
+require "yaml"
+require "time"
+
+t=Tempfile.new("ljpost")
+t.write(File.read("#{LJPOSTDIR}/template"))
+t.close
+system(ENV["VISUAL"],t.path)
+
+fh=File.open(t.path,File::RDONLY)
+
+text=fh.read
+# (headertext,bodytext)=t.read.split(/^--------$/,2);
+(headertext,bodytext)=text.split(/^--text follows this line--$/,2);
+headers=Hash.new
+headertext.split(/\n/).each do |line|
+ header,value=line.split(/: ?/,2)
+ headers[header]=value
+end
+headers["Body"]=bodytext
+
+if headers["Date"] != "" then
+ headers["Date"]=Time.parse(headers["Date"])
+else
+ headers["Date"]=Time.now
+end
+
+File.open("#{LJPOSTDIR}/outgoing/"+headers["Date"].strftime("%Y%m%d%H%M%S"),
+ "w") do |f|
+ f.write(headers.to_yaml)
+end
Please sign in to comment.
Something went wrong with that request. Please try again.