summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorjdlugosz963 <jdlugosz963@gmail.com>2023-11-09 12:11:45 +0100
committerjdlugosz963 <jdlugosz963@gmail.com>2023-11-09 12:11:45 +0100
commit9c4854b2a720cca88750544030c457c4e31a6140 (patch)
tree4a05866aa3b546a65fcf741bd6b460031e96d90e /src
downloadyasa-9c4854b2a720cca88750544030c457c4e31a6140.tar.gz
yasa-9c4854b2a720cca88750544030c457c4e31a6140.zip
Add yasa project tree.
Diffstat (limited to 'src')
-rw-r--r--src/yasa/core.clj115
-rw-r--r--src/yasa/settings.clj12
2 files changed, 127 insertions, 0 deletions
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 @@
1(ns yasa.core
2 (:require [etaoin.api :as e]
3 [etaoin.keys :as k]
4 [yasa.settings :as s]))
5
6(def driver (e/firefox))
7
8(def addresses
9 {:school "https://liceum-internetowe.edu.pl/"
10 :cocpit "https://liceum-internetowe.edu.pl/my/"})
11
12(def lessons
13 {:polski "https://liceum-internetowe.edu.pl/course/view.php?id=163"
14 :matematyka "https://liceum-internetowe.edu.pl/course/view.php?id=171"
15 :angielski-p "https://liceum-internetowe.edu.pl/course/view.php?id=164"
16 :angielski-r "https://liceum-internetowe.edu.pl/course/view.php?id=165"
17 :wos "https://liceum-internetowe.edu.pl/course/view.php?id=227"})
18
19(defn login []
20 (e/go driver (:school addresses))
21
22 (e/wait 3)
23
24 (e/click driver [{:class "login"} {:tag :a}])
25
26 (e/wait 3)
27
28 (e/fill driver [{:id "username"}] (:username s/settings))
29 (e/wait 1)
30 (e/fill driver [{:id "password"}] (:password s/settings))
31 (e/wait 1)
32
33 (e/click driver [{:id "loginbtn"}]))
34
35(defn logout []
36 (e/go driver (:cocpit addresses))
37
38 (e/wait 3)
39
40 (e/click driver [{:id "action-menu-toggle-1"}])
41
42 (e/wait 1)
43
44 (e/click driver [{:id "actionmenuaction-6"}]))
45
46(defn lesson-info-todo []
47 (let [sections (e/children driver (e/query driver [{:class "topics"}]) {:tag :li :fn/has-class "section"})
48 activities (map #(e/children driver % {:tag :li :fn/has-class "activity"}) sections)
49 activities-todo-buttons (map (fn [a]
50 (map #(let [button (e/children driver % {:tag :button})]
51 (when (not (empty? button))
52 (first button)))
53 a))
54 activities)
55 activities-todo (clojure.walk/postwalk (fn [a]
56 (if (string? a)
57 (as-> a a
58 (e/child driver a {:tag :img})
59 (e/get-element-property-el driver a :src)
60 (clojure.string/ends-with? a "-n"))
61 a))
62 activities-todo-buttons)
63
64 activities-todo-buttons (flatten activities-todo-buttons)
65 activities-todo (flatten activities-todo)
66
67 activities-todo-buttons (->> (map #(when %1 %2)
68 activities-todo
69 activities-todo-buttons)
70 (remove nil?))
71
72 activities-lesson-links-todo (->> (map #(when %2
73 (as-> %1 a
74 (e/child driver a {:tag :a :class "aalink"})
75 (e/get-element-property-el driver a :href)))
76 (flatten activities)
77 activities-todo)
78 (remove nil?))]
79
80 {:lesson-links activities-lesson-links-todo
81 :check-button activities-todo-buttons}))
82
83
84(defn check-first-button []
85 (let [lesson-info (lesson-info-todo)]
86 (e/click-el driver (first (:check-button lesson-info)))))
87
88(defn enter-first-lesson []
89 (let [lesson-info (lesson-info-todo)]
90 (e/go driver (first (:lesson-links lesson-info)))))
91
92
93
94(defn do-lesson [lesson]
95 (let [random-wait (fn [x] (fn [] (e/wait (+ x (* 4 (rand))))))
96 random-short-wait (random-wait 2)]
97 (login)
98 (random-short-wait)
99 (e/go driver (lesson lessons))
100 (random-short-wait)
101 (check-first-button)
102 (random-short-wait)
103 (enter-first-lesson)
104 (random-short-wait)
105 (logout)
106 true))
107
108
109(comment
110 (e/go driver (:polski lessons))
111
112 (login)
113 (logout)
114 (do-lesson :matematyka)
115 )
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 @@
1(ns yasa.settings)
2
3(def settings
4 {:username (or nil ;; ENTER YOUR USERNAME
5 (or (System/getenv "YASA-USERNAME")
6 (lazy-seq
7 (throw (Exception. "No username provided!")))))
8 :password (or nil ;; ENTER YOUR PASSWORD
9 (or (System/getenv "YASA-PASSWORD")
10 (lazy-seq
11 (throw (Exception. "No password provided!")))))})
12