queryImageTitles from mediaWiki
This commit is contained in:
@@ -12,25 +12,29 @@
|
|||||||
// TODO make this an externMethod --
|
// TODO make this an externMethod --
|
||||||
// but mediaWikiUrl, headers, and maxLag will still have to be specified, not as args
|
// but mediaWikiUrl, headers, and maxLag will still have to be specified, not as args
|
||||||
// unless all vars and props are passed to externmethods by default
|
// unless all vars and props are passed to externmethods by default
|
||||||
(method :Dynamic queryProp [:Array<String> titles :Array<String> props]
|
(method :Dynamic query [:Map<String,Array<String>> params]
|
||||||
(Json.parse
|
(Json.parse
|
||||||
(#extern String python
|
(#extern String python
|
||||||
(object
|
(object
|
||||||
hxmlFile "extern-files/python/args.hxml"
|
hxmlFile "extern-files/python/args.hxml"
|
||||||
importHxFile "extern-files/python/import.hx"
|
importHxFile "extern-files/python/import.hx"
|
||||||
langProjectFile "extern-files/python/requirements.txt")
|
langProjectFile "extern-files/python/requirements.txt")
|
||||||
[:Array<String> titles _ :Array<String> props _ :String mediaWikiUrl _ :String maxLag (if maxLag (Std.string maxLag) "1") :Map<String,String> headers _]
|
[:Map<String,Array<String>> params _ :String mediaWikiUrl _ :String maxLag (if maxLag (Std.string maxLag) "1") :Map<String,String> headers _]
|
||||||
(let [response
|
(let [response
|
||||||
(Requests.get mediaWikiUrl
|
(Requests.get mediaWikiUrl
|
||||||
|
(let [innerParams
|
||||||
[
|
[
|
||||||
=>"action" "query"
|
=>"action" "query"
|
||||||
=>"titles" (titles.join "|")
|
|
||||||
=>"prop" (props.join "|")
|
|
||||||
=>"maxlag" maxLag
|
=>"maxlag" maxLag
|
||||||
=>"format" "json"
|
=>"format" "json"
|
||||||
]
|
]]
|
||||||
|
(doFor =>param paramValues params (dictSet innerParams param (paramValues.join "|")))
|
||||||
|
innerParams)
|
||||||
(object headers headers))]
|
(object headers headers))]
|
||||||
(assert response.ok)
|
(assert response.ok)
|
||||||
response.text))))
|
response.text))))
|
||||||
|
|
||||||
|
(defmethod queryImageTitles [:Array<String> pageTitles]
|
||||||
|
(flatten (for =>_id page (the haxe.DynamicAccess<Dynamic> .pages .query (query [=>"titles" pageTitles =>"prop" ["images"]])) (page.images.map ->image image.title))))
|
||||||
|
|
||||||
(var headers [=>"User-Agent" "NatArchiveTool/0.0.0 (https://github.com/NQNStudios/kisslang/tree/main/projects/nat-archive-tool; natquaylenelson@gmail.com) Requests/2.26.0"])
|
(var headers [=>"User-Agent" "NatArchiveTool/0.0.0 (https://github.com/NQNStudios/kisslang/tree/main/projects/nat-archive-tool; natquaylenelson@gmail.com) Requests/2.26.0"])
|
||||||
@@ -31,4 +31,4 @@
|
|||||||
(assert (= name "Adventure"))))
|
(assert (= name "Adventure"))))
|
||||||
|
|
||||||
(let [wikipedia (new MediaWikiSystem "https://en.wikipedia.org/w/api.php" null null 1)]
|
(let [wikipedia (new MediaWikiSystem "https://en.wikipedia.org/w/api.php" null null 1)]
|
||||||
~(wikipedia.queryProp ["Phoenix Wright"] ["images"]))
|
~(wikipedia.queryImageTitles ["Phoenix Wright"]))
|
||||||
Reference in New Issue
Block a user