Test new features for variables
This commit is contained in:
parent
89f3576881
commit
68b6e1c9fe
|
@ -3,10 +3,29 @@ const request = require('sync-request');
|
|||
const dom = require('@xmldom/xmldom').DOMParser;
|
||||
const xpath = require('xpath');
|
||||
|
||||
const FunctToEvalString = (Funct) => Funct.toString().split('{').slice(1).join('{').split('}').slice(0, -1).join('}');
|
||||
const FormatMacrosInText = (Text) => {
|
||||
//console.log('`' + Text.replaceAll('{', '${Macros.').replaceAll('}', '({})}') + '`');
|
||||
return ('`' + Text.replaceAll('{', '${Macros.').replaceAll('}', '({})}') + '`');
|
||||
};
|
||||
|
||||
const GetStepValues = (Step, Parent, Reqs) => {
|
||||
let StepFinal = {};
|
||||
let Macros = Reqs.Macros;
|
||||
let Values = xpath.select('./*', Step);
|
||||
for (let Value of Values) {
|
||||
// if '${Step.getAttribute('source').toLowerCase()}' === 'body'
|
||||
if (Value.tagName.toLowerCase() === 'value') {
|
||||
StepFinal[Value.getAttribute('name')] = xpath.select(eval(FormatMacrosInText(Value.getAttribute('path'))), Reqs.Html/*HtmlDom*/).toString();
|
||||
} else
|
||||
if (Value.tagName.toLowerCase() === 'items') {
|
||||
StepFinal = {...StepFinal, ...GetStepValues(Value, Step, Reqs)};
|
||||
};
|
||||
};
|
||||
return StepFinal;
|
||||
};
|
||||
|
||||
const LoadBeesText = (Xml) => {
|
||||
let Final = {};
|
||||
let [Final, Macros] = [{}, {}];
|
||||
let Parsed = new dom().parseFromString(Xml, 'text/xml');
|
||||
let Bees = xpath.select('/bees/bee', Parsed);
|
||||
for (let Bee of Bees) {
|
||||
|
@ -15,32 +34,42 @@ const LoadBeesText = (Xml) => {
|
|||
ApiUrl: Bee.getAttribute('apiurl'),
|
||||
Functions: {},
|
||||
};
|
||||
let Sets = xpath.select('//set', Bee);
|
||||
for (let Set_ of Sets) {
|
||||
//let ArgsList = Set_.getAttribute('').split(' ');
|
||||
//if (ArgsList[0]) {
|
||||
Macros[Set_.getAttribute('name')] = (Args) => {
|
||||
//console.log(eval('`' + Set_.getAttribute('value').replaceAll('{', '${Args.') + '`'));
|
||||
eval('`' + Set_.getAttribute('value').replaceAll('{', '${Args.') + '`');
|
||||
};
|
||||
//};
|
||||
};
|
||||
let Functs = xpath.select('./function', Bee);
|
||||
for (let Funct of Functs) {
|
||||
let FuncName = Funct.getAttribute('name');
|
||||
let SubFuncts = [];
|
||||
let Steps = xpath.select('./*', Funct);
|
||||
for (let Step of Steps) {
|
||||
SubFuncts = [...SubFuncts, () => {
|
||||
SubFuncts = [...SubFuncts, (Args) => {
|
||||
let StepFinal = {};
|
||||
if (Step.tagName === 'request') {
|
||||
let Res = request(Step.getAttribute('method'), `${Final[Name].ApiUrl}${Step.getAttribute('path')}`);
|
||||
// if '${Step.getAttribute('format')}' == 'HTML'
|
||||
for (let Arg in Args) {
|
||||
Macros[Arg] = () => Args[Arg];
|
||||
};
|
||||
if (Step.tagName.toLowerCase() === 'request') {
|
||||
let Res = request(Step.getAttribute('method'), Final[Name].ApiUrl + eval(FormatMacrosInText(Step.getAttribute('path'))));
|
||||
// if '${Step.getAttribute('format').toLowerCase()}' === 'html'
|
||||
let Body = Res.getBody('utf-8');
|
||||
let HtmlDom = new dom().parseFromString(Body);
|
||||
let Values = xpath.select('./value', Step);
|
||||
for (let Value of Values) {
|
||||
// if '${Step.getAttribute('source')}' == 'body'
|
||||
StepFinal[Value.getAttribute('name')] = xpath.select(Value.getAttribute('path'), HtmlDom).toString();
|
||||
};
|
||||
//let Values = xpath.select('./value', Step);
|
||||
StepFinal = GetStepValues(Step, null, {Html: HtmlDom, Macros: Macros});
|
||||
};
|
||||
return StepFinal;
|
||||
}];
|
||||
};
|
||||
Final[Name].Functions[FuncName] = () => {
|
||||
Final[Name].Functions[FuncName] = (Args) => {
|
||||
let FuncFinal = {};
|
||||
for (SubFunct of SubFuncts) {
|
||||
FuncFinal = {...FuncFinal, ...SubFunct()};
|
||||
FuncFinal = {...FuncFinal, ...SubFunct(Args)};
|
||||
};
|
||||
return FuncFinal;
|
||||
};
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env node
|
||||
const BeeWarehouse = require('../../BeeWarehouse.js');
|
||||
|
||||
let ExampleCom = BeeWarehouse.LoadBeesFile('./ExampleCom.xml').ExampleCom;
|
||||
let ExampleCom = BeeWarehouse.LoadBeesFile(`${__dirname}/ExampleCom.xml`).ExampleCom;
|
||||
let Info = ExampleCom.Functions.GetInfo();
|
||||
console.log(Info);
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
const BeeWarehouse = require('../../BeeWarehouse.js');
|
||||
|
||||
let Arguments = { "Source": "profile.php?id=100043901540898" };
|
||||
let FbLikebox = BeeWarehouse.LoadBeesFile('./FbLikebox.xml').FbLikebox;
|
||||
let FbLikebox = BeeWarehouse.LoadBeesFile(`${__dirname}/FbLikebox.xml`).FbLikebox;
|
||||
|
||||
let Profile = ExampleCom.Functions.GetProfileInfo(Arguments);
|
||||
let Profile = FbLikebox.Functions.GetProfileInfo(Arguments);
|
||||
console.log(Profile);
|
||||
|
||||
let Posts = ExampleCom.Functions.GetLatestPosts(Arguments);
|
||||
let Posts = FbLikebox.Functions.GetLatestPosts(Arguments);
|
||||
console.log(Posts);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<bees>
|
||||
<bee name="FbLikebox" apiurl="https://www.facebook.com">
|
||||
<set name="LikeboxUrl" value="/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2F{Source}&stream=true&_fb_noscript=1" arguments="Source">
|
||||
<set name="LikeboxUrl" value="/plugins/likebox.php?href=https%3A%2F%2Fwww.facebook.com%2F{Source}&stream=true&_fb_noscript=1"/>
|
||||
|
||||
<function name="GetProfileInfo" arguments="Source">
|
||||
<request method="GET" path="{LikeboxUrl}" format="HTML">
|
||||
|
@ -12,7 +12,7 @@
|
|||
<function name="GetLatestPosts" arguments="Source">
|
||||
<request method="GET" path="{LikeboxUrl}" format="HTML">
|
||||
<items source="body" path="/html/body//div[@role='feed']/div/div/div[2]">
|
||||
<set name="PostAnchor" value="./div[1]/div[2]/div[1]/div[2]/div/div/div[2]/a">
|
||||
<set name="PostAnchor" value="./div[1]/div[2]/div[1]/div[2]/div/div/div[2]/a"/>
|
||||
<value name="Message" source="body" path="./div[1]/div[2]/div[2]" key="text"/>
|
||||
<value name="Media" source="body" path="./div[1]/div[1]//a/*[@src]" key="src"/>
|
||||
<value name="Time" source="body" path="{PostAnchor}/abbr" key="data-utime"/>
|
||||
|
|
Loading…
Reference in New Issue