Permalink
Browse files

Twitter and Pinboard plugins updates

I've started converting more plugins to split long time periods into
days and insert them properly. Also making main tags at the end appear
in parenthesis for better Markdown compatibility (don't become
headlines)
  • Loading branch information...
1 parent 09e0710 commit 3943318cc5d74e7f8bb70d74368aaa410a6a959d @ttscoff committed Feb 14, 2014
Showing with 40 additions and 19 deletions.
  1. +37 −16 plugins/pinboardlogger.rb
  2. +3 −3 plugins/twitterlogger.rb
View
@@ -29,6 +29,23 @@
require 'rss/dublincore'
class PinboardLogger < Slogger
+ def split_days(bookmarks)
+ # tweets.push({:text => tweet_text, :date => tweet_date, :screen_name => screen_name, :images => tweet_images, :id => tweet_id})
+ dated_bookmarks = {}
+ bookmarks.each {|mark|
+ date = mark[:date].strftime('%Y-%m-%d')
+ dated_bookmarks[date] = [] unless dated_bookmarks[date]
+ dated_bookmarks[date].push(mark)
+ }
+ dated_bookmarks
+ end
+
+ def digest_entry(bookmarks, tags)
+ bookmarks.reverse.map do |t|
+ t[:content]
+ end.join("\n") << "\n(#{tags})"
+ end
+
def do_log
if @config.key?(self.class.name)
config = @config[self.class.name]
@@ -47,7 +64,8 @@ def do_log
today = @timespan.to_i
@log.info("Getting Pinboard bookmarks for #{config['pinboard_feeds'].length} feeds")
- output = ''
+ feed_link = ''
+ feed_output = []
config['pinboard_feeds'].each do |rss_feed|
begin
@@ -57,46 +75,49 @@ def do_log
end
rss = RSS::Parser.parse(rss_content, false)
- feed_output = ''
+
rss.items.each { |item|
- feed_output = '' unless config['pinboard_digest']
+ feed_output = [] unless config['pinboard_digest']
item_date = Time.parse(item.date.to_s) + Time.now.gmt_offset
if item_date > @timespan
content = ''
post_tags = ''
if config['pinboard_digest']
- content = "\n " + item.description.gsub(/\n/, "\n ").strip unless item.description.nil?
+ content = "\n\t" + item.description.gsub(/\n/, "\n\t").strip unless item.description.nil?
else
content = "\n> " + item.description.gsub(/\n/, "\n> ").strip unless item.description.nil?
end
- content = "\n#{content}\n" unless content == ''
+ content = "#{content}\n" unless content == ''
if config['pinboard_save_hashtags']
- post_tags = "\n" + item.dc_subject.split(' ').map { |tag| "##{tag}" }.join(' ') + "\n" unless item.dc_subject.nil?
+ post_tags = "\n\t\t" + item.dc_subject.split(' ').map { |tag| "##{tag}" }.join(' ') + "\n" unless item.dc_subject.nil?
end
- post_tags = "\n#{post_tags}\n" unless post_tags == ''
- feed_output += "#{config['pinboard_digest'] ? '* ' : ''}[#{item.title.gsub(/\n/, ' ').strip}](#{item.link})\n#{content}#{post_tags}"
+
+ feed_output.push({:date => Time.parse(item.date.to_s), :content => "#{config['pinboard_digest'] ? '* ' : ''}[#{item.title.gsub(/\n/, ' ').strip}](#{item.link})\n#{content}#{post_tags}"})
else
break
end
- output = feed_output unless config['pinboard_digest']
+ output = feed_output[0][:content] unless feed_output[0].nil? or config['pinboard_digest']
unless output == '' || config['pinboard_digest']
options = {}
- options['datestamp'] = Time.parse(item.date.to_s).utc.iso8601
- options['content'] = "## New Pinboard bookmark\n#{output}#{tags}"
+ options['datestamp'] = feed_output[0][:date].utc.iso8601
+ options['content'] = "## New Pinboard bookmark\n#{output}(#{tags})"
sl.to_dayone(options)
end
}
- output += "#### [#{rss.channel.title}](#{rss.channel.link})\n\n" + feed_output + "\n" unless feed_output == ''
+ feed_link = "[#{rss.channel.title}](#{rss.channel.link})" unless feed_output.empty?
rescue Exception => e
puts "Error getting posts for #{rss_feed}"
p e
return ''
end
end
- unless output == '' || !config['pinboard_digest']
- options = {}
- options['content'] = "## Pinboard bookmarks\n\n#{output}#{tags}"
- sl.to_dayone(options)
+ unless feed_link == '' || !config['pinboard_digest']
+ dated_marks = split_days(feed_output)
+ dated_marks.each {|k,v|
+ content = "## Pinboard bookmarks\n\n### #{feed_link} on #{Time.parse(k).strftime(@date_format)}\n\n"
+ content << digest_entry(v, tags)
+ sl.to_dayone({'content' => content, 'datestamp' => Time.parse(k).utc.iso8601})
+ }
end
end
end
View
@@ -59,7 +59,7 @@ def single_entry(tweet)
@twitter_config['twitter_tags'] ||= ''
options = {}
- options['content'] = "#{tweet[:text]}\n\n-- [@#{tweet[:screen_name]}](https://twitter.com/#{tweet[:screen_name]}/status/#{tweet[:id]})\n\n#{@twitter_config['twitter_tags']}\n"
+ options['content'] = "#{tweet[:text]}\n\n-- [@#{tweet[:screen_name]}](https://twitter.com/#{tweet[:screen_name]}/status/#{tweet[:id]})\n\n(#{@twitter_config['twitter_tags']})\n"
tweet_time = Time.parse(tweet[:date].to_s)
options['datestamp'] = tweet_time.utc.iso8601
@@ -246,8 +246,8 @@ def do_log
@twitter_config['digest_timeline'] ||= true
sl = DayOne.new
- @twitter_config['twitter_tags'] ||= '#social #twitter'
- tags = "\n\n#{@twitter_config['twitter_tags']}\n" unless @twitter_config['twitter_tags'] == ''
+ @twitter_config['twitter_tags'] ||= ''
+ tags = "\n\n(#{@twitter_config['twitter_tags']})\n" unless @twitter_config['twitter_tags'] == ''
@twitter_config['twitter_users'].each do |user|

0 comments on commit 3943318

Please sign in to comment.