/
scraping.rb
41 lines (37 loc) · 865 Bytes
/
scraping.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
require 'net/http'
require 'time'
require 'pp'
module Hibiki
class Program < Struct.new(:access_id, :episode_id, :title, :episode_name, :cast)
end
class Scraping
def main
get_list.reject do |program|
program.episode_id == nil
end
end
def get_list
programs = []
parsed = nil
page = 1
begin
uri = URI("https://vcms-api.hibiki-radio.jp/api/v1//programs?limit=8&page=#{page}")
res = Net::HTTP.get(uri)
raws = JSON.parse(res)
programs += raws.map{|raw| parse_program(raw) }
sleep 1
page += 1
end while raws.size == 8
programs
end
def parse_program(raw)
Program.new(
raw['access_id'],
raw['latest_episode_id'],
raw['name'],
raw['latest_episode_name'],
raw['cast'],
)
end
end
end