-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost2json.rb
More file actions
36 lines (35 loc) · 727 Bytes
/
post2json.rb
File metadata and controls
36 lines (35 loc) · 727 Bytes
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
require 'sinatra'
require 'rubygems'
require 'pismo'
require 'json'
require 'thin'
get '/' do
begin
url = params[:url]
logger.info "#{url}"
unless url[/^http:\/\//] || url[/^https:\/\//]
url = 'http://' + url
end
raise 'Invalid URL' if url.empty?
doc = Pismo::Document.new(url)
post = {
:url => url,
:favicon => doc.favicon,
:feed => doc.feed,
:title => doc.title,
:author => doc.author,
:excerpt => doc.description,
:body_text => doc.body,
:body_html => doc.html_body,
:images => nil,
:timestamp => doc.datetime
}
if !doc.images.nil?
post[:images] = doc.images
end
content_type :json
JSON.pretty_generate(post)
rescue Exception => e
logger.error e
end
end