-
Notifications
You must be signed in to change notification settings - Fork 5
/
booker_wp.rb
executable file
·57 lines (53 loc) · 1.54 KB
/
booker_wp.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
# wordcloud.rb
require 'rubygems'
require 'sinatra'
require 'haml'
require 'feed-normalizer'
require 'prince-ruby'
require 'json'
require 'open-uri'
require 'digest/md5'
require 'rdelicious'
require 'readability_old.rb'
post '/' do
feedurl = params[:feedurl]
dname = params[:dname]
dpass = params[:dpass]
delicious = Rdelicious.new(dname, dpass)
posts = []
@chapters = []
feed = FeedNormalizer::FeedNormalizer.parse open(feedurl)
feed.entries.each do |post|
puts post.urls.first.index(/[jpg|png|gif]/)
puts post.urls.first
if ((post.urls.first.include? 'jpg') || (post.urls.first.include? 'png') || (post.urls.first.include? 'gif'))
@chapters.push("content"=>"<img src=\""+post.urls.first+"\">")
else
url = 'http://felixcohen.co.uk/readability.php?url='+post.urls.first
text = open(url).read
@chapters.push("title"=>post.title,"content"=>text)
end
delicious.add(post.urls.first,post.title,'','madeintoabook') if delicious.is_connected?
end
template = File.read('views/book.haml')
haml_engine = Haml::Engine.new(template)
output = haml_engine.render(Object.new, :@chapters => @chapters)
puts output
file = "/tmp/"+feedurl+".pdf"
prince = Prince.new
prince.add_style_sheets("views/print.css")
prince.html_to_file(output, file)
send_file(
file,
:filename => '/tmp/'+feedurl+'.pdf',
:type => 'application/pdf'
)
end
get '/' do
haml :index
end
get '/print.css' do
send_file(
'views/print.css',
:type => 'text/css'
)end