2022-09-16 13:56:03 +00:00
|
|
|
#lang racket/base
|
2022-10-09 07:53:09 +00:00
|
|
|
(require racket/list
|
|
|
|
(prefix-in easy: net/http-easy)
|
|
|
|
memo
|
2022-09-16 13:56:03 +00:00
|
|
|
"url-utils.rkt"
|
|
|
|
"xexpr-utils.rkt")
|
|
|
|
|
|
|
|
(provide
|
2022-10-09 09:50:50 +00:00
|
|
|
(struct-out siteinfo^)
|
|
|
|
(struct-out license^)
|
2022-10-09 07:53:09 +00:00
|
|
|
siteinfo-fetch
|
2022-10-09 09:50:50 +00:00
|
|
|
siteinfo-default
|
2022-10-09 07:53:09 +00:00
|
|
|
license-default)
|
2022-09-16 13:56:03 +00:00
|
|
|
|
2022-10-09 09:50:50 +00:00
|
|
|
(struct siteinfo^ (sitename basepage license) #:transparent)
|
|
|
|
(struct license^ (text url) #:transparent)
|
2022-10-09 07:53:09 +00:00
|
|
|
|
2022-10-09 09:50:50 +00:00
|
|
|
(define license-default (license^ "CC-BY-SA" "https://www.fandom.com/licensing"))
|
|
|
|
(define siteinfo-default (siteinfo^ "Test Wiki" "Main_Page" license-default))
|
2022-10-09 07:53:09 +00:00
|
|
|
|
|
|
|
(define/memoize (siteinfo-fetch wikiname) #:hash hash
|
2022-09-16 13:56:03 +00:00
|
|
|
(define dest-url
|
|
|
|
(format "https://~a.fandom.com/api.php?~a"
|
|
|
|
wikiname
|
|
|
|
(params->query '(("action" . "query")
|
|
|
|
("meta" . "siteinfo")
|
2022-10-09 07:53:09 +00:00
|
|
|
("siprop" . "general|rightsinfo")
|
2022-09-16 13:56:03 +00:00
|
|
|
("format" . "json")
|
|
|
|
("formatversion" . "2")))))
|
2022-10-04 08:13:07 +00:00
|
|
|
(log-outgoing dest-url)
|
2022-09-16 13:56:03 +00:00
|
|
|
(define res (easy:get dest-url))
|
|
|
|
(define data (easy:response-json res))
|
2022-10-09 09:50:50 +00:00
|
|
|
(siteinfo^ (jp "/query/general/sitename" data)
|
|
|
|
(second (regexp-match #rx"/wiki/(.*)" (jp "/query/general/base" data)))
|
|
|
|
(license^ (jp "/query/rightsinfo/text" data)
|
|
|
|
(jp "/query/rightsinfo/url" data))))
|