/usr/share/yapra/legacy_plugins/Publish/delicious.rb is in yapra 0.1.2-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | ## Publish::delicious - to post feed items to del.icio.us-- emergent
##
## - module: Publish::delicious
## config:
## username: your_username
## password: your_password
## opt_tag: pragger
## no_comment: 1
##
require 'rubygems'
require 'mechanize'
require 'uri'
require 'kconv'
class Delicious
def initialize username, password, proxy=nil
@username = username
@password = password
@agent = Mechanize.new
@agent.basic_auth(@username, @password)
if proxy && proxy.is_a?(Hash) && proxy['proxy_addr'] && proxy['proxy_port']
@agent.set_proxy(proxy['proxy_addr'], proxy['proxy_port'],
proxy['proxy_user'], proxy['proxy_pass'])
end
end
def post url, desc, option=nil
params = {}
post_url = 'https://api.del.icio.us/v1/posts/add?'
params[:url] = url
params[:description] = desc
if option
params[:extended] = option["summary"] if option["summary"]
params[:dt] = option["datetime"] if option["datetime"]
params[:tags] = option["tags"] if option["tags"]
params[:replace] = 'no' if option["no_replace"]
params[:shared] = 'no' if option["private"]
end
req_param = []
params.map do |k,v|
req_param << k.to_s.toutf8 + '=' + v.toutf8 if (v.length > 0)
end
result = @agent.get(URI.encode(post_url + req_param.join('&')))
puts URI.encode(post_url + req_param.join('&'))
if result.body =~ /code="done"/
return true
end
false
end
end
def get_tags entry
entry.dc_subjects.map do |s| s.content end.join(' ') rescue ''
end
def delicious config, data
sleeptime = 3
if config['sleep']
sleeptime = config['sleep'].to_i
end
data.each {|entry|
print 'posting ' + entry.title + ': '
tags = get_tags entry
if config['opt_tag']
tags = [tags, config['opt_tag']].select{|t| t.length > 0}.join(' ')
end
summary = config['no_comment'].to_i > 0 ? '' : entry.description
begin
agent = Delicious.new(config['username'], config['password'])
res = agent.post(entry.link, entry.title,
'tags' => tags, 'summary' => summary)
if res then puts 'done' else puts 'failed' end
rescue
puts 'exception'
#raise
end
sleep sleeptime
}
data
end
|