Last active
December 20, 2015 13:29
-
-
Save valvallow/6138735 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env gosh | |
(use file.util) | |
(use net.twitter) | |
(use gauche.threads) | |
(use gauche.parseopt) | |
(define (usage cmd) | |
(print "Usage: " (sys-basename cmd) " [option ...] message") | |
(print " h|help : Show this help") | |
(print " n|number : Number of continuous tweets (default:endress)") | |
(print " k|key-file : The path of the file for which have listed the Consumer-key and Access-token") | |
(print " ex) twitter-id1 consumer-key1 consumer-secret1 access-token1 access-token-secret1") | |
(print " twitter-id2 consumer-key2 consumer-secret2 access-token2 access-token-secret2") | |
(print " ...") | |
(print " twitter-idn consumer-keyn consumer-secretn access-tokenn access-token-secretn") | |
(print " (default: " +RC_FILE_PATH+ ")") | |
(print " i|interval :Interval (default: 0.1)") | |
(print " s|suffix :Message suffix (default: !)") | |
(print " d|debug :Debug mode. Print message to console, Twitter not update") | |
(exit)) | |
(define +RC_FILE_PATH+ "~/.tbbbrc") | |
(define *threads* '()) | |
;; C-c to exit | |
(set-signal-handler! SIGINT (^ _ (exit))) | |
;; file spec: refer to the help option k|key-file | |
;; return (("twitter-id" . <twitter-cred>) ...) | |
(define (file->credentials file) | |
(if (not (file-exists? (expand-path file))) | |
'() | |
(map (^(line) | |
(let1 id&cred (string-split line #\space) | |
(cons (car id&cred) | |
(apply make <twitter-cred> | |
(append-map list | |
(list :consumer-key | |
:consumer-secret | |
:access-token | |
:access-token-secret) | |
(cdr id&cred)))))) | |
(file->string-list (expand-path file))))) | |
;; suffix=! | |
;; n=1, msg=hoge => "hoge!" | |
;; n=2, msg=hoge => "hoge!!" | |
;; n=3, msg=hoge => "hoge!!!" ... | |
(define (make-nth-tweet n msg suffix) | |
(apply string-append msg (make-list n suffix))) | |
(define (main args) | |
(let-args (cdr args) | |
((help "h|help" => (cut usage (car args))) | |
(number "n|number=i" +inf.0) | |
(keys "k|keys=s" +RC_FILE_PATH+) | |
(interval "i|interval=f" 0.1) | |
(suffix "s|suffix=s" "!") | |
(debug "d|debug") | |
(else (opt . _) | |
(print "Unknown option : " opt) | |
(usage (car args))) | |
. rest) | |
(when debug | |
(set! twitter-update | |
(^(cred msg) | |
(print cred " " msg)))) | |
(let1 credentials (file->credentials keys) | |
(when (or (null? rest) ; massage | |
(null? credentials)) | |
(usage (car args))) | |
(let/cc break | |
(dotimes (i number) | |
(let1 msg (make-nth-tweet i (car rest) suffix) | |
(when (< 140 (string-length msg)) | |
(break)) | |
(for-each (^c (thread-sleep! interval) | |
(let1 thread (make-thread | |
(^ _ (twitter-update (cdr c) msg) | |
(print (car c) " " i " done!"))) | |
(push! *threads* thread) | |
(thread-start! thread))) | |
credentials)))) | |
(print "Press any key to continue ...") | |
(read-line)))) |
% ./tweet-bals-batch-balk.scm ばるす > bals.log
% cat bals.log | grep done | awk '{print $1}'| sort | uniq -c | awk '{ total+= $1}END{print total}'
% ln -s realpath ./tweet-bals-batch-balk.scm
~/bin/bals
% bals ばるす > bals.log
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/mhayashi1120/Gauche-net-oauth
https://github.com/mhayashi1120/Gauche-net-twitter