Skip to content

Commit

Permalink
Add colorized output, toggle verbosity
Browse files Browse the repository at this point in the history
Closes #11
  • Loading branch information
Daniils Petrovs committed Aug 16, 2022
1 parent 95e935c commit ddc016a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 27 deletions.
4 changes: 3 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject atoss-cli "0.3.0-SNAPSHOT"
(defproject atoss-cli "0.3.1-SNAPSHOT"
:description "A CLI tool for interacting with ATOSS time sheets"
:url "https://github.com/platogo/atoss-cli"
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
Expand All @@ -8,6 +8,8 @@
:dependencies [[org.clojure/clojure "1.11.1"]
[org.clojure/tools.cli "1.0.206"]
[etaoin "0.4.6"]
[com.github.pmonks/spinner "2.0.120"]
[clojure-term-colors "0.1.0"]
[com.github.clj-easy/graal-build-time "0.1.4"]]
:target-path "target/%s"
:jar-name "atoss-cli.jar"
Expand Down
31 changes: 21 additions & 10 deletions src/atoss_cli/atoss.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
[etaoin.keys :as keys])
(:gen-class))

(comment "Various ATOSS web interface selectors.")

(def valid-day-codes #{"du" "nu" "rt" "sd" "ta" "th" "tp" "ts" "wh" "" nil})

(def atoss-url "https://ases.novomatic.com/SES/html")
Expand Down Expand Up @@ -84,8 +86,9 @@

(defn login
"Login into ATOSS dashboard using provided credentials."
[driver {user :username pass :password}]
(println "Logging into ATOSS with user: " (subs user 3) "***")
[driver {user :username pass :password} {verbosity :verbosity}]
(when (> verbosity 0)
(println "Logging into ATOSS with user: " (subs user 3) "***"))
(doto driver
(api/go atoss-url)
(api/switch-frame :applicationIframe)
Expand All @@ -95,11 +98,15 @@
(api/fill-active keys/tab)
(api/fill-active pass)
(api/fill-active keys/enter))
(println "Logged in"))

(when (> verbosity 0)
(println "Logged in")))

(defn logout
[driver]
(println "Logging out of ATOSS")
[driver {verbosity :verbosity}]
(when (> verbosity 0)
(println "Logging out of ATOSS"))

(doto driver
(api/click nav-user-btn)
(api/click logout-btn)))
Expand Down Expand Up @@ -145,17 +152,21 @@

(defn create-time-pair-entry
"Create a new time entry as a combination of day code and a time pair for a given day."
[driver {day-code :day-code start :start-time end :end-time}]
[driver {day-code :day-code
start :start-time
end :end-time
verbosity :verbosity}]
(when (> verbosity 0)
(println (if (= day-code " ")
"No day code provided"
(str "Day code: " day-code))))

(println (if (nil? day-code)
"No day code provided"
(str "Day code: " day-code)))
(api/click driver date-input)
(dotimes [_i 4]
(api/fill-active driver keys/tab))
(api/wait driver 3) ;; Do not touch waiters - if it is any less, the UI will not have enough time to update
(doto driver
(api/fill-active (if (nil? day-code) " " day-code))
(api/fill-active day-code)
(api/fill-active keys/tab)
(api/wait 2)
(api/fill-active start)
Expand Down
20 changes: 14 additions & 6 deletions src/atoss_cli/cli.clj
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
(ns atoss-cli.cli
(:require
[clojure.java.io :as io]
[atoss-cli.atoss :refer [valid-day-codes]])
[atoss-cli.atoss :refer [valid-day-codes]]
[clojure.term.colors :refer [bold]])
(:import (java.text SimpleDateFormat)
(java.util Date Properties))
(:gen-class))

(comment
"This handles all CLI related parts of the ATOSS CLI, such as printing, parsing arguments etc.")

(def desc "ATOSS CLI by Platogo Interactive Entertainment Gmbh.
Work seamlessly with ATOSS time sheets.")

(def help-header "
\033[1;37mUSAGE\u001b[0m
(def help-header
(str
(bold "USAGE") "
atoss-cli <command> [args]
\033[1;37mCOMMANDS\u001b[0m
log: Log time pair for today or a specific date")
"
(bold "COMMANDS")
"
log: Log time pair for today or a specific date"))

(defn today-date
"Get today's date."
Expand All @@ -37,7 +44,7 @@ Work seamlessly with ATOSS time sheets.")
[["-d" "--date DATE" "Date in the format DD.MM.YYYY"
:default (today-date)] ;; FIXME: Add validation
["-c" "--day-code CODE" "Valid ATOSS day code (e.g. wh for WFH) can also be left blank."
:default nil
:default " "
:validate [#(contains? valid-day-codes %) "Must be a valid ATOSS time code."]]
["-s" "--start-time TIME" "Work start time in the format HH:MM"
:default "9:00"]
Expand All @@ -58,6 +65,7 @@ Work seamlessly with ATOSS time sheets.")
[args-summary]
(print desc)
(newline)
(newline)
(print help-header)
(newline)
(newline)
Expand Down
22 changes: 12 additions & 10 deletions src/atoss_cli/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,40 @@
"Entrypoint module for the ATOSS CLI."
(:require
[clojure.tools.cli :refer [parse-opts]]
[clojure.term.colors :refer [bold green red]]
[atoss-cli.atoss :as atoss]
[atoss-cli.cli :as cli])
(:import (java.util Collection))
(:gen-class))

(defn log-time
"Log a time pair for a given day."
"Log a time pair for a given date."
[{opts :options}]
(let [driver (atoss/setup-driver)
creds (atoss/creds-from-dotfile)
{date :date} opts]
(try
(doto driver
(atoss/login creds)
(atoss/login creds opts)
(atoss/nav-to-time-correction)
(atoss/set-date date)
(atoss/create-time-pair-entry opts)
(atoss/logout)
(atoss/logout opts)
(atoss/end))
(println "Logged time")
(catch Exception e (println (.getMessage e))))))
(println (green "Logged time for date: " date))
(catch Exception e (println (red (.getMessage e)))))))

;; FIXME: very brittle so disabled for now
(defn show-month-overview
"Display the current month overview in the terminal."
[]
[{opts :options}]
(let [driver (atoss/setup-driver)
creds (atoss/creds-from-dotfile)]
(doto driver
(atoss/login creds)
(atoss/login creds opts)
(atoss/nav-to-month-overview))
(let [days (atoss/parse-month-table-rows driver)]
(println "\033[1;37mMonth overview:\u001b[0m")
(println (bold "Month overview:"))
(newline)
(doseq [day days]
(-> day
Expand All @@ -45,10 +46,11 @@
(let [{^Collection arguments :arguments
summary :summary,
options :options,
:as opts} (parse-opts args cli/options)]
:as opts} (parse-opts args cli/options)
command (first arguments)]
(cond
(options :version) (cli/print-project-ver)
(options :help) (cli/print-help summary)
(= (first arguments) "log") (log-time opts)
(= command "log") (log-time opts)
:else (cli/print-help summary))
(flush)))

0 comments on commit ddc016a

Please sign in to comment.