Last active
March 16, 2019 13:30
-
-
Save kubek2k/320caf7e0e0fddffe542e5bd7a575929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
"exec" "clojure" "-Sdeps" "{:deps | |
{clj-http {:mvn/version \"3.9.1\"} | |
org.seleniumhq.selenium/htmlunit-driver {:mvn/version \"2.34.0\"}}}" "$0" "$@" | |
;; usage | |
;; update/install clojure: brew install clojure | |
;; make the file executable: chmod +x | |
;; fill in below config values | |
;; run the file whenever you want | |
(defn- required [env] | |
(let [v (System/getenv env)] | |
(if | |
(nil? v) | |
(do | |
(.println *err* (str env " env var not provided")) | |
(System/exit 1)) | |
v))) | |
;; config | |
(def cfg-holiday-app-user (required "HOLIDAY_APP_USER")) | |
(def cfg-holiday-app-pwd (required "HOLIDAY_APP_PASSWORD")) | |
(defn- toMonthString [month] | |
(if (< (int month) 9) | |
(str "0" month) | |
(str month))) | |
;; code | |
(import org.openqa.selenium.By) | |
(import org.openqa.selenium.htmlunit.HtmlUnitDriver) | |
(import org.openqa.selenium.support.ui.Select) | |
(import java.util.Date) | |
(def client (HtmlUnitDriver. true)) | |
(def now (Date.)) | |
(def day (nth *command-line-args* 0 (.getDate now))) | |
(def month (nth *command-line-args* 1 (+ 1 (.getMonth now)))) | |
(def year (nth *command-line-args* 2 (+ 1900 (.getYear now)))) | |
(println "Setting wfh for " day month year) | |
(.get client "https://r2p.stpinfra.com") | |
(-> (.findElement client (By/id "EDLOGIN")) (.sendKeys (into-array [cfg-holiday-app-user]))) | |
(-> (.findElement client (By/id "EDHASLO")) (.sendKeys (into-array [cfg-holiday-app-pwd]))) | |
(-> (.findElement client (By/id "OKBTN")) (.click)) | |
(-> (.findElement client (By/xpath "//a[@title='Miesięczna karta pracy']")) (.click)) | |
(-> (.findElement client (By/id "CBROK")) (Select.) (.selectByVisibleText (str year))) | |
(-> (.findElement client (By/id "CBMIES")) (Select.) (.selectByVisibleText (toMonthString month))) | |
(-> (.findElement client (By/id "CBDZIEN3")) (Select.) (.selectByVisibleText (str day))) | |
(-> (.findElement client (By/id "BTNNOWYWNIOSKI")) (.click)) | |
(-> (.findElement client (By/id "CMBRODZAJ")) (Select.) (.selectByVisibleText "Praca zdalna")) | |
(-> (.findElement client (By/id "OKBTNWNIOSKI")) (.click)) | |
(-> (.quit client)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment