WIP mediaWikiSystem
This commit is contained in:
1
cli.hxml
1
cli.hxml
@@ -2,6 +2,7 @@
|
||||
-lib uuid
|
||||
-lib tink_macro
|
||||
-lib tink_json
|
||||
-lib requests-externs
|
||||
-cp src
|
||||
--main nat.CLI
|
||||
--interp
|
1
extern-files/python/args.hxml
Normal file
1
extern-files/python/args.hxml
Normal file
@@ -0,0 +1 @@
|
||||
-lib requests-externs
|
2
extern-files/python/import.hx
Normal file
2
extern-files/python/import.hx
Normal file
@@ -0,0 +1,2 @@
|
||||
import requests_externs.Response;
|
||||
import requests_externs.Requests;
|
1
extern-files/python/requirements.txt
Normal file
1
extern-files/python/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
requests==2.26.0
|
@@ -1,9 +1,9 @@
|
||||
(function eval [:String expStr :Array<String> activeConditions]
|
||||
(let [hscriptExp
|
||||
(.parseString (new Parser)
|
||||
(Prelude.convertToHScript expStr))
|
||||
interp
|
||||
(new BoolExpInterp)]
|
||||
(let [hscript (Prelude.convertToHScript expStr)
|
||||
parser (new Parser)
|
||||
hscriptExp (parser.parseString hscript)
|
||||
interp (new BoolExpInterp)]
|
||||
|
||||
(doFor condition activeConditions
|
||||
(interp.variables.set condition true))
|
||||
?(interp.execute hscriptExp)))
|
||||
|
9
src/nat/systems/MediaWikiSystem.hx
Normal file
9
src/nat/systems/MediaWikiSystem.hx
Normal file
@@ -0,0 +1,9 @@
|
||||
package nat.systems;
|
||||
|
||||
import kiss.Prelude;
|
||||
import kiss.List;
|
||||
import requests_externs.Response;
|
||||
import nat.System;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class MediaWikiSystem extends System {}
|
32
src/nat/systems/MediaWikiSystem.kiss
Normal file
32
src/nat/systems/MediaWikiSystem.kiss
Normal file
@@ -0,0 +1,32 @@
|
||||
(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 :Response queryProp [:Array<String> titles :Array<String> props]
|
||||
(#extern Response python
|
||||
(object
|
||||
hxmlFile "extern-files/python/args.hxml"
|
||||
importHxFile "extern-files/python/import.hx"
|
||||
langProjectFile "extern-files/python/requirements.txt")
|
||||
[:Array<String> titles _ :Array<String> props _ :String mediaWikiUrl _ :Float maxLag (or maxLag 1) :Map<String,String> headers _]
|
||||
(Requests.get mediaWikiUrl
|
||||
[
|
||||
=>"action" "query"
|
||||
=>"titles" (titles.join "|")
|
||||
=>"prop" (props.join "|")
|
||||
=>"maxlag" (Std.string maxLag)
|
||||
=>"format" "json"
|
||||
]
|
||||
(object headers headers))))
|
||||
|
||||
(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"])
|
@@ -6,6 +6,7 @@ import nat.BoolExpInterp;
|
||||
import nat.Archive;
|
||||
import nat.Lib;
|
||||
import nat.components.*;
|
||||
import nat.systems.*;
|
||||
|
||||
@:build(kiss.Kiss.build())
|
||||
class TestMain {}
|
||||
|
@@ -1,12 +1,21 @@
|
||||
// External programs can load Lib.kiss with (loadFrom "nat-archive-tool" "src/nat/Lib.kiss")
|
||||
(load "../nat/Lib.kiss")
|
||||
|
||||
(print "dicks")
|
||||
|
||||
(assert (BoolExpInterp.eval "true" []))
|
||||
(print "dicks")
|
||||
(assert !(BoolExpInterp.eval "false" []))
|
||||
(print "dicks")
|
||||
(assert !(BoolExpInterp.eval "flag" []))
|
||||
(print "dicks")
|
||||
(assert (BoolExpInterp.eval "flag" ["flag"]))
|
||||
(print "dicks")
|
||||
(assert !(BoolExpInterp.eval "(and flag false)" ["flag"]))
|
||||
(print "dicks")
|
||||
(assert (BoolExpInterp.eval "(or flag otherFlag)" ["otherFlag"]))
|
||||
|
||||
(print "dicks")
|
||||
(let [archive
|
||||
(new Archive "src/test/example-archive")
|
||||
song1
|
||||
@@ -14,6 +23,7 @@
|
||||
song2
|
||||
(dictGet archive.entries "song2")]
|
||||
|
||||
(print "dicks")
|
||||
(assert (hasComponent song1 Tags))
|
||||
(assert (hasComponent song2 Tags))
|
||||
(assert (componentsMatch song1 "(and Name Author)"))
|
||||
@@ -22,9 +32,17 @@
|
||||
(assert !(tagsMatch archive song1 "(and song religious)"))
|
||||
(assert (tagsMatch archive song2 "(and song religious)"))
|
||||
(assert !(tagsMatch archive song2 "(and song western)"))
|
||||
(print "dicks")
|
||||
|
||||
(withWritableComponents archive song1
|
||||
[author Author
|
||||
name Name]
|
||||
(assert (= author "Rafael Krux"))
|
||||
(assert (= name "Adventure"))))
|
||||
|
||||
(print "dicks")
|
||||
|
||||
(let [wikipedia (new MediaWikiSystem "https://en.wikipedia.org/w/api.php" null null 1)]
|
||||
//~(wikipedia.queryProp ["Phoenix Wright"] ["images"])
|
||||
0
|
||||
)
|
Reference in New Issue
Block a user