WIP mediaWikiSystem

This commit is contained in:
2021-08-01 18:27:58 -06:00
parent c4754c2b35
commit 9e75fd8d5b
10 changed files with 73 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
-lib uuid
-lib tink_macro
-lib tink_json
-lib requests-externs
-cp src
--main nat.CLI
--interp

View File

@@ -0,0 +1 @@
-lib requests-externs

View File

@@ -0,0 +1,2 @@
import requests_externs.Response;
import requests_externs.Requests;

View File

@@ -0,0 +1 @@
requests==2.26.0

View File

@@ -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)))

View 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 {}

View 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"])

View File

@@ -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 {}

View File

@@ -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
)

View File

@@ -1,6 +1,8 @@
-D test
-lib kiss
-lib nat-archive-tool
-lib requests-externs
-cp test
--main test.TestMain
--interp
--python bin/main.py
--cmd python bin/main.py