incomplete

This commit is contained in:
2023-08-04 15:48:48 +03:00
parent 7fbb71a4c1
commit fdcba863c2
13 changed files with 239 additions and 43 deletions

3
server/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
bin/
lib/
cache/

0
server/README.md Normal file
View File

22
server/shard.lock Normal file
View File

@@ -0,0 +1,22 @@
version: 2.0
shards:
backtracer:
git: https://github.com/sija/backtracer.cr.git
version: 1.2.2
exception_page:
git: https://github.com/crystal-loot/exception_page.git
version: 0.3.1
kemal:
git: https://github.com/kemalcr/kemal.git
version: 1.4.0
lexbor:
git: https://github.com/kostya/lexbor.git
version: 3.1.2
radix:
git: https://github.com/luislavena/radix.git
version: 0.4.1

24
server/shard.yml Normal file
View File

@@ -0,0 +1,24 @@
name: api_server
version: 0.1.0
authors:
- Alexander Popov <iiiypuk@fastmail.fm>
# description: |
# Short description of server
targets:
api:
main: src/api.cr
dependencies:
kemal:
github: kemalcr/kemal
lexbor:
github: kostya/lexbor
# development_dependencies:
# webmock:
# github: manastech/webmock.cr
license: WTFPL

11
server/src/api.cr Normal file
View File

@@ -0,0 +1,11 @@
require "kemal"
require "./modules/*"
APP = {version: "1.0.0"}
get "/" do
render "#{__DIR__}/layouts/index.ecr"
end
Kemal.config.env = "development"
Kemal.run

View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>api</title>
</head>
<body>
<main>
<p>:-p</p>
</main>
</body>
</html>

View File

@@ -0,0 +1,16 @@
require "json"
get "/info" do |env|
version = APP["version"]
if env.params.query["json"]?
env.response.content_type = "application/json"
data = {version: version}.to_json
data
else
env.response.content_type = "text/plain"
"Vesrion: #{version}"
end
end

View File

@@ -0,0 +1,54 @@
require "http/client"
require "json"
require "lexbor"
# ...
#
# Output:
# ```
# ...
# ```
get "/api/v1.0/rev2_monsters" do |env|
url = "https://game.capcom.com/residentevil/en/onlineevent-4_1108.html"
cache_time = File.read("./cache/rev2/time.txt").to_i
timestamp = Time.local.to_unix
if timestamp > cache_time + 3600 # 1 hour
response = HTTP::Client.get url
time_remaining = ""
enemies = [] of String
Lexbor::Parser.new(response.body).nodes(:dl).each do |node|
if node["class"]?
if node["class"] == "timer big status_1 hard windows"
time_remaining = node.inner_text.split[2]
end
if node["class"] == "status hard windows status_1"
enemies = node.inner_text.split
enemies.delete_at(0, 2)
end
end
end
enemies.each_with_index do |ememy, i|
hp = /\d+%/.match(ememy)
enemies[i] = enemies[i].gsub(/\d+%/, " \\0")
end
response = {time_remaining: time_remaining, enemies: enemies}.to_json
File.write("./cache/rev2/time.txt", timestamp)
File.write("./cache/rev2/data.json", response)
else
response = File.read("./cache/rev2/data.json")
end
env.response.content_type = "application/json"
env.response.headers.add("Access-Control-Allow-Origin", "*")
response
end