From 9c4854b2a720cca88750544030c457c4e31a6140 Mon Sep 17 00:00:00 2001 From: jdlugosz963 Date: Thu, 9 Nov 2023 12:11:45 +0100 Subject: Add yasa project tree. --- src/yasa/core.clj | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/yasa/settings.clj | 12 ++++++ 2 files changed, 127 insertions(+) create mode 100644 src/yasa/core.clj create mode 100644 src/yasa/settings.clj (limited to 'src') diff --git a/src/yasa/core.clj b/src/yasa/core.clj new file mode 100644 index 0000000..668197e --- /dev/null +++ b/src/yasa/core.clj @@ -0,0 +1,115 @@ +(ns yasa.core + (:require [etaoin.api :as e] + [etaoin.keys :as k] + [yasa.settings :as s])) + +(def driver (e/firefox)) + +(def addresses + {:school "https://liceum-internetowe.edu.pl/" + :cocpit "https://liceum-internetowe.edu.pl/my/"}) + +(def lessons + {:polski "https://liceum-internetowe.edu.pl/course/view.php?id=163" + :matematyka "https://liceum-internetowe.edu.pl/course/view.php?id=171" + :angielski-p "https://liceum-internetowe.edu.pl/course/view.php?id=164" + :angielski-r "https://liceum-internetowe.edu.pl/course/view.php?id=165" + :wos "https://liceum-internetowe.edu.pl/course/view.php?id=227"}) + +(defn login [] + (e/go driver (:school addresses)) + + (e/wait 3) + + (e/click driver [{:class "login"} {:tag :a}]) + + (e/wait 3) + + (e/fill driver [{:id "username"}] (:username s/settings)) + (e/wait 1) + (e/fill driver [{:id "password"}] (:password s/settings)) + (e/wait 1) + + (e/click driver [{:id "loginbtn"}])) + +(defn logout [] + (e/go driver (:cocpit addresses)) + + (e/wait 3) + + (e/click driver [{:id "action-menu-toggle-1"}]) + + (e/wait 1) + + (e/click driver [{:id "actionmenuaction-6"}])) + +(defn lesson-info-todo [] + (let [sections (e/children driver (e/query driver [{:class "topics"}]) {:tag :li :fn/has-class "section"}) + activities (map #(e/children driver % {:tag :li :fn/has-class "activity"}) sections) + activities-todo-buttons (map (fn [a] + (map #(let [button (e/children driver % {:tag :button})] + (when (not (empty? button)) + (first button))) + a)) + activities) + activities-todo (clojure.walk/postwalk (fn [a] + (if (string? a) + (as-> a a + (e/child driver a {:tag :img}) + (e/get-element-property-el driver a :src) + (clojure.string/ends-with? a "-n")) + a)) + activities-todo-buttons) + + activities-todo-buttons (flatten activities-todo-buttons) + activities-todo (flatten activities-todo) + + activities-todo-buttons (->> (map #(when %1 %2) + activities-todo + activities-todo-buttons) + (remove nil?)) + + activities-lesson-links-todo (->> (map #(when %2 + (as-> %1 a + (e/child driver a {:tag :a :class "aalink"}) + (e/get-element-property-el driver a :href))) + (flatten activities) + activities-todo) + (remove nil?))] + + {:lesson-links activities-lesson-links-todo + :check-button activities-todo-buttons})) + + +(defn check-first-button [] + (let [lesson-info (lesson-info-todo)] + (e/click-el driver (first (:check-button lesson-info))))) + +(defn enter-first-lesson [] + (let [lesson-info (lesson-info-todo)] + (e/go driver (first (:lesson-links lesson-info))))) + + + +(defn do-lesson [lesson] + (let [random-wait (fn [x] (fn [] (e/wait (+ x (* 4 (rand)))))) + random-short-wait (random-wait 2)] + (login) + (random-short-wait) + (e/go driver (lesson lessons)) + (random-short-wait) + (check-first-button) + (random-short-wait) + (enter-first-lesson) + (random-short-wait) + (logout) + true)) + + +(comment + (e/go driver (:polski lessons)) + + (login) + (logout) + (do-lesson :matematyka) + ) diff --git a/src/yasa/settings.clj b/src/yasa/settings.clj new file mode 100644 index 0000000..d936515 --- /dev/null +++ b/src/yasa/settings.clj @@ -0,0 +1,12 @@ +(ns yasa.settings) + +(def settings + {:username (or nil ;; ENTER YOUR USERNAME + (or (System/getenv "YASA-USERNAME") + (lazy-seq + (throw (Exception. "No username provided!"))))) + :password (or nil ;; ENTER YOUR PASSWORD + (or (System/getenv "YASA-PASSWORD") + (lazy-seq + (throw (Exception. "No password provided!")))))}) + -- cgit v1.2.3