Requests return dynamic
This commit is contained in:
@@ -1,2 +1 @@
|
|||||||
import requests_externs.Response;
|
|
||||||
import requests_externs.Requests;
|
import requests_externs.Requests;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package nat.systems;
|
|||||||
|
|
||||||
import kiss.Prelude;
|
import kiss.Prelude;
|
||||||
import kiss.List;
|
import kiss.List;
|
||||||
import requests_externs.Response;
|
|
||||||
import nat.System;
|
import nat.System;
|
||||||
|
import haxe.Json;
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
class MediaWikiSystem extends System {}
|
class MediaWikiSystem extends System {}
|
||||||
|
|||||||
@@ -12,21 +12,25 @@
|
|||||||
// 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 :Response queryProp [:Array<String> titles :Array<String> props]
|
(method :Dynamic queryProp [:Array<String> titles :Array<String> props]
|
||||||
(#extern Response python
|
(Json.parse
|
||||||
(object
|
(#extern String python
|
||||||
hxmlFile "extern-files/python/args.hxml"
|
(object
|
||||||
importHxFile "extern-files/python/import.hx"
|
hxmlFile "extern-files/python/args.hxml"
|
||||||
langProjectFile "extern-files/python/requirements.txt")
|
importHxFile "extern-files/python/import.hx"
|
||||||
[:Array<String> titles _ :Array<String> props _ :String mediaWikiUrl _ :String maxLag (if maxLag (Std.string maxLag) "1") :Map<String,String> headers _]
|
langProjectFile "extern-files/python/requirements.txt")
|
||||||
(Requests.get mediaWikiUrl
|
[:Array<String> titles _ :Array<String> props _ :String mediaWikiUrl _ :String maxLag (if maxLag (Std.string maxLag) "1") :Map<String,String> headers _]
|
||||||
[
|
(let [response
|
||||||
=>"action" "query"
|
(Requests.get mediaWikiUrl
|
||||||
=>"titles" (titles.join "|")
|
[
|
||||||
=>"prop" (props.join "|")
|
=>"action" "query"
|
||||||
=>"maxlag" maxLag
|
=>"titles" (titles.join "|")
|
||||||
=>"format" "json"
|
=>"prop" (props.join "|")
|
||||||
]
|
=>"maxlag" maxLag
|
||||||
(object headers headers))))
|
=>"format" "json"
|
||||||
|
]
|
||||||
|
(object headers headers))]
|
||||||
|
(assert response.ok)
|
||||||
|
response.text))))
|
||||||
|
|
||||||
(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,6 +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.queryProp ["Phoenix Wright"] ["images"]))
|
||||||
0
|
|
||||||
)
|
|
||||||
@@ -3,7 +3,6 @@ package requests_externs;
|
|||||||
import haxe.extern.EitherType;
|
import haxe.extern.EitherType;
|
||||||
import python.Dict;
|
import python.Dict;
|
||||||
import python.KwArgs;
|
import python.KwArgs;
|
||||||
import requests_externs.Response;
|
|
||||||
|
|
||||||
typedef NativeRequestKwArgs = {
|
typedef NativeRequestKwArgs = {
|
||||||
?headers:Dict<String, String>
|
?headers:Dict<String, String>
|
||||||
@@ -15,12 +14,12 @@ typedef RequestKwArgs = {
|
|||||||
|
|
||||||
@:pythonImport("requests")
|
@:pythonImport("requests")
|
||||||
extern class NativeRequests {
|
extern class NativeRequests {
|
||||||
public static function get(url:String, params:Dict<String, String>, ?kwArgs:KwArgs<RequestKwArgs>):NativeResponse;
|
public static function get(url:String, params:Dict<String, String>, ?kwArgs:KwArgs<NativeRequestKwArgs>):Dynamic;
|
||||||
}
|
}
|
||||||
|
|
||||||
class Requests {
|
class Requests {
|
||||||
public static function get(url:String, params:Map<String, String>, ?kwArgs:KwArgs<RequestKwArgs>):NativeResponse {
|
public static function get(url:String, params:Map<String, String>, ?kwArgs:RequestKwArgs):Dynamic {
|
||||||
return NativeRequests.get(url, mapToDict(params), kwArgs);
|
return NativeRequests.get(url, mapToDict(params), kwArgsToNativeKwArgs(kwArgs));
|
||||||
}
|
}
|
||||||
|
|
||||||
static function mapToDict(?map:Map<String, String>) {
|
static function mapToDict(?map:Map<String, String>) {
|
||||||
@@ -33,7 +32,9 @@ class Requests {
|
|||||||
return dict;
|
return dict;
|
||||||
}
|
}
|
||||||
|
|
||||||
static function kwArgsToNativeKwArgs(kwArgs:RequestKwArgs) {
|
static function kwArgsToNativeKwArgs(?kwArgs:RequestKwArgs) {
|
||||||
|
if (kwArgs == null)
|
||||||
|
return null;
|
||||||
return {
|
return {
|
||||||
headers: mapToDict(kwArgs.headers)
|
headers: mapToDict(kwArgs.headers)
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package requests_externs;
|
|
||||||
|
|
||||||
@:pythonImport("requests.Response")
|
|
||||||
extern class NativeResponse {}
|
|
||||||
|
|
||||||
typedef Response = {};
|
|
||||||
Reference in New Issue
Block a user