Ejemplo n.º 1
0
async def list_info(msg):
    if "website" in msg.data:
        #bad use of distill_msg, it needs rework
        distilled = distill_msg(msg=msg, sediment="website")
        distilled = distill_msg(msg=distilled, sediment="list")
        show_all = False
        if "_all_" in distilled.data or "_every" in distilled.data:
            show_all = True
        requested_sites = []
        if not show_all:
            for key in resource_handler.get_resource_keys(section=_WEBSITE_SECTION):
                if intersect_strings(distilled.data, key)["char_count"] >= 4:
                    requested_sites.append(key)
        if len(requested_sites) <= 0:
            show_all = True
        display_strings = []
        for key, ws in resource_handler.get_resources(section=_WEBSITE_SECTION):
            if show_all or key in requested_sites:
                try:
                    display_strings.append(await form_display_string(website_info=ws.get_info()))
                except:
                    traceback.print_exc()
        if len(display_strings) >= 1:
            for display_string in display_strings:
                print("")
                print(display_string)
            return True
    return False
Ejemplo n.º 2
0
async def send_message(msg):
    data = msg.data
    recipients = []
    for cerebrate in cerebratesinfo.get_cerebrate_records():
        name = cerebrate.get(cerebratesinfo.Record.NAME, "")
        if name in data:
            mac = cerebrate.get(cerebratesinfo.Record.MAC, "")
            if not mac in recipients:
                recipients.append(mac)
                communication.distill_msg(msg, name)
    for cerebrate in cerebratesinfo.get_cerebrate_records():
        location = cerebrate.get(cerebratesinfo.Record.LOCATION, "")
        if location in data:
            mac = cerebrate.get(cerebratesinfo.Record.MAC, "")
            if not mac in recipients:
                recipients.append(mac)
                communication.distill_msg(msg, location)
    if recipients.__len__() <= 0:
        recipients = cerebratesinfo.get_cerebrate_macs()
        recipients.remove(mysysteminfo.get_mac_address())
    for recipient in recipients:
        await communication.Secretary.communicate_message(
            cerebrate_mac=recipient,
            msg=communication.Message('display_message', data=msg.data))
    # speak msg
    #aprint("Message communicated")
    return True
Ejemplo n.º 3
0
def open_browser(msg=None):
    url = None
    if msg:
        #get match_string from msg, get URL from Website using match_string
        data = distill_msg(msg=msg, sediment="open").data.strip()
        url = Website.get_url_greedy_match(match_string=data)
        if not url and not "browser" in data:
            return False
    return _open_browser(url=url)
Ejemplo n.º 4
0
def _close_browser(msg=None, lock=_browser_lock):
    '''Closes the current window, or the target window if given in Message.'''
    global _browser
    try:
        window_title = None
        if msg:
            '''extract window to close'''
            open_window_titles = []
            for handle in _browser.window_handles:
                _browser.switch_to.window(handle)
                open_window_titles.append(_browser.title)
            data = distill_msg(msg, "close").data.strip()
            if data:
                match = get_greedy_match(match_string=data, possible_matches=open_window_titles)
                if match.get("char_count", 0) > 2:
                    window_title = match.get("match", None)
                if not window_title:
                    if "browser" in data:
                        _quit_browser()
                    else:
                        return False
        with lock:
            if not window_title:
                try:
                    _close_handle(handle=_browser.current_window_handle, lock=_Lock_Bypass())
                except:
                    _close_handle(handle=_browser.window_handles[len(_browser.window_handles)-1], lock=_Lock_Bypass())
            elif window_title.lower() in _browser.title.lower():
                _close_handle(handle=_browser.current_window_handle, lock=_Lock_Bypass())
            else:
                active_handle = _browser.current_window_handle
                for handle in _browser.window_handles:
                    _browser.switch_to.window(handle)
                    if window_title.lower() in _browser.title.lower():
                        _close_handle(handle=handle, lock=_Lock_Bypass())
                        break
                try:
                    _browser.switch_to.window(active_handle)
                except:
                    '''active handle was closed'''
                    if len(_browser.window_handles) > 0:
                        _browser.switch_to.window(_browser.window_handles[len(_browser.window_handles)-1])
        if len(_browser.window_handles) <= 0:
            _quit_browser()
    except:
        '''all windows are closed (or browser is already closed)'''
        if cc.debug_in_effect:
            traceback.print_exc()
        _quit_browser()
    return True
Ejemplo n.º 5
0
def search_site(msg):
    data = distill_msg(msg=msg, sediment="search").data.strip()
    if not data:
        return False
    try:
        parsed_data = data.split("for")
        site_name = parsed_data[0]
        query = parsed_data[1]
        try:
            url = Website.get_url_greedy_match(match_string=site_name, query_string=query)
            if url:
                _open_browser(url=url)
        except:
            traceback.print_exc()
    except:
        '''input does not match pattern'''
Ejemplo n.º 6
0
def save_site(msg):
    '''If clipboard contains a url, it will be saved according to the name given in msg.data.
    Name in msg.data is parsed as anything given after the word "as".
    If no name given, will parse the url and save it according to domain name.
    '''
    url = pyperclip.paste()
    print("url = ", url)
    if not validate_url(url):
        return False
    path_name = None
    data = distill_msg(msg=msg, sediment="save").data.strip()
    if data:
        try:
            path_name = data.split("as")[1].strip()
        except:
            '''no 'as' found, so path_name cannot be extracted from given data'''
    _save_url(url=url, path_name=path_name)
    return True
Ejemplo n.º 7
0
Archivo: info.py Proyecto: Hynchus/Hive
async def info(msg):
    check = None
    try:
        data = command.format_command(cmd=distill_msg(msg, "help").data)
        everything = True
        for _, _, command_dict in command.get_all_commands():
            check = command_dict
            if command_dict[Command.NAME].lower() in data:
                everything = False
                print("\n", command_dict[Command.NAME], ": ",
                      command_dict[Command.DESCRIPTION])
                print("\t", command_dict[Command.USE])
        if everything:
            for _, _, command_dict in command.get_all_commands():
                print("\n", command_dict[Command.NAME], ": ",
                      command_dict[Command.DESCRIPTION])
                print("\t", command_dict[Command.USE])
    except:
        traceback.print_exc()
        print(check)
    return True