Skip to content

Instantly share code, notes, and snippets.

@Jach
Created April 26, 2024 06:44
Show Gist options
  • Save Jach/8ee686d605e2e4a2cd78f46118b77808 to your computer and use it in GitHub Desktop.
Save Jach/8ee686d605e2e4a2cd78f46118b77808 to your computer and use it in GitHub Desktop.
Check if an instagram profile has an active story
#|
Instagram is truly a terrible site.
And their notifications suck.
And even if you have pretty good self-control, the addiction mechanisms can still get you for a time.
Anyway, this script lets me stay away from the site and only check it if a profile I care about
has a new story posted. (Stories themselves are also evil, ephemeral status updates popularized by
snapchat are the devil.)
It sleeps for 24.5ish hours after a hit, because 24h is the default time before a story expires if
the person doesn't delete it first, so if further stories are posted, you won't know about them
right away, and may even miss them entirely if they were posted right after. (Oh well.)
Public domain code.
|#
(defpackage :insta-notify
(:use :cl))
(in-package :insta-notify)
(ql:quickload :cl-webdriver-client)
(ql:quickload :cl-ppcre)
(use-package :webdriver-client)
(defvar page "https://www.instagram.com/PROFILE_HERE/")
(defun has-story ()
(handler-case
(with-session (make-capabilities :always-match
'((browser-name . "firefox")
("moz:firefoxOptions" . (("args" . #("-headless"))) )
))
(setf (url) page)
(sleep (+ 8 (random 2.0)))
(let ((has-pointer? (execute-script
"
let imgs = Array.from(document.getElementsByTagName('img'));
let prof_img = imgs.find(el => (el.getAttribute('alt') && el.getAttribute('alt').search('profile picture') != -1));
let div_to_check = prof_img.parentNode.parentNode;
return div_to_check.style.cursor;" nil)))
(string-equal "pointer" has-pointer?)))
(sb-sys:io-timeout () nil)
(webdriver-client::protocol-error () nil)))
(defun main ()
(loop
(when (has-story)
(uiop:run-program (list "/usr/bin/notify-send" "-u" "critical" "PERSON posted a new story" (format nil "Link ~a" page)))
(format t "New story, sleeping now~%")
(force-output)
; wait 24 hours before checking again, since it will continue being true until it expires
(sleep (* 60 60 24)))
(format t ".")
(force-output)
(sleep (* 60 (+ 30 (+ 0.75 (random 4.0)))))))
(eval-when (:execute)
(main))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment