-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnarou.rb
More file actions
47 lines (43 loc) · 929 Bytes
/
narou.rb
File metadata and controls
47 lines (43 loc) · 929 Bytes
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
require 'sinatra'
require 'json'
require 'net/http'
def req(uri)
return JSON.parse(
Net::HTTP.get(uri)
)
end
def get_data(fin,r18)
baseurl = "http://api.syosetu.com/novelapi/api/?out=json"
r18_url = "http://api.syosetu.com/novel18api/api/?out=json"
params ||= ""
res ||= []
ncodes = (1..100).map{
"n#{[*0..9999].sample.to_s.rjust(4,'0')}#{[*"a".."zz"].sample}"
}.join("-")
if fin
params += "&stop=1"
end
res = req(URI.parse(baseurl + "&ncode=#{ncodes}" + params)).drop(1)
if r18
res += req(URI.parse(r18_url + "&ncode=#{ncodes}" + params)).drop(1)
end
return res.sample
end
get '/' do
@checked ||= {}
if params[:stop] == "true"
fin = true
@checked[:stop] = true
end
if params[:r18] == "true"
r18 = true
@checked[:r18] = true
end
fin ||= false
r18 ||= false
@data = get_data(fin=fin, r18=r18)
if @data.nil?
redirect "/"
end
erb :index
end