Skip to content

Commit

Permalink
Adds really basic setup details and details about dev enviroment
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Morris committed Aug 18, 2020
1 parent d0e2a2e commit 69ce964
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 203 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,26 @@
# mycroft-cl
A new mycroft command line interface, that is ment to be decoupled from any one particular mycroft instance.

Dependencies:
pip install websocket
[a Mycroft instace](https://github.com/MycroftAI/mycroft-core)

Getting started useing this tool:
```git clone https://github.com/FruityWelsh/mycroft-cl.git```
```cd mycroft-cl```
if you are running this for a local mycroft instance then you
can run it with no added steps for example:
```./mycroft_cl.py speak hello```

Otherwise you can change the IP target address and port by change the ```MYCROFT_ADDR``` and ```MYCROFT_PORT``` env vars.
This can be done prior to use like:
```export MYCROFT_ADDR='localhost'```
```export MYCROFT_PORT='8181'```

or by adding these lines (but with your new values) to your ```${HOME}/.profile``` config file.


Setup for development:
I currently use poetry for depency managment.
I also use black and mypy for code linting and include pre-commit hooks for them.

5 changes: 5 additions & 0 deletions mycroft_cl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sys
import os


logging.basicConfig(level=logging.DEBUG)
local_file_path = os.path.dirname(os.path.realpath(__file__))
MYCROFT_ADDR = os.environ.get("MYCROFT_ADDR", "localhost")
Expand All @@ -21,6 +22,7 @@


def send_message(message, mycroft_addr=MYCROFT_ADDR, mycroft_port=MYCROFT_PORT):
"""Creates websocket address string, connects and sends fully formed json message"""
url = f"ws://{mycroft_addr}:{mycroft_port}/core"
logging.debug(f"Websocket url: {url}")
ws = create_connection(url)
Expand All @@ -35,15 +37,18 @@ def send_message(message, mycroft_addr=MYCROFT_ADDR, mycroft_port=MYCROFT_PORT):


def get_mycroft_message(command, json_dir=MYCROFT_JSON_DIR):
"""Retrives and loads the correct json file for the command given"""
json_file = f"{json_dir}/{command}.json"
logging.debug(f"json_file: {json_file}")
with open(f"{json_file}", "rb") as fh:
message = json.load(fh)
logging.debug(f"json_message: {message}")
print(type(message))
return message


def run(command, data, mycroft_addr=MYCROFT_ADDR, mycroft_port=MYCROFT_PORT):
"""Parses data into expected json fields depending on which command is provided"""
message = get_mycroft_message(command)

if command == "speak":
Expand Down
Loading

0 comments on commit 69ce964

Please sign in to comment.