diff --git a/app/tootify.rb b/app/tootify.rb index 23d877a..e36e5b7 100644 --- a/app/tootify.rb +++ b/app/tootify.rb @@ -4,9 +4,12 @@ require_relative 'bluesky_account' require_relative 'mastodon_account' class Tootify + attr_accessor :check_interval + def initialize @bluesky = BlueskyAccount.new @mastodon = MastodonAccount.new + @check_interval = 60 end def login_bluesky(handle) @@ -54,6 +57,13 @@ class Tootify end end + def watch + loop do + sync + sleep @check_interval + end + end + def post_to_mastodon(record) p record diff --git a/tootify b/tootify index aad20c9..5232169 100755 --- a/tootify +++ b/tootify @@ -3,16 +3,24 @@ require 'bundler/setup' require_relative 'app/tootify' -$app = Tootify.new - def run(argv) options, args = argv.partition { |x| x.start_with?('-') } + app = Tootify.new + + options.each do |o| + if o.start_with?('--interval=') + app.check_interval = o.split('=')[1].to_i + end + end + case args.first when 'login' login(args[1]) when 'check' - $app.sync + app.sync + when 'watch' + app.watch else print_help end @@ -25,10 +33,12 @@ def print_help end def login(name) + app = Tootify.new + if name =~ /\A[^@]+@[^@]+\z/ - $app.login_mastodon(name) + app.login_mastodon(name) elsif name =~ /\A@[^@]+\z/ - $app.login_bluesky(name) + app.login_bluesky(name) elsif name.nil? print_help else