~drewr/freenyt

67e1a96ea3935dde15556bb692f38d12fd46b994 — Drew Raines a month ago main
Init
7 files changed, 81 insertions(+), 0 deletions(-)

A .gitignore
A CHANGELOG.md
A LICENSE
A README.md
A project.clj
A src/freenyt/core.clj
A test/freenyt/core_test.clj
A  => .gitignore +13 -0
@@ 1,13 @@
/target
/classes
/checkouts
profiles.clj
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
/.prepl-port
.hgignore
.hg/

A  => CHANGELOG.md +0 -0
A  => LICENSE +8 -0
@@ 1,8 @@
Copyright 2022 Andrew A. Raines

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


A  => README.md +15 -0
@@ 1,15 @@
# freenyt

If you have an NYT gift code, this automate the steps of filling it in.

## Usage

```
nix-shell \
  -p leiningen \
  --run "NYT_CAMPAIGN=<CAMPAIGN> \
         NYT_GIFTCODE=<SECRET> \
         NYT_USER=bob@gmail.com \
         NYT_PASS=bobspass \
         lein run"
```

A  => project.clj +7 -0
@@ 1,7 @@
(defproject freenyt "1.0.0"
  :description "Clicky click NYT"
  :license {:name "MIT"}
  :dependencies [[org.clojure/clojure "1.10.3"]
                 [etaoin/etaoin "0.4.6"]]
  :repl-options {:init-ns freenyt.core}
  :main freenyt.core)

A  => src/freenyt/core.clj +31 -0
@@ 1,31 @@
(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="
                  (System/getenv "NYT_CAMPAIGN")
                  "&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 6)

    (println (eta/get-url driver))

    (try
      (eta/quit driver)
      (catch Exception _))))

A  => test/freenyt/core_test.clj +7 -0
@@ 1,7 @@
(ns freenyt.core-test
  (:require [clojure.test :refer :all]
            [freenyt.core :refer :all]))

(deftest a-test
  (testing "FIXME, I fail."
    (is (= 0 1))))