Cookbook 03: Browser, shell and files
The same computer has a shell and files: it exports reports from a portal, checks them in its shell and hands back a zip.
By The Pine Computer team
The browser is one part of the computer. The same machine has a shell and a filesystem, and this program uses all three.
It writes a list of reports and a check script onto the computer. It asks for every report on the list to be exported from an HR portal, with the sign-in passed as secrets so it never appears in the instructions. Then it runs the check in the computer’s shell and downloads everything the run produced as one zip.
computer = pine.create_computer
session = computer.create_session(browser: true)
session.create_tab(url: ENV["HR_URL"])
session.write_file("reports.csv", File.read("reports.csv"))
session.write_file("check.sh", File.read("check.sh"))
session.agent.run("Sign in and export every report listed in reports.csv as CSV. " \
"The sign-in details are in $SESSION_SECRETS.",
secrets: { "HR_USER" => ENV["HR_USER"], "HR_PASSWORD" => ENV["HR_PASSWORD"] })
session.agent.events { |e| break if e.terminal? }
puts session.exec("sh attachments/check.sh").stdout
File.binwrite("reports.zip", session.download_artifacts_zip)
puts "reports.zip is on this Mac"
gets
computer.stopMore in the docs.