Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Commit

Permalink
Fix #2, get all stream for each event
Browse files Browse the repository at this point in the history
So if an event is streamed in multiple languages, that's picked up
correctly now :-).
  • Loading branch information
vendethiel committed Apr 10, 2017
1 parent ae0677d commit 7aa1e03
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
3 changes: 2 additions & 1 deletion ignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
The Nydus
The Nydus
The PiG Daily
65 changes: 44 additions & 21 deletions main.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
(ql:quickload :plump :silent t)
(ql:quickload :clss :silent t)

(defconstant +sc2-css+ ".ev[style='background: url(/images/games/1.png) transparent no-repeat']" )
(defconstant +sc2-css+ ".ev[style='background: url(/images/games/1.png) transparent no-repeat']")
(defconstant +default-lang+ "gb")
(defvar *sc2-streams* (make-hash-table :test 'equal))
(with-open-file (stream "streams")
(loop
Expand All @@ -26,25 +27,46 @@
collect line)))

(defun parse-events (tl-doc)
(flet ((approved-event (name) (not (member name *sc2-ignores* :test 'equal)))
(has-elements (seq) (plusp (length seq))))
(labels
((approved-event (name)
(not (member name *sc2-ignores* :test 'equal)))
(has-elements (seq)
(plusp (length seq)))
(attr-first (els attr)
(plump:attribute (aref els 0) attr))
(stream-name (a)
(format nil "http://teamliquid.net~a" (attr-first a "href")))
(stream-lang (imgs)
(if (plusp (length imgs)) ; 0 or 1
;; extract flag
(pathname-name (pathname (attr-first imgs "src")))
+default-lang+))
(get-streams (name stream-spans)
(alexandria:if-let (stream (gethash name *sc2-streams*))
(list (list +default-lang+ stream)) ; single result if listed
(map 'list
(lambda (span)
(list (stream-lang (clss:select "img" span))
(stream-name (clss:select "a" span))))
stream-spans))))
(loop
for event across (clss:select ".ev-feed .ev-block" tl-doc)
for classes = (plump:attribute event "class")
for name = (plump:text (aref (clss:select "span[data-event-id]" event) 0))
for timer = (plump:text (aref (clss:select ".ev-timer" event) 0))

for is-live = (search "ev-live" classes)
for stream-a = (clss:select ".ev-stream a" event) ; find TL stream link (XXX the english stream SHOULD always be first)
for stream-tl = (when (and is-live (has-elements stream-a))
(format nil "http://teamliquid.net~a" (plump:attribute (aref stream-a 0) "href")))
for stream = (or (gethash name *sc2-streams*) stream-tl)
for result = (list name (if is-live nil timer) stream)

when (and (approved-event name) (has-elements (clss:select +sc2-css+ event)))
for event across (clss:select ".ev-feed .ev-block" tl-doc)
for classes = (plump:attribute event "class")
for name = (plump:text (aref (clss:select "span[data-event-id]" event) 0))
for timer = (plump:text (aref (clss:select ".ev-timer" event) 0))

for is-live = (search "ev-live" classes)
for stream-spans = (clss:select ".ev-stream > div > span:first-child" event)
;for stream-spans = (map 'list (lambda (div) (aref (clss:select "span" div) 0))
; (clss:select ".ev-stream" event))
for result = (list name
(unless is-live timer)
(if is-live (get-streams name stream-spans)))

when (and (approved-event name) (has-elements (clss:select +sc2-css+ event)))
if is-live collect result into live
else collect result into upcoming
finally (return (list live upcoming)))))
else collect result into upcoming
finally (return (list live upcoming)))))

(defun print-events (header events)
(when events
Expand All @@ -53,10 +75,11 @@
(lambda (event)
(destructuring-bind (name timer stream) event
(unless (search "days" timer) ; remove event in the "far" future (2d+)
(format t "~a~@[ - ~a~]~@[ - ~a~]~%" name timer stream))))
(format t "~a~@[ - ~a~]~%~:{ :flag_~a: ~a~%~}" name timer stream)

)))
events)
(write-char #\Newline)
))
(write-char #\Newline)))

(destructuring-bind (live upcoming) (parse-events (plump:parse (dex:get "http://teamliquid.net/")))
(print-events "live" live)
Expand Down

0 comments on commit 7aa1e03

Please sign in to comment.