-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet_client.rb
53 lines (46 loc) · 1.4 KB
/
tweet_client.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby
require 'bundler/setup'
require 'twitter'
require 'httparty'
require 'imgkit'
require_relative 'utils'
def run(subject:, rank:)
# initiates twitter client as @client
init_client
date = (Date.today - 1).to_s
response =
HTTParty.get("https://tophuntsdaily.herokuapp.com/charts/#{date}/data")
entry_data = JSON.parse(response.body)
post = entry_data['posts'].find { |p| p['rank'] == rank }
rank = post['rank']
hunter = post['hunter']
makers = post['makers']
url = post['url']
image_kit = IMGKit.new(
"https://tophuntsdaily.herokuapp.com/charts/#{date}?rank=#{rank}",
zoom: 2, width: 2048, height: 1024
)
img = image_kit.to_file("rank_#{rank}_img.jpg")
case subject
when 'summary'
# send summary tweet
@client.update_with_media(summary_text(entry_data['makers'], url), img)
# add makers and hunters to respective twitter lists
add_list_members(hunters: entry_data['hunters'],
makers: entry_data['makers'])
when 'hunter'
# hunter tweet
if hunter.length > 0
@client.update_with_media(hunter_text(hunter, rank, url), img)
end
when 'makers'
# makers tweet
if makers.any?
@client.update_with_media(makers_text(makers, rank, url), img)
end
end
end
if $0 == __FILE__
raise ArgumentError, "Usage: #{$0} subject rank" unless ARGV.length > 0
run(subject: ARGV[0], rank: (ARGV[1] || 1).to_i)
end