Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Merge commit '932498453a21cb39df7681d4a476fa19f1eb7f84'
Browse files Browse the repository at this point in the history
* commit '932498453a21cb39df7681d4a476fa19f1eb7f84':
  use utc start time for strava logger
  change strava header from ride to activity
  update strava to version 3 of their api
  mock http calls
  starting on some specs for the plugins
  bump
  Twitter and Pinboard plugins updates
  version bump
  update
  TwitterLogger update Store tweets by date in digest mode, reimplement droplr downloads, save images from favorites.
  format the completion date consistently across locales
  Add line break to end of {note} to separate tasks
  Allow todo entries to create journal entries per day
  • Loading branch information
drallgood committed Feb 25, 2014
2 parents bb89c17 + 9324984 commit 51bb2b8
Show file tree
Hide file tree
Showing 14 changed files with 521 additions and 147 deletions.
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ gem 'feed-normalizer'
gem 'twitter', '~> 5.3.0'
gem 'twitter_oauth'
gem 'json'

group :test do
gem 'rake'
gem 'rspec'
gem 'vcr'
gem 'webmock'
end
43 changes: 32 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,69 @@ GEM
addressable (2.3.5)
atomic (1.1.14)
buftok (0.2.0)
crack (0.4.2)
safe_yaml (~> 1.0.0)
descendants_tracker (0.0.3)
equalizer (0.0.7)
faraday (0.8.8)
multipart-post (~> 1.2.0)
diff-lcs (1.2.5)
equalizer (0.0.9)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
feed-normalizer (1.5.2)
hpricot (>= 0.6)
simple-rss (>= 1.1)
hpricot (0.8.6)
http (0.5.0)
http_parser.rb
http_parser.rb (0.6.0)
json (1.8.0)
memoizable (0.3.1)
json (1.8.1)
memoizable (0.4.0)
thread_safe (~> 0.1.3)
mime-types (1.23)
multipart-post (1.2.0)
mime-types (2.1)
multipart-post (2.0.0)
oauth (0.4.7)
simple-rss (1.2.3)
rake (10.1.1)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.7)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.5)
safe_yaml (1.0.1)
simple-rss (1.3.1)
simple_oauth (0.2.0)
thread_safe (0.1.3)
atomic
twitter (5.3.0)
twitter (5.3.1)
addressable (~> 2.3)
buftok (~> 0.2.0)
descendants_tracker (~> 0.0.1)
equalizer (~> 0.0.7, != 0.0.8)
equalizer (~> 0.0.9)
faraday (>= 0.8, < 0.10)
http (~> 0.5.0)
http_parser.rb (~> 0.6.0)
json (~> 1.8)
memoizable (~> 0.3.1)
memoizable (~> 0.4.0)
simple_oauth (~> 0.2.0)
twitter_oauth (0.4.94)
json (>= 1.8.0)
mime-types (>= 1.16)
oauth (>= 0.4.7)
vcr (2.8.0)
webmock (1.15.2)
addressable (>= 2.2.7)
crack (>= 0.3.2)

PLATFORMS
ruby

DEPENDENCIES
feed-normalizer
json
rake
rspec
twitter (~> 5.3.0)
twitter_oauth
vcr
webmock
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec

53 changes: 37 additions & 16 deletions plugins/pinboardlogger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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
62 changes: 44 additions & 18 deletions plugins/twitterlogger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -91,11 +91,11 @@ def get_tweets(user,type='timeline')
case type

when 'favorites'
params = { "count" => 250, "screen_name" => user, "include_entities" => true }
params = { :count => 250, :screen_name => user, :include_entities => true }
tweet_obj = client.favorites(params)

when 'timeline'
params = { "count" => 250, "screen_name" => user, "include_entities" => true, "exclude_replies" => @twitter_config['exclude_replies'], "include_rts" => @twitter_config['save_retweets']}
params = { :count => 250, :screen_name => user, :include_entities => true, :exclude_replies => @twitter_config['exclude_replies'], :include_rts => @twitter_config['save_retweets']}
tweet_obj = client.user_timeline(params)

end
Expand All @@ -109,6 +109,7 @@ def get_tweets(user,type='timeline')
break if tweet_date < today
tweet_text = tweet.text.gsub(/\n/,"\n\t")
screen_name = user

if type == 'favorites'
# TODO: Prepend favorite's username/link
screen_name = tweet.user.status.user.screen_name
Expand Down Expand Up @@ -147,10 +148,13 @@ def get_tweets(user,type='timeline')
tweet_images.push(final_url) unless final_url.nil?
end
# Drop.lr downloads temporarily broken
# tweet_text.scan(/\((http:\/\/#{@twitter_config['droplr_domain']}\/\w+?)\)/).each do |picurl|
# # final_url = self.get_body(picurl[0]).match(/"(https:\/\/s3.amazonaws.com\/files.droplr.com\/.+?)"/)
# tweet_images << { 'content' => tweet_text, 'date' => tweet_date.utc.iso8601, 'url' => picurl[0]+"+" } # unless final_url.nil?
# end
tweet_text.scan(/\((http:\/\/#{@twitter_config['droplr_domain']}\/\w+?)\)/).each do |picurl|
# final_url = self.get_body(picurl[0]).match(/"(https:\/\/s3.*?\.amazonaws\.com\/droplr\.storage\/.+?)"/)
# tweet_images << { 'content' => tweet_text, 'date' => tweet_date.utc.iso8601, 'url' => picurl[0]+"+" } # unless final_url.nil?
aurl = URI.parse(picurl[0]+"+")
curl = RedirectFollower.new(aurl).resolve
tweet_images.push(curl) unless curl.nil?
end

tweet_text.scan(/\((http:\/\/instagr\.am\/\w\/.+?\/)\)/).each do |picurl|
final_url=self.get_body(picurl[0]).match(/http:\/\/distilleryimage.*?\.com\/[a-z0-9_]+\.jpg/)
Expand Down Expand Up @@ -182,6 +186,17 @@ def get_tweets(user,type='timeline')

end

def split_days(tweets)
# tweets.push({:text => tweet_text, :date => tweet_date, :screen_name => screen_name, :images => tweet_images, :id => tweet_id})
dated_tweets = {}
tweets.each {|tweet|
date = tweet[:date].strftime('%Y-%m-%d')
dated_tweets[date] = [] unless dated_tweets[date]
dated_tweets[date].push(tweet)
}
dated_tweets
end

def do_log
if @config.key?(self.class.name)
@twitter_config = @config[self.class.name]
Expand Down Expand Up @@ -231,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|

Expand All @@ -245,13 +260,18 @@ def do_log
end

unless tweets.empty?

if @twitter_config['digest_timeline']
content = "## Tweets\n\n### Posts by @#{user} on #{Time.now.strftime(@date_format)}\n\n"
content << digest_entry(tweets, tags)
sl.to_dayone({'content' => content})
if @twitter_config['save_images']
tweets.select {|t| !t[:images].empty? }.each {|t| self.single_entry(t) }
end
dated_tweets = split_days(tweets)
dated_tweets.each {|k,v|
content = "## Tweets\n\n### Posts by @#{user} 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})
if @twitter_config['save_images']
tweets.select {|t| !t[:images].empty? }.each {|t| self.single_entry(t) }
end
}

else
tweets.each do |t|
self.single_entry(t)
Expand All @@ -260,9 +280,15 @@ def do_log

end
unless favs.empty?
content = "## Favorite Tweets\n\n### Favorites from @#{user} for #{Time.now.strftime(@date_format)}\n\n"
content << digest_entry(favs, tags)
sl.to_dayone({'content' => content})
dated_tweets = split_days(favs)
dated_tweets.each {|k,v|
content = "## Favorite Tweets\n\n### Favorites from @#{user} 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})
if @twitter_config['save_images_from_favorites']
favs.select {|t| !t[:images].empty? }.each {|t| self.single_entry(t) }
end
}
end
end

Expand Down
2 changes: 1 addition & 1 deletion plugins_disabled/omnifocus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def do_log
end
if note != "null" && log_notes
note = note.gsub("\\n","\n> ")
taskString += "*Notes:*\n> #{note}"
taskString += "*Notes:*\n> #{note}\n"
end

output += taskString
Expand Down
Loading

0 comments on commit 51bb2b8

Please sign in to comment.