Last active
June 9, 2018 08:27
-
-
Save masatoi/14902ce178ea0474e978941168ad2251 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| #|-*- mode:lisp -*-|# | |
| #| | |
| exec ros -Q -- $0 "$@" | |
| |# | |
| (progn ;;init forms | |
| (ros:ensure-asdf) | |
| #+quicklisp (ql:quickload '(:dexador :plump :clss :anaphora) :silent t)) | |
| (defpackage :ros.script.connpass-participation.3736231159 | |
| (:use :cl :anaphora :plump :clss)) | |
| (in-package :ros.script.connpass-participation.3736231159) | |
| (defstruct user | |
| display-name user-page-link profile icon twitter github) | |
| (defun node-text (node) | |
| (let ((text-list nil)) | |
| (traverse node | |
| (lambda (node) (push (text node) text-list)) | |
| :test #'text-node-p) | |
| (apply #'concatenate 'string (nreverse text-list)))) | |
| (defun e1 (arr) (aref arr 0)) | |
| (defun get-user-page-links-from-event-page (url) | |
| (let ((root (parse (dex:get url)))) | |
| (map 'list | |
| (lambda (a-node) | |
| (list (node-text a-node) | |
| (attribute a-node "href"))) | |
| (select ".applicant_area .user .display_name a" root)))) | |
| (defun make-user-from-user-page (display-name url) | |
| (let* ((root (parse (dex:get url))) | |
| (icon-node (e1 (select "#side_area .mb_20 img" root))) | |
| (icon-url (attribute icon-node "src")) | |
| (profile-header (e1 (select "#main .profile_header_area" root))) | |
| (social-link (map 'list | |
| (lambda (node) (attribute node "href")) | |
| (select ".social_link a" profile-header))) | |
| (profile (node-text (e1 (select "p" profile-header))))) | |
| (make-user | |
| :display-name display-name | |
| :user-page-link url | |
| :profile profile | |
| :icon icon-url | |
| :twitter (aif (car social-link) (subseq it 19)) | |
| :github (aif (cadr social-link) (subseq it 19))))) | |
| (defun get-users-from-event-page (url) | |
| (let ((name-link-pairs (get-user-page-links-from-event-page url))) | |
| (mapcar (lambda (name-link-pair) | |
| (format t "fetching profile of ~A~%" (car name-link-pair)) | |
| (apply #'make-user-from-user-page name-link-pair)) | |
| name-link-pairs))) | |
| (defun format-user (user &key (stream *standard-output*)) | |
| (format stream | |
| "## ~A | |
|  | |
| - ~A | |
| - Twitter: ~A | |
| - Github: ~A | |
| --- | |
| " | |
| (user-display-name user) (user-icon user) (user-profile user) | |
| (user-twitter user) (user-github user))) | |
| ;;; usage | |
| ;; ./connpass-participation.ros https://lisp.connpass.com/event/87489/participation/ out | |
| (defun main (&rest argv) | |
| (assert (= (length argv) 2)) | |
| (let ((url (car argv)) | |
| (output-file (cadr argv))) | |
| (with-open-file (out output-file :direction :output :if-exists :supersede) | |
| (let ((users (get-users-from-event-page url))) | |
| (dolist (user users) | |
| (format-user user :stream out)))))) | |
| ;;; vim: set ft=lisp lisp: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment