Skip to content

Commit

Permalink
Merge branch 'release/2.0.18.1'
Browse files Browse the repository at this point in the history
* release/2.0.18.1:
  version bump
  Updating BlogLogger most popular to use @date_format
  Updated readme with new install instructions and CLI options
  fix missing local variable error in try block
  Better error handling for LastFMLogger
  CLI option to create/update config only, increase max_retries default to 3
  • Loading branch information
ttscoff committed May 4, 2013
2 parents a9d77f5 + 4810771 commit 6f58781
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 65 deletions.
47 changes: 20 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,35 +59,38 @@ Slogger indexes various public social services and creates Day One (<http://dayo
- Note that Slogger does not delete the original file, so your script needs to move files out of the folder manually to avoid double-processing.
- **NEW:** #tags in posts are saved as native tags. Default tags specified in the config are saved, as well as any hashtags present in the post. Github #XX issue references are ignored.

## Configure ##
## Install ##

1. From within the Slogger folder, run `./slogger` to create the initial configuration file. If this doesn't work, you may need to make the file executable: `chmod a+x slogger` from within the Slogger folder.
2. Edit the file `slogger_config` that shows up
- The only options will be 'storage:', 'image_filename_is_title:', 'date_format:' and 'time_format:'
1. Download and unzip (or clone using git) the Slogger project. It can be stored in your home directory, a scripts folder or anywhere else on your drive.
2. Default plugins are stored in `/plugins/`, additional plugins are usually found in `/plugins_disabled/`. Plugins are enabled and disabled by adding/removing them from the `/plugins/` folder. Move any additional plugins you want to use into `/plugins/` and disable any other plugins by moving them from `/plugins/` to `plugins_disabled`. (Plugins that are found in `plugins` but not configured will not break anything, but you'll see warnings when run.)
3. From within the Slogger folder, run `./slogger --update-config` to create the initial configuration file. If this doesn't work, you may need to make the file executable: `chmod a+x slogger` from within the Slogger folder. Note that any time you add new plugins or update existing ones, you'll want to run `./slogger --update-config` to ensure that your available options are up to date.
4. Edit the file `slogger_config` that shows up in your Slogger folder
- The required options will be 'storage:', 'image_filename_is_title:', 'date_format:' and 'time_format:'
- storage: should be one of
- 'icloud'
- a path to a Dropbox-synced Journal (e.g. '/Users/username/Dropbox/Apps/Day One/Journal.dayone')
- a path to a folder for storing markdown files and related images (if the path doesn't end in "Journal.dayone", markdown storage is triggered automatically)
- image_filename_is_title: should be set to true or false. If true, it will use the base filename (without extension) as the title of images imported individually.
- date_format and time_format should be set to your favorite style (strftime)
3. Move any additional plugins you want to use from `/plugins_disabled/` into `/plugins/`.
4. Run `./slogger` again to update the configuration file with enabled plugin options.
5. Edit `slogger_config` again and fill in the necessary parameters for listed configuration settings.
6. Next time you run `./slogger`, it will execute the plugins and generate your log entries.
- date_format and time_format should be set to your preferred style (strftime)

5. Edit additional configuration options for any plugins defined. The config file is formatted as YAML, and your options need to conform to that syntax. For the most part, you can just maintain the formatting (quotes, dashes, brackets, etc.) of the default settings when updating.
6. Next time you run `./slogger`, it will execute the enabled and configured plugins and generate your journal entries.

## Usage ##

1. From within the Slogger folder, run `./slogger` to run the data
capture for the plugins you have in you `/plugins/` directory.
2. You may run `./slogger` manually to test, or if you do not wish to automate the process.
3. If you wish to automate slogger, use Lingon (launchd) or other scheduling app.
4. You can install a launchd task that will automatically run at 11:50pm every night by running `install.rb`. It's the same as Lingon would create, but all automatic and everything.
- To uninstall the launchd task, run the command `rm ~/Library/LaunchAgents/com.brettterpstra.slogger.plist` and then log out and back in.
2. Check the output to see if there are any errors occurring. Plugin configuration errors can be ignored, or you can remove offending plugins from the `/plugins/` folder (if you don't need them).
3. If you wish to automate slogger:
- use [Lingon](http://www.peterborgapps.com/lingon/), [LaunchControl](http://www.soma-zone.com/LaunchControl/), or other `launchd` scheduling app, **or**...
- run `./install.rb` to automatically install a launchd task that will run at 11:50pm every night. It's the same as Lingon would create, but all free and stuff.
- To uninstall the launchd task, run the command `rm ~/Library/LaunchAgents/com.brettterpstra.slogger.plist` and then log out and back in.

## Command line options ##

$ ./slogger -h
Usage: slogger [-dq] [-r X] [/path/to/image.jpg]
--update-config Create or update a slogger_config file. No plugins will be run.
-c, --config FILE Specify alternate configuration file
-d, --develop Develop mode
-h, --help Display this screen
Expand All @@ -99,7 +102,7 @@ Slogger indexes various public social services and creates Day One (<http://dayo
-u, --undo COUNT Undo the last COUNT runs
-v, --version Display the version number

> **Note:** You can use the `-s` option to only log since the last run date, handy if you want to run Slogger more than once per day or are testing plugins.
> **Note:** You can use the `-s` option to only log since the last run date, handy if you want to run Slogger more or less than once per day or are testing plugins.
>
> You can also use `-o` to run only a certain plugin in the standard plugin directory: just provide it with enough of the name to be unique, e.g. `slogger -o gist`.
>
Expand Down Expand Up @@ -136,20 +139,10 @@ When developing plugins you can create a directory called 'plugins_develop' in t
_\ \| | (_) | (_| | (_| | __/ |
\__/|_|\___/ \__, |\__, |\___|_|
|___/ |___/
Copyright 2012, Brett Terpstra
Copyright 2013, Brett Terpstra
http://brettterpstra.com
--------------------

[The BSD License]

Copyright (c) 2012 Brett Terpstra

All rights reserved.

> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
> Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
> Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
Slogger by Brett Terpstra is licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License][license].

> **THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.**
[license]: http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US
2 changes: 1 addition & 1 deletion plugins/BlogLogger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def parse_feed(rss_feed)
}
unless posts.empty?
options = {}
options['content'] = "## Most Tweeted posts on #{rss.title.content} for #{Time.now.strftime('%b %d, %Y')}\n\n"
options['content'] = "## Most Tweeted posts on #{rss.title.content} for #{Time.now.strftime(@date_format)}\n\n"
posts.sort_by { |post| post['count'] }.reverse[0..5].each {|post|
options['content'] += "* [#{post['title']}](#{post['url']}) (#{post['count']})\n"
}
Expand Down
79 changes: 51 additions & 28 deletions plugins/lastfmlogger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
$slog.register_plugin({ 'class' => 'LastFMLogger', 'config' => config })

class LastFMLogger < Slogger
def get_fm_feed(feed)
begin
rss_content = false
feed_url = URI.parse(feed)
feed_url.open do |f|
rss_content = f.read
end
return rss_content
rescue
return false
end
end

def do_log
if @config.key?(self.class.name)
Expand All @@ -39,67 +51,78 @@ def do_log
config['lastfm_feeds'] ||= ['recent', 'loved']

feeds = []
feeds << {'title'=>"## Listening To", 'feed' => "http://ws.audioscrobbler.com/2.0/user/#{config['lastfm_user']}/recenttracks.rss?limit=100"} if config['lastfm_feeds'].include?('recent')
feeds << {'title'=>"## Loved Tracks", 'feed' => "http://ws.audioscrobbler.com/2.0/user/#{config['lastfm_user']}/lovedtracks.rss?limit=100"} if config['lastfm_feeds'].include?('loved')
feeds << {'title'=>"Listening To", 'feed' => "http://ws.audioscrobbler.com/2.0/user/#{config['lastfm_user']}/recenttracks.rss?limit=100"} if config['lastfm_feeds'].include?('recent')
feeds << {'title'=>"Loved Tracks", 'feed' => "http://ws.audioscrobbler.com/2.0/user/#{config['lastfm_user']}/lovedtracks.rss?limit=100"} if config['lastfm_feeds'].include?('loved')

today = @timespan

@log.info("Getting Last.fm playists for #{config['lastfm_user']}")

feeds.each do |rss_feed|
entrytext = ''
rss_content = ""
begin
feed_url = URI.parse(rss_feed['feed'])
feed_url.open do |f|
rss_content = f.read
end
rescue Exception => e
raise "ERROR fetching feed #{rss_feed['title']}"
p e
rss_content = try { get_fm_feed(rss_feed['feed'])}
unless rss_content
@log.error("Failed to retrieve #{rss_feed['title']} for #{config['lastfm_user']}")
break
end
content = ''
rss = RSS::Parser.parse(rss_content, false)

# define a hash to store song count and a hash to link song title to the last.fm URL
songs_count = {}
title_to_link = {}
songs_count = {}
title_to_link = {}

rss.items.each { |item|
break if Time.parse(item.pubDate.to_s) < today
title = String(item.title).e_link()
link = String(item.link).e_link()

# keep track of URL for each song title
# keep track of URL for each song title
title_to_link[title] = link

# store play counts in hash
if songs_count[title].nil?
songs_count[title] = 1
else
songs_count[title] += 1
end
if songs_count[title].nil?
songs_count[title] = 1
else
songs_count[title] += 1
end
}

# loop over each song and make final output as appropriate
# (depending on whether there was 1 play or more)
# (depending on whether there was 1 play or more)
songs_count.each { |k, v|

# a fudge because I couldn't seem to access this hash value directly in
# the if statement
link = title_to_link[k]
link = title_to_link[k]

if v == 1
content += "* [#{k}](#{link})\n"
else
content += "* [#{k}](#{link}) (#{v} plays)\n"
end
}
if v == 1
content += "* [#{k}](#{link})\n"
else
content += "* [#{k}](#{link}) (#{v} plays)\n"
end
}

if content != ''
entrytext = "#{rss_feed['title']} for #{today.strftime(@date_format)}\n\n" + content + "\n#{tags}"
entrytext = "## #{rss_feed['title']} for #{today.strftime(@date_format)}\n\n" + content + "\n#{tags}"
end
DayOne.new.to_dayone({'content' => entrytext}) unless entrytext == ''
end
end

def try(&action)
retries = 0
success = false
until success || $options[:max_retries] == retries
result = yield
if result
success = true
else
retries += 1
@log.error("Error performing action, retrying (#{retries}/#{$options[:max_retries]})")
sleep 2
end
end
result
end
end
1 change: 0 additions & 1 deletion plugins/twitterlogger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ def try(&action)
if result
success = true
else
@log.error e
retries += 1
@log.error("Error performing action, retrying (#{retries}/#{$options[:max_retries]})")
sleep 2
Expand Down
2 changes: 1 addition & 1 deletion slogger
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# --------------------
MAJOR_VERSION = 2.0
MINOR_VERSION = 18
BUILD_NUMBER = 0
BUILD_NUMBER = 1

init_env = ENV['SLOGGER_NO_INITIALIZE'].to_s
ENV['SLOGGER_NO_INITIALIZE'] = "false"
Expand Down
19 changes: 12 additions & 7 deletions slogger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,14 @@ def run_plugins
end
@config[_namespace][_namespace+"_last_run"] = Time.now.strftime('%c')
end
# credit to Hilton Lipschitz (@hiltmon)
updated_config = eval(plugin['class']).new.do_log
if updated_config && updated_config.class.to_s == 'Hash'
updated_config.each { |k,v|
@config[_namespace][k] = v
}
unless $options[:config_only]
# credit to Hilton Lipschitz (@hiltmon)
updated_config = eval(plugin['class']).new.do_log
if updated_config && updated_config.class.to_s == 'Hash'
updated_config.each { |k,v|
@config[_namespace][k] = v
}
end
end
end
ConfigTools.new({'config_file' => $options[:config_file]}).dump_config(@config)
Expand Down Expand Up @@ -310,6 +312,9 @@ def template
optparse = OptionParser.new do|opts|
opts.banner = "Usage: slogger [-dq] [-r X] [/path/to/image.jpg]"
$options[:config_file] = File.expand_path(File.dirname(__FILE__)+'/slogger_config')
opts.on('--update-config', 'Create or update a configuration file') do
$options[:config_only] = true
end
opts.on( '-c', '--config FILE', 'Specify configuration file to use') do |file|
file = File.expand_path(file)
$options[:config_file] = file
Expand All @@ -330,7 +335,7 @@ def template
opts.on( '-q','--quiet', 'Run quietly (no notifications/messages)' ) do
$options[:quiet] = true
end
$options[:max_retries] = 1
$options[:max_retries] = 3
opts.on( '-r','--retries COUNT', 'Maximum number of retries per plugin (int)' ) do |count|
$options[:max_retries] = count.to_i
end
Expand Down

0 comments on commit 6f58781

Please sign in to comment.