diff options
-rw-r--r-- | .gitignore | 13 | ||||
-rw-r--r-- | project.clj | 8 | ||||
-rw-r--r-- | src/yasa/core.clj | 115 | ||||
-rw-r--r-- | src/yasa/settings.clj | 12 |
4 files changed, 148 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d956ab0 --- /dev/null +++ b/.gitignore | |||
@@ -0,0 +1,13 @@ | |||
1 | /target | ||
2 | /classes | ||
3 | /checkouts | ||
4 | profiles.clj | ||
5 | pom.xml | ||
6 | pom.xml.asc | ||
7 | *.jar | ||
8 | *.class | ||
9 | /.lein-* | ||
10 | /.nrepl-port | ||
11 | /.prepl-port | ||
12 | .hgignore | ||
13 | .hg/ | ||
diff --git a/project.clj b/project.clj new file mode 100644 index 0000000..692c4fd --- /dev/null +++ b/project.clj | |||
@@ -0,0 +1,8 @@ | |||
1 | (defproject yasa "0.1.0-SNAPSHOT" | ||
2 | :description "Yasa - Yet another school automation - yet another, because i forgot to backup previous version :(" | ||
3 | :url "https://jdlugosz.com" | ||
4 | ;; :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" | ||
5 | ;; :url "https://www.eclipse.org/legal/epl-2.0/"} | ||
6 | :dependencies [[org.clojure/clojure "1.11.1"] | ||
7 | [etaoin "1.0.40"]] | ||
8 | :repl-options {:init-ns yasa.core}) | ||
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 | |||