Permalink
Browse files

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

livejournal post.
  • Loading branch information...
dagbrown authored and Dave Brown committed Sep 28, 2007
1 parent 6af0333 commit 13ec9e750790c03ca3df1b4d2be5cd70c5410d3f
Showing with 35 additions and 0 deletions.
  1. +35 −0 bin/ljpost
View
@@ -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

0 comments on commit 13ec9e7

Please sign in to comment.