Initial neo4j collector code
This commit is contained in:
112
ovos_PHAL_plugin_neo4j_collector/__init__.py
Normal file
112
ovos_PHAL_plugin_neo4j_collector/__init__.py
Normal file
@@ -0,0 +1,112 @@
|
||||
import requests
|
||||
|
||||
import json
|
||||
import queue
|
||||
|
||||
from ovos_plugin_manager.phal import PHALPlugin
|
||||
from ovos_config.config import LocalConf
|
||||
from ovos_config.config import update_mycroft_config
|
||||
from ovos_config.locations import get_webcache_location
|
||||
from ovos_bus_client.util import get_mycroft_bus
|
||||
from ovos_utils.messagebus import Message
|
||||
from ovos_utils.log import LOG
|
||||
from ovos_utils import classproperty
|
||||
from ovos_utils.process_utils import RuntimeRequirements
|
||||
from json_database import JsonConfigXDG
|
||||
|
||||
|
||||
class Neo4jCollectorPlugin(PHALPlugin):
|
||||
def __init__(self, bus=None, config=None):
|
||||
super().__init__(bus, "ovos-PHAL-plugin-neo4j-collector", config)
|
||||
#self.web_config = LocalConf(get_webcache_location())
|
||||
|
||||
# Initialize queue for Mycroft and user messages
|
||||
self.message_queue = queue.Queue()
|
||||
|
||||
|
||||
self.bus.on("mycroft.internet.connected", self.on_reset)
|
||||
self.bus.on("recognizer_loop:utterance", self.on_utterance)
|
||||
self.bus.on("configuration.updated", self.init_configuration)
|
||||
reinstall_hint = "pip install --upgrade --no-deps --force-reinstall git+https://git.sebastianmaki.fi/sebastian/ovos-PHAL-plugin-neo4j-collector.git"
|
||||
LOG.info(f"Reinstall hint: {reinstall_hint}")
|
||||
|
||||
self.setup_configuration()
|
||||
|
||||
@classproperty
|
||||
def runtime_requirements(self):
|
||||
return RuntimeRequirements(internet_before_load=True,
|
||||
network_before_load=True,
|
||||
requires_internet=True,
|
||||
requires_network=True,
|
||||
no_internet_fallback=False,
|
||||
no_network_fallback=False)
|
||||
|
||||
def on_reset(self, message=None):
|
||||
LOG.info(f"On reset triggered")
|
||||
|
||||
def on_utterance(self, message=None):
|
||||
LOG.info(f"On utterance triggered: %s", message.serialize())
|
||||
#for utterance in message.data['utterances']:
|
||||
# self.message_queue.put(("user", utterance))
|
||||
|
||||
def on_speak(self, message=None):
|
||||
LOG.info(f"On speak triggered: %s", message.serialize())
|
||||
#self.message_queue.put(("mycroft", message.data['utterance']))
|
||||
|
||||
|
||||
def setup_configuration(self):
|
||||
first_start = self.config.get("first_start", True)
|
||||
if first_start:
|
||||
self.config["first_start"] = False
|
||||
config_patch = {
|
||||
"PHAL": {
|
||||
"ovos-PHAL-plugin-neo4j-collector": {
|
||||
"first_start": False,
|
||||
"neo4j_uri": "",
|
||||
"neo4j_password": "",
|
||||
"neo4j_username": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
update_mycroft_config(config=config_patch, bus=self.bus)
|
||||
self.init_configuration()
|
||||
|
||||
def init_configuration(self, message=None):
|
||||
""" Initialize instance configuration """
|
||||
configuration_first_start = self.config.get("first_start", True)
|
||||
configuration_neo4j_uri = self.config.get("neo4j_uri", "")
|
||||
configuration_neo4j_username= self.config.get("neo4j_username", "")
|
||||
configuration_neo4j_password = self.config.get("neo4j_password", "")
|
||||
config = {"neo4j_uri": configuration_neo4j_uri, "neo4j_username": configuration_neo4j_username, "neo4j_password": configuration_neo4j_password }
|
||||
config_json = json.dumps(config)
|
||||
LOG.info(f"Configuration updated: %s", config_json)
|
||||
|
||||
uninitialized_settings = []
|
||||
if not configuration_neo4j_uri:
|
||||
uninitialized_settings.append("NEO4J_URI")
|
||||
|
||||
if not configuration_neo4j_username:
|
||||
uninitialized_settings.append("NEO4J_USERNAME")
|
||||
|
||||
if not configuration_neo4j_password:
|
||||
uninitialized_settings.append("NEO4J_PASSWORD")
|
||||
|
||||
if uninitialized_settings:
|
||||
self.bus.emit(Message("ovos.phal.plugin.neo4j_collector.requires.configuration"))
|
||||
config_issue = "The following configuration settings are uninitialized: " + ", ".join(uninitialized_settings)
|
||||
LOG.info(config_issue)
|
||||
else:
|
||||
self.neo4j_uri = configuration_neo4j_uri
|
||||
self.neo4j_user = configuration_neo4j_username
|
||||
self.neo4j_pass = configuration_neo4j_password
|
||||
LOG.info("All configuration settings are initialized.")
|
||||
self.init_neo4j()
|
||||
|
||||
def init_neo4j(self):
|
||||
# Start the Connection to a neo4j instance
|
||||
LOG.info("Starting the bot")
|
||||
self.bot.run(self.api_token)
|
||||
|
||||
|
||||
|
||||
|
||||
7
ovos_PHAL_plugin_neo4j_collector/version.py
Normal file
7
ovos_PHAL_plugin_neo4j_collector/version.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# The following lines are replaced during the release process.
|
||||
# START_VERSION_BLOCK
|
||||
VERSION_MAJOR = 0
|
||||
VERSION_MINOR = 0
|
||||
VERSION_BUILD = 0
|
||||
VERSION_ALPHA = 1
|
||||
# END_VERSION_BLOCK
|
||||
Reference in New Issue
Block a user