-
Notifications
You must be signed in to change notification settings - Fork 6
/
poster.rb
executable file
·60 lines (42 loc) · 1.14 KB
/
poster.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env ruby
require 'httparty'
require 'yaml'
require 'uri'
$config = YAML::load( File.open( 'private.yml' ) )
$creds = $config['tinycc']
def minify( post_url, slug )
post_uri = URI.escape(post_url)
url = "http://tiny.cc/?c=rest_api&m=shorten&version=2.0.3&format=json&shortUrl=#{slug}&longUrl=#{post_uri}&login=#{$creds['user']}&apiKey=#{$creds['key']}"
#response = HTTParty.get(url)
return url
end
def publish
post_url='http://www.rasplex.com'
slug='blah'
url = minify(post_url,slug)
puts url
end
def new(title, type)
dateshort = Time.now().strftime("%Y-%m-%d")
datelong = Time.now().strftime("%Y-%m-%d %H-%M-%S")
fname = "#{dateshort}-#{title.downcase.split(' ').join('-')}.markdown"
header_data = {
"title" => title,
"modified" => datelong,
"layout" => type,
"tags" => []
}
header = YAML.dump(header_data)
header = "#{header}---"
outname = "_posts/"+fname
outfile = File.open(outname,"w")
outfile.write(header)
outfile.close
puts "Post file created at #{outname}"
end
command = ARGV[0]
type = ARGV[1]
title = ARGV[2]
if command == 'new'
new(title, type)
end