Skip to content

Instantly share code, notes, and snippets.

@Jach
Last active August 28, 2023 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jach/41082f105f5779531e041a6d3afb21db to your computer and use it in GitHub Desktop.
Save Jach/41082f105f5779531e041a6d3afb21db to your computer and use it in GitHub Desktop.
Quick and dirty webdriver script to run at whatever cadence and get notifications that Coyo (or some other youtube channel) wrote something new in the Community tab, because Youtube's native notifications suck
; before running, run java -jar selenium-server-4.1.2.jar standalone
(defpackage #:coyo-yt-posts
(:use #:cl))
(in-package :coyo-yt-posts)
(ql:quickload :cl-webdriver-client)
(ql:quickload :dexador)
(use-package :webdriver-client)
(defvar community-url "https://www.youtube.com/@Coyote_KemoV/community")
(defvar posts)
(defvar post-contents)
(defvar last-post-file "~/projects/snippets/coyo_yt_posts--last-post")
(defvar last-post-content)
(defvar latest)
(defun latest-content (post-contents)
(third post-contents))
(loop while t do
; headless mode required some effort to trace, don't trust docs
(start-interactive-session (make-capabilities :always-match
'((browser-name . "firefox")
("moz:firefoxOptions" . (("args" . #("-headless"))) )
)))
;(webdriver::http-post-value (webdriver::session-path webdriver::*session* "/window/minimize"))
; minimize call is useful if can't do headless for some reason
(setf (url) community-url)
(sleep 10)
(setf posts (find-elements "#content"))
(setf post-contents (mapcar #'element-text posts))
(setf last-post-content (uiop:read-file-string last-post-file))
(setf latest (latest-content post-contents))
(unless (or (equal last-post-content latest) (null latest) (equal "NIL" (string latest)) (equal "" (string latest)))
(format t "New post~%")
; Added POST to public PHP service
;(dex:post "https://www.thejach.com/services/yt_post_notification_subscribe.php" :content
; `(("notify" . "true")
; ("content" . ,latest)
; ("secret" . "1234")))
(handler-case
(uiop:run-program (list "/usr/bin/notify-send" (format nil "New Coyo Youtube Community Post ~a" community-url)))
(uiop/run-program:subprocess-error () nil))
(with-open-file (s last-post-file :direction :output :if-exists :supersede)
(format s "~a" (latest-content post-contents))))
(stop-interactive-session)
(format t ".")
(force-output)
(sleep 300))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment