Skip to content

Instantly share code, notes, and snippets.

@SaitoAtsushi
Created February 6, 2011 03:41
Show Gist options
  • Save SaitoAtsushi/813104 to your computer and use it in GitHub Desktop.
Save SaitoAtsushi/813104 to your computer and use it in GitHub Desktop.
#!/usr/bin/env gosh
;; -*- coding: utf-8-unix ; mode: gauche; -*-
(use rfc.http)
(use rfc.json)
(use srfi-43)
(use gauche.collection)
(use text.tree)
(use sxml.tools)
(use sxml.serializer)
(use www.cgi)
(define (assoc* obj lst)
(if-let1 x (assoc obj lst)
(cdr x)
#f))
(define (ranked-list)
(receive (status header body)
(http-get "www.followjp.com"
"/common/php/realtimeList.php?from=1&to=25")
(call-with-input-string body parse-json)))
(define (sexp->rss sexp)
`(*TOP*
(@@ (*NAMESPACES*
(rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#")))
(rdf:RDF
(@ (xmlns "http://purl.org/rss/1.0/"))
(channel
(@ (rdf:about "http://www.followjp.com/"))
(title "WiLiKi")
(link "ここに cgi を設置した url を書くこと")
(description "RT ranking")
(items (rdf:Seq
,@(map (lambda(x)`(rdf:li (@ (rdf:resource ,(car x))))) sexp))))
,@(map (lambda(x)`(item (@ (rdf:about ,(car x)))
(title ,(cadr x))
(link ,(car x))))
sexp))))
(define (json->sexp lst)
(let1 x (assoc* "rankedTwitList" lst)
(map-to <list>
(^z (list #`"http://twitter.com/,(assoc* \"owner\" z)/statuses/,(assoc* \"id\" z)" (assoc* "body" z)))
x)))
(define (main args)
(cgi-main
(lambda(param)
`(,(cgi-header)
"<?xml version='1.0' encoding='utf-8' ?>\n"
,(srl:parameterizable
(sexp->rss (json->sexp (ranked-list))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment