Class: Twitter2mastodon::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/twitter2mastodon.rb

Instance Method Summary collapse

Instance Method Details

#get_last_tweetObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/twitter2mastodon.rb', line 18

def get_last_tweet
  message_count = 0
  return unless options[:configfile]

  # Configure different client
  configuration = Twitter2Mastodon::Configuration.new(options[:configfile])

  puts configuration.inspect if options[:ultraverbose]

  twitter = configuration.twitter_client
  mastodon = configuration.mastodon_client
  @store = Twitter2Mastodon::Store.new

  users = if options[:user]
            [options[:user]]
          else
            configuration.users
          end

  users.each do |user|
    # get last tweet and stores it
    last_twitt = twitter.user_timeline(user).reject(&:retweet?).reject(&:user_mentions?).first
    last_twitt = @store.add_to_store(Twitter2Mastodon::Status.new(last_twitt))

    # publish status
    if last_twitt
      mastodon.create_status(last_twitt.status)
      message_count += 1
      puts "Succefully published #{last_twitt.message}" if options[:ultraverbose]
    else
      puts "No new status has been published" if options[:ultraverbose]
    end
  end

  puts @store.store if options[:ultraverbose]
  return unless options[:verbose]

  if message_count
    puts "Succefully published #{message_count} status"
  else
    puts "No status published as expected"
  end
end