Skip to content

Instantly share code, notes, and snippets.

@drewr
Created July 9, 2022 21:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewr/c3bfced68888b65bb1d21f863b9f4d91 to your computer and use it in GitHub Desktop.
Save drewr/c3bfced68888b65bb1d21f863b9f4d91 to your computer and use it in GitHub Desktop.
Redeem NYT gift code
(ns freenyt.core
(:gen-class)
(:require [etaoin.api :as eta]
[etaoin.keys :as k]))
;;(def driver (eta/firefox-headless))
(defn -main [& args]
(let [driver (eta/safari)]
(eta/go
driver (str "https://www.nytimes.com/subscription"
"/redeem?campaignId=8UR8F&gift_code="
(System/getenv "NYT_GIFTCODE")))
(eta/wait-visible driver {:tag :input :value :Redeem})
(eta/click driver [{:tag :input :class :giftRedeem__submitButton}])
(eta/wait-visible driver {:tag :input :name :email})
(eta/fill driver {:tag :input :name :email} (System/getenv "NYT_USER"))
(eta/click driver [{:tag :button :type :submit}])
(eta/wait-visible driver {:tag :input :name :password})
(eta/fill driver {:tag :input :name :password} (System/getenv "NYT_PASS"))
(eta/click driver [{:tag :button :type :submit}])
(eta/wait 10)
(println (eta/get-url driver))
(try
(eta/quit driver)
(catch Exception _))))
(defproject freenyt "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
:url "https://www.eclipse.org/legal/epl-2.0/"}
:dependencies [[org.clojure/clojure "1.10.3"]
[etaoin/etaoin "0.4.6"]
[clojure.java-time/clojure.java-time "0.3.3"]]
:repl-options {:init-ns freenyt.core}
:main freenyt.core)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment