Пример #1
0
 def print_table_fancy_grid(converter, to_file):
     FileUtils.ensure_file_exists_and_writable(to_file)
     converted_data = converter.convert(ExportMode.TEXT)
     tabulated = tabulate(converted_data,
                          converter.headers,
                          tablefmt="fancy_grid")
     LOG.info("Writing results to file: %s", to_file)
     FileUtils.write_to_file(to_file, tabulated)
def main():
    # checking for connected devices
    adb_out = os.popen("adb devices -l").read()
    if not adb_out:
        raise ValueError("Unexpected output from adb: '{}'".format(adb_out))

    second_line = adb_out.split('\n', 1)[1]
    device_info_list = second_line.split("device")[1:]
    if not device_info_list:
        print("Found no device connected!")
        exit(1)
    device_info = "".join([d.strip() for d in device_info_list])
    print("Detected connected device: " + device_info)

    # Get forward list
    forward_list = os.popen("adb forward --list").read().strip()
    if not forward_list:
        print(
            "Port forward not detected. Opening one port forwarding TCP socket on port %s"
            % PORT)
        os.system("adb forward tcp:{} localabstract:{}".format(
            PORT, ABSTRACT_SOCKET_NAME))
    forward_list = os.popen("adb forward --list").read().strip()
    if not forward_list:
        raise ValueError(
            "Cannot create port forwarding TCP socket on port %s!" % PORT)
    print("Forward list: " + forward_list)

    data = None
    try:
        data = load_json("http://localhost:{}/json/list".format(PORT))
    except ConnectionError as e:
        print(
            "Error while querying Chrome history. Make sure Google Chrome is launched on the device."
        )
        print(e)
        exit(1)

    # Order by ids
    ordered_data = sorted(data, key=lambda d: d['id'])
    # print("Ordered data: " + str(ordered_data))

    urls = [d['url'] for d in ordered_data]
    # print("URLs: " + str(urls))

    if not urls:
        print("Opened pages could not be found. Exiting...")
        return
    final_result = "\n".join(urls)
    file_name = "webpages-phone-" + datetime.datetime.now().strftime(
        '%Y%m%d_%H%M%S.txt')
    file_path = os.path.join("/tmp", file_name)
    FileUtils.write_to_file(file_path, final_result)
    print("Pages saved to file: " + file_path)
    print("Please execute command: cp {} ~/Downloads/ && subl ~/Downloads/{}".
          format(file_path, file_name))
Пример #3
0
    def print_table_html(converter, to_file):
        import html
        FileUtils.ensure_file_exists_and_writable(to_file)
        converted_data = converter.convert(ExportMode.HTML)
        tabulated = tabulate(converted_data,
                             converter.headers,
                             tablefmt="html")

        # Unescape manually here, as tabulate automatically escapes HTML content and there's no way to turn this off.
        tabulated = html.unescape(tabulated)

        LOG.info("Writing results to file: " + to_file)
        FileUtils.write_to_file(to_file, tabulated)