Skip to content

Instantly share code, notes, and snippets.

@patatepartie
Created August 26, 2023 07:16
Show Gist options
  • Save patatepartie/4fe7bfb9606508fa6ab1b08b80412411 to your computer and use it in GitHub Desktop.
Save patatepartie/4fe7bfb9606508fa6ab1b08b80412411 to your computer and use it in GitHub Desktop.
Using Chessputzer's online instance as an API to generate a FEN from an image of a chessboard
require 'faraday'
conn = Faraday.new('https://www.ocf.berkeley.edu') do |f|
f.request :multipart
f.request :url_encoded
f.adapter :net_http # This is what ended up making it work
end
res = diagram.open do |file|
payload = { :file => Faraday::UploadIO.new(file, 'image/png') }
conn.post('/~abhishek/putz/run.fcgi/upload', payload)
end
html_res = Nokogiri::HTML(res.body)
fen = html_res.css("p.boxed").first.text.split("\n").first.split(":").second.strip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment