pinoss/feedbook

View on GitHub
bin/feedbook

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')

require 'gli'
require 'box'
require 'feedbook'
require 'fileutils'

include GLI::App

program_desc 'Feedbook is a simple gem and application that notifies about new posts and Atom/RSS updates on your social media sites (like Facebook and Twitter), e-mail or IRC.'

desc 'Parses feedbook.yml file for feeds and configuration and listen for changes in RSS/Atom feeds to notify about updates on social media sites'
command :start do |c|

  c.flag [:c, :config],  default_value: 'feedbook.yml',          desc: 'Feedbook configuration file location'
  c.flag [:p, :plugins], default_value: './plugins',             desc: 'Plugins directory'
  c.flag [:a, :archive], default_value: 'feedbook_offline.yml',  desc: 'Feedbook archive file'

  c.default_desc 'Parses feedbook.yml file for feeds and configuration and listen for changes in RSS/Atom feeds to notify about updates on social media sites'
  c.action do |_, options, _|
    Feedbook::Listener.start(options[:config], options[:plugins])
  end

  c.desc 'Parses feedbook.yml file for feeds and configuration and listen for changes in RSS/Atom feeds to notify about updates on social media sites'
  c.command :offline do |cc|

    cc.action do |_, options, _|
      Feedbook::Listener.start_offline(options[:config], options[:archive], options[:plugins])
    end
  end
end

desc 'Creates basic feedbook config file'
command :init do |c|

  c.flag [:c,:config], default_value: 'feedbook.yml', desc: 'Feedbook configuration file location'

  c.action do |_, options, _|
    abort 'There is already a feedbook configuration file' if File.exist?(options[:config])
    File.open(options[:config], 'w') { |f| f.write(Box::FILES['feedbook']) }
    puts "=> Created default feedbook configuration file: #{options[:config]}"
  end
end

desc 'Outputs feedbook gem version'
command :version do |c|
  c.action do |_, _, _|
    puts "feedbook version: #{Feedbook::VERSION}"
  end
end

on_error do |exception|
  case exception
  when SystemExit
  else
    STDERR.puts "Error: #{exception} (#{exception.class})"
    STDERR.puts exception.backtrace.join("\n")
  end
  false
end

exit run(ARGV)

__END__
@@  feedbook
## Feedbook default config file, modify it!

feeds:
  - url: https://github.com/pinoss.atom
    variables:
      default_header: Check out our new post
    notifications:
      - type: facebook
        template: "{{ default_header }} {{ title }} by {{ author }}: {{ url }}"
      - type: twitter
        template: "{{ default_header }} on our blog {{ feed_url }}: {{ title }}/{{ url }}"

configuration:
  interval: 5m
  facebook:
    token: SECRET_FACEBOOK_TOKEN
  twitter:
    api_key: SECRET_API_KEY
    api_secret: SECRET_API_SECRET
    access_token: SECRET_TWITTER_ACCESS_TOKEN
    access_token_secret: SECRET_TWITTER_ACCESS_TOKEN_SECRET