4 Commits
v2.0 ... 2.1

Author SHA1 Message Date
702a90e864 #3 show http error for playing cmd
Some checks failed
Compile and test using leiningen / Run tests (push) Has been cancelled
2026-02-24 00:36:04 +01:00
c8ce6fea5a #3 check if there is a valid key before get matches
Some checks failed
Compile and test using leiningen / Run tests (push) Has been cancelled
2026-02-24 00:29:08 +01:00
e85bc24e38 Merge pull request '#9 post filter dates' (#10) from 2.0.1 into main
Some checks failed
Compile and test using leiningen / Run tests (push) Has been cancelled
Reviewed-on: #10
2026-02-24 00:10:29 +01:00
94ae848e52 #9 post filter dates
Some checks failed
Compile and test using leiningen / Run tests (push) Has been cancelled
2026-02-24 00:00:31 +01:00
3 changed files with 72 additions and 33 deletions

View File

@@ -17,6 +17,7 @@
(pp/pprint params) (pp/pprint params)
(println "Positional args:" (s/join "," (:lambdaisland.cli/argv params)))) (println "Positional args:" (s/join "," (:lambdaisland.cli/argv params))))
(defn cmd-check-playing (defn cmd-check-playing
"Check if the player is playing right now." "Check if the player is playing right now."
[player-name player-tag & {:keys [lol tft template continuous every-seconds max header] [player-name player-tag & {:keys [lol tft template continuous every-seconds max header]
@@ -52,6 +53,8 @@
(cmd-check-playing "Walid Georgey" "EUW") ;; This kills the REPL (cmd-check-playing "Walid Georgey" "EUW") ;; This kills the REPL
(cmd-check-playing "Walid Georgey" "EUW" :continuous true :max 2) ;; Infinite loop if max is nil (cmd-check-playing "Walid Georgey" "EUW" :continuous true :max 2) ;; Infinite loop if max is nil
) )
(defn print-table (defn print-table
[matches-data] [matches-data]
(let [no-participants (map #(dissoc % :participants) matches-data) (let [no-participants (map #(dissoc % :participants) matches-data)
@@ -132,37 +135,6 @@
:winner false}] :winner false}]
":")) ":"))
(defn add-calculated-data
[puuid match-data]
(-> match-data
(assoc :winner (player-won? puuid match-data))
(assoc :champion (:champion (filter-by-player puuid match-data)))
(assoc :placement (:placement (filter-by-player puuid match-data)))
))
(defn get-matches
[player-name player-tag & {:keys [lol tft since until max]
:or {lol true
tft true}
:as params}]
(let [call-params (cond-> {}
max (assoc :count max)
since (assoc :startTime (/ (process-time-literal since) 1000))
until (assoc :endTime (/ (process-time-literal until) 1000)))
lol-puuid (get-lol-puuid player-name player-tag)
tft-puuid (get-tft-puuid player-name player-tag)]
(when @debug (println "Params") (pp/pprint call-params))
(cond-> []
lol (concat (map #(add-calculated-data lol-puuid (get-lol-match-data %))
(get-lol-matches lol-puuid call-params)))
tft (concat (map #(add-calculated-data tft-puuid (get-tft-match-data %))
(get-tft-matches tft-puuid call-params))))))
(comment
(reset! debug true)
(get-matches "Walid Georgey" "EUW" :max 3))
(defn cmd-show-matches (defn cmd-show-matches
"Show basic info about matches played by player" "Show basic info about matches played by player"

View File

@@ -527,7 +527,7 @@
(comment (comment
(set-riot-api-key :RIOT_DEV_KEY "RGAPI-bbbed5c8-d4d7-4de4-a7e7-b8366afee5a4") (set-riot-api-key :RIOT_DEV_KEY "RGAPI-85aa58ae-ab2a-4092-823b-f9ff6e346916")
(deref (:RIOT_DEV_KEY RIOT-KEYS)) (deref (:RIOT_DEV_KEY RIOT-KEYS))
(call-riot-api :lol-account-by-riot-id :path-params {:player-name "Walid Georgey" (call-riot-api :lol-account-by-riot-id :path-params {:player-name "Walid Georgey"

View File

@@ -2,6 +2,7 @@
(:require [rcorral.api.core :refer :all] (:require [rcorral.api.core :refer :all]
[rcorral.date-util :refer :all] [rcorral.date-util :refer :all]
[riot.riot-api :refer :all] [riot.riot-api :refer :all]
[clojure.pprint :as pp]
[tick.core :as t]) [tick.core :as t])
(:import [java.util Date]) (:import [java.util Date])
(:gen-class)) (:gen-class))
@@ -62,12 +63,25 @@
(first (filter #(= (:puuid %) puuid) (:participants match-data)))) (first (filter #(= (:puuid %) puuid) (:participants match-data))))
(defn filter-by-start-timestamp
[ts match-data]
(when @debug (println "filter by start:" ts))
(filter #(< ts (:start %)) match-data))
(defn filter-by-end-timestamp
[ts match-data]
(when @debug (println "filter by end:" ts))
(filter #(> ts (:end %)) match-data))
(defn player-won? (defn player-won?
[puuid match-data] [puuid match-data]
(if (and puuid match-data) (if (and puuid match-data)
(:win (filter-by-player puuid match-data)) (:win (filter-by-player puuid match-data))
(do (println "Invalid puuid or match data") false))) (do (println "Invalid puuid or match data") false)))
(defn player-alive? (defn player-alive?
[puuid participants] [puuid participants]
(let [player-data (first (filter #(= (:puuid %) puuid) participants)) (let [player-data (first (filter #(= (:puuid %) puuid) participants))
@@ -168,6 +182,54 @@
1767819383643 1767819383643
) )
(defn filter-by-dates
"This is a workaround for a bug in the API"
[params match-data]
(if (some? match-data)
(cond->> match-data
(some? (:startTime params)) (filter-by-start-timestamp (* 1000 (:startTime params)))
(some? (:endTime params)) (filter-by-end-timestamp (* 1000 (:endTime params))))
match-data))
(defn add-calculated-data
[puuid match-data]
(-> match-data
(assoc :winner (player-won? puuid match-data))
(assoc :champion (:champion (filter-by-player puuid match-data)))
(assoc :placement (:placement (filter-by-player puuid match-data)))))
(defn get-matches
[player-name player-tag & {:keys [lol tft since until max]
:or {lol true
tft true}
:as params}]
(let [call-params (cond-> {}
max (assoc :count max)
since (assoc :startTime (/ (process-time-literal since) 1000))
until (assoc :endTime (/ (process-time-literal until) 1000)))
lol-puuid (get-lol-puuid player-name player-tag)
tft-puuid (get-tft-puuid player-name player-tag)]
(when @debug (println "get-matches Params") (pp/pprint call-params))
(cond-> []
(and lol (some? lol-puuid))
(concat (filter-by-dates
call-params (map #(add-calculated-data lol-puuid (get-lol-match-data %))
(get-lol-matches lol-puuid call-params))))
(and tft (some? tft-puuid))
(concat (filter-by-dates
call-params (map #(add-calculated-data tft-puuid (get-tft-match-data %))
(get-tft-matches tft-puuid call-params)))))))
(comment
(reset! debug true)
(get-matches "Walid Georgey" "EUW" :max 3 :tft false)
)
;; Check if it's playing ;; Check if it's playing
(defn is-playing-lol? (defn is-playing-lol?
@@ -182,7 +244,12 @@
(let [response (call-riot-api :tft-spectator (let [response (call-riot-api :tft-spectator
:path-params {:puuid puuid}) :path-params {:puuid puuid})
http-code (:http-code response)] http-code (:http-code response)]
(= 200 http-code))) (cond
(= 200 http-code) true
(= 404 http-code) false
:else (str "unknown, error " http-code))
))
(defn create-playing (defn create-playing