Cookbook 04: Sign in once. Stay signed in.
Sign in once, stop the computer, and come back later: the same computer is still signed in.
By The Pine Computer team
Two programs, two hours apart, on one computer.
The first signs in to Amazon. When Amazon texts a code, the run asks for it in the terminal and the person types it in. Then the program stops the computer.
Two hours later, the second program brings the same computer back. Amazon already greets it by name, and the item goes into the cart without signing in again. Sign-ins are saved per computer.
# signin.rb
computer = pine.create_computer
a = computer.create_session(browser: true)
a.agent.run("Sign in to amazon.com as $EMAIL. If it asks for a code, ask me.",
secrets: { "EMAIL" => ENV["AMAZON_EMAIL"] })
follow(a)
gets # press Enter to stop
puts "Stopping the computer…"
computer.stop# buy.rb
id, saved = load_computer
computer = pine.attach_computer(id, **saved) # the same computer, back
session = computer.create_session(browser: true)
session.agent.run("Add Apple's wired EarPods with a USB-C plug to the cart on
amazon.com.")
follow(session)
gets # press Enter to stop
puts "Stopping the computer…"
computer.stopfollow prints the run’s notes and passes the person’s answers back. load_computer reads what the first program kept to bring the computer back. More in the docs.