-
Notifications
You must be signed in to change notification settings - Fork 0
/
newsappsjobs.rb
55 lines (44 loc) · 1.75 KB
/
newsappsjobs.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
require 'rubygems'
require 'bundler/setup'
Bundler.require(:default)
Bitly.use_api_version_3
class Twitterbot
attr_accessor :jobs, :twitter_config, :gdrive_session, :job_worksheet, :bitly
def initialize
@twitter_config = Psych.load_file('config/config.yml')
@gdrive_session = GoogleDrive.login(@twitter_config['g_drive_login'], @twitter_config['g_drive_app_pass'])
@job_worksheet = @gdrive_session.spreadsheet_by_key(@twitter_config['jobs_ws_key']).worksheets[0]
@bitly = Bitly.new(@twitter_config['bitly_user_name'], @twitter_config['bitly_api_key'])
@jobs = []
Twitter.configure do |config|
config.consumer_key = @twitter_config['consumer_key']
config.consumer_secret = @twitter_config['consumer_secret']
config.oauth_token = @twitter_config['oauth_token']
config.oauth_token_secret = @twitter_config['oauth_token_secret']
end
end
def shorten_link(link)
begin
shorter_link = @bitly.shorten(link).short_url
rescue => e
e
end
end
def short_time
Time.new.to_s.match(/\d\d\-\d\d\s\d\d:\d\d/).to_s
end
def make_jobs
@job_worksheet.rows.each do |row|
if row[2].match(/\d\/\d+\/201\d/)
unless shorten_link(row[0]).class.to_s == 'BitlyError'
@jobs << "#{row[1].strip.chomp}, #{row[5]}: #{row[4]} #{shorten_link(row[0])} #newapps #ddj #{short_time}"
else
@jobs << "#{row[1].strip.chomp}, #{row[5]}: #{row[4]} #{row[0]} #newapps #ddj #{short_time}"
end#unless
end#if
end
@jobs.sample
end#make_jobs
end
bot = Twitterbot.new
Twitter.update(bot.make_jobs)