-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#42 - CLI helper / personal assistant on command prompt
Commit for php helper and linux/macos shell runner, outstanding is windows batch file. The TagUI scripts are already in natural-language-like syntax to convert to JS code. I want to have a helper that can convert natural-language-like instructions on the command line to call the right scripts with right parameters. Instead of typing tagui download_bank_report june on command prompt, I think it is more intuitive to support typing erina download my june bank report or something like that directly on command prompt. And let the magic happens behind the scenes to return the results. running this - erina 5w1h/verb fillers options/modifiers fillers single-or-multi-word-context results in running - tagui 5w1h/verb_context quiet options/modifiers calling using chrome/firefox/headless or with chrome/firefox/headless at the end of erina … will call tagui in visible chrome, firefox, headless chrome respectively. this feature allows future extension to natural language voice control. the trigger word erina can be changed by just renaming the erina file (macos/linux) or erina.cmd (windows) file.
- Loading branch information
Showing
6 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
# HELPER ASSISTANT SCRIPT FOR RUNNING TAGUI FRAMEWORK ~ TEBEL.ORG # | ||
|
||
# save location of initial directory where helper is called | ||
initial_dir=`pwd` | ||
|
||
# change current directory to TAGUI directory | ||
SOURCE="${BASH_SOURCE[0]}" # slimerjs's implementation instead of cd "`dirname "$0"`" | ||
while [ -h "$SOURCE" ]; do TAGUI_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" | ||
SOURCE="$(readlink "$SOURCE")"; [[ $SOURCE != /* ]] && SOURCE="$TAGUI_DIR/$SOURCE"; done | ||
TAGUI_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"; cd "$TAGUI_DIR" | ||
|
||
# delete helper file if it exists to prevent running an old call | ||
if [ -f "tagui_helper" ]; then rm tagui_helper; fi | ||
|
||
# call php helper to interpret parameters passed in to cli helper | ||
php -q tagui_helper.php $1 $2 $3 $4 $5 $6 $7 $8 $9 | ||
|
||
# run generated output from php helper to call automation flow | ||
if [ -f "tagui_helper" ]; then ./tagui_helper; fi | ||
|
||
# change back to initial directory where tagui is called | ||
cd "$initial_dir" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/* HELPER PARSER SCRIPT FOR TAGUI FRAMEWORK ~ TEBEL.ORG */ | ||
|
||
// configure directory to look for automation flow files - default location is set to tagui/flows | ||
// avoid spaces in folder and filename, issue with CasperJS and TagUI can't tell where options start | ||
$helper_flow_directory = "../flows"; | ||
|
||
// concatenate all parameters into one string for processing | ||
$raw_intent = $argv[1] . " " . $argv[2] . " " . $argv[3] . " " . $argv[4] . " " . | ||
$argv[5] . " " . $argv[6] . " " . $argv[7] . " " . $argv[8] . " " . $argv[9]; | ||
$raw_intent = trim($raw_intent); | ||
|
||
// initialise components required for forming the final output command | ||
$helper_flow_context = ""; $helper_flow_action = ""; $helper_flow_filename = ""; | ||
$helper_flow_options = ""; $helper_flow_browser = ""; $helper_flow_found = false; | ||
|
||
// remove filler words that have limited impact on meaning of intention | ||
$raw_intent = str_replace(" is "," ",$raw_intent); $raw_intent = str_replace(" are "," ",$raw_intent); | ||
$raw_intent = str_replace(" was "," ",$raw_intent); $raw_intent = str_replace(" were "," ",$raw_intent); | ||
$raw_intent = str_replace(" my "," ",$raw_intent); $raw_intent = str_replace(" me "," ",$raw_intent); | ||
$raw_intent = trim($raw_intent); | ||
|
||
// check for using browser string at end of intention to pass browser type option | ||
// important to concatenate at end of options in order to not disrupt p1-p9 parameters | ||
if ((strpos($raw_intent,"using chrome")!==false) and | ||
(strrpos($raw_intent,"using chrome") == (strlen($raw_intent) - strlen("using chrome")))) | ||
{$helper_flow_browser = " chrome"; $raw_intent = substr($raw_intent,0,strrpos($raw_intent,"using chrome"));} | ||
else if ((strpos($raw_intent,"using headless")!==false) and | ||
(strrpos($raw_intent,"using headless") == (strlen($raw_intent) - strlen("using headless")))) | ||
{$helper_flow_browser = " headless"; $raw_intent = substr($raw_intent,0,strrpos($raw_intent,"using headless"));} | ||
else if ((strpos($raw_intent,"using firefox")!==false) and | ||
(strrpos($raw_intent,"using firefox") == (strlen($raw_intent) - strlen("using firefox")))) | ||
{$helper_flow_browser = " firefox"; $raw_intent = substr($raw_intent,0,strrpos($raw_intent,"using firefox"));} | ||
else if ((strpos($raw_intent,"with chrome")!==false) and | ||
(strrpos($raw_intent,"with chrome") == (strlen($raw_intent) - strlen("with chrome")))) | ||
{$helper_flow_browser = " chrome"; $raw_intent = substr($raw_intent,0,strrpos($raw_intent,"with chrome"));} | ||
else if ((strpos($raw_intent,"with headless")!==false) and | ||
(strrpos($raw_intent,"with headless") == (strlen($raw_intent) - strlen("with headless")))) | ||
{$helper_flow_browser = " headless"; $raw_intent = substr($raw_intent,0,strrpos($raw_intent,"with headless"));} | ||
else if ((strpos($raw_intent,"with firefox")!==false) and | ||
(strrpos($raw_intent,"with firefox") == (strlen($raw_intent) - strlen("with firefox")))) | ||
{$helper_flow_browser = " firefox"; $raw_intent = substr($raw_intent,0,strrpos($raw_intent,"with firefox"));} | ||
$raw_intent = trim($raw_intent); | ||
|
||
// throw error message if there are no minimum of an action + 1-word context | ||
if (strpos($raw_intent," ")==false) die("cannot find action and context in your instruction" . "\n"); | ||
|
||
// loop through intention after filtering away fillers and browser option | ||
$token = explode(" ",$raw_intent); $helper_flow_action = $token[0]; // split into tokens separated by space | ||
for ($count = 1; $count < sizeof($token); $count++) {$helper_flow_context = ""; $helper_flow_options = ""; | ||
for ($context_count = 1 + $count; $context_count <= sizeof($token); $context_count++) { | ||
$helper_flow_context .= $token[$context_count - 1] . " ";} | ||
$helper_flow_context = str_replace(" ","_",trim($helper_flow_context)); | ||
for ($options_count = 1 ; $options_count < $count; $options_count++) { | ||
$helper_flow_options .= $token[$options_count] . " ";} | ||
$helper_flow_options = trim($helper_flow_options); | ||
$helper_flow_filename = $helper_flow_directory . "/" . trim($helper_flow_action . "_" . $helper_flow_context); | ||
// echo "./tagui " . $helper_flow_filename . " quiet " . trim($helper_flow_options . $helper_flow_browser) . "\n"; | ||
if (file_exists($helper_flow_filename)) {$helper_flow_found = true; break;}} | ||
|
||
// generate flow options taking into account browser to be used | ||
$helper_flow_options = trim($helper_flow_options . $helper_flow_browser); | ||
|
||
// throw error message if a match for flow filename is not found | ||
if (!$helper_flow_found) die("cannot find automation to run for your instruction" . "\n"); | ||
|
||
// write interpreted command and flow to run to output runner | ||
$output_file = fopen('tagui_helper','w') or die("cannot open tagui_helper, raise an issue on TagUI GitHub page" . "\n"); | ||
fwrite($output_file,"#!/usr/bin/env bash" . "\n"); | ||
fwrite($output_file,"# GENERATED HELPER ASSISTANT SCRIPT FOR RUNNING TAGUI FRAMEWORK ~ TEBEL.ORG #" . "\n"); | ||
fwrite($output_file,"./tagui " . $helper_flow_filename . " quiet " . $helper_flow_options . "\n"); | ||
fclose($output_file); chmod ('tagui_helper',0700); | ||
|
||
?> |
3e3f924
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tagged wrong issue, should be #44