65 lines
3.1 KiB
Plaintext
65 lines
3.1 KiB
Plaintext
(load "../Lib.kiss")
|
|
|
|
(defNew [&prop :String mediaWikiUrl
|
|
// TODO make a &super annotation that passes an argument to the super constructor
|
|
:EntryChecker canProcess
|
|
:EntryProcessor processor
|
|
&prop :Null<Float> maxLag]
|
|
(super
|
|
canProcess
|
|
processor))
|
|
|
|
// TODO make this an externMethod --
|
|
// 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
|
|
(method :Option<Dynamic> query [:Map<String,Array<String>> params]
|
|
(let [data
|
|
(Json.parse
|
|
(#extern String python
|
|
(object
|
|
hxmlFile "extern-files/python/args.hxml"
|
|
importHxFile "extern-files/python/import.hx"
|
|
langProjectFile "extern-files/python/requirements.txt")
|
|
[:Map<String,Array<String>> params _ :String mediaWikiUrl _ :String maxLag (if maxLag (Std.string maxLag) "1") :Map<String,String> headers _]
|
|
|
|
(print "extern query call $params")
|
|
(let [response
|
|
(Requests.get mediaWikiUrl
|
|
(let [innerParams
|
|
[
|
|
=>"action" "query"
|
|
=>"maxlag" maxLag
|
|
=>"format" "json"
|
|
]]
|
|
(doFor =>param paramValues params (dictSet innerParams param (paramValues.join "|")))
|
|
innerParams)
|
|
(object
|
|
headers headers
|
|
timeout 2))]
|
|
(assert response.ok "MediaWiki query failed")
|
|
(print "call finished: ${response.text}")
|
|
response.text)))]
|
|
(if data.query
|
|
(Some data.query)
|
|
None)))
|
|
|
|
(method :Array<String> queryImageTitles [:Array<String> pageTitles]
|
|
(ifLet [(Some queryResult) (query [=>"titles" pageTitles =>"prop" ["images"]])]
|
|
(flatten
|
|
(for =>_id page (the haxe.DynamicAccess<Dynamic> queryResult.pages)
|
|
(if page.images
|
|
(page.images.map ->image image.title)
|
|
[])))
|
|
[]))
|
|
|
|
(method :Array<String> queryImageUrls [:Array<String> imageTitles]
|
|
(ifLet [(Some queryResult) (query [=>"titles" imageTitles =>"prop" ["imageinfo"] =>"iiprop" ["url"]])]
|
|
(flatten
|
|
(for =>_id image
|
|
(the haxe.DynamicAccess<Dynamic> queryResult.pages)
|
|
(if image.imageinfo
|
|
(image.imageinfo.map ->image image.url)
|
|
[])))
|
|
[]))
|
|
|
|
(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"]) |