-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet.rb
executable file
·29 lines (23 loc) · 910 Bytes
/
tweet.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env ruby
require 'dotenv'
require 'twitter'
require 'redis'
require "./lib/authentic.rb"
require './lib/followers.rb'
require './lib/tweet_sender.rb'
Dotenv.load if ENV['TWITTER_CONSUMER_KEY'].nil?
twitter_client = Twitter::REST::Client.new do |config|
config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
config.access_token = ENV['TWITTER_ACCESS_TOKEN']
config.access_token_secret = ENV['TWITTER_ACCESS_SECRET']
end
redis_client = Redis.new(url: ENV['REDIS_URL'])
if Random.rand(10) < 1 # Tweet 1 time in 10
if Random.rand(100) < 10 # Tweet at a follower 10% of the time
follower = Followers.new(twitter_client, redis_client).get_follower
TweetSender.new(twitter_client).tweet follower unless follower.nil?
else
TweetSender.new(twitter_client).tweet Authentic.new(redis_client).get_job
end
end