-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
47 lines (35 loc) · 935 Bytes
/
main.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
# frozen_string_literal: true
require 'json'
require 'net/http'
require_relative 'job'
require_relative 'db'
require_relative 'slack'
require_relative 'tweet'
class BoardSyndicator
attr_accessor :db, :channels, :dry_run
def initialize
@db = DB.new('./jobs.sqlite')
@channels = [Slack.new, Tweet.new]
@dry_run = true
@dry_run = false if ENV["SYN_ENV"] == "production"
end
def scan
jobs = JSON.parse(Net::HTTP.get(URI('https://jobs.tampa.dev/jobs.json')))
new_posts = []
jobs["data"].each do |jd|
job = Job.new(jd)
unless dry_run
next if @db.job_exist?(job)
@db.add_job(job)
end
puts "Syndicating: #{job.title} \##{job.id}"
new_posts.push(job)
end
@channels.each do |chan|
chan.syndicate(new_posts, dry_run: @dry_run)
puts "Channel exec: #{chan.class.name}"
end
end
end
boardsyn = BoardSyndicator.new
boardsyn.scan