コード例 #1
0
def main(test=False):
    tool = GroupTools()
    scrape = MultiProcessHtml()
    system = SystemTools()
    last_func_called = ""

    while True:
        print("\n" + 10 * "#" + " GROUP TOOLS MENU " + 10 * "#" +
              "\nPlease choose one of the following options\n")
        user_input = input(
            "\njoin_group: joins a single WhatsApp group\n\n" +
            "join_multiple_groups: joins all groups listed in a file\n\n" +
            "single_group_data: retrieves and saves raw html containing single group messages\n\n"
            +
            "all_groups_data: retrieves and saves raw html containing group messages for all groups\n\n"
            + "print_groups: prints group list to the console\n\n" +
            "back: return to main menu\n\nUSER INPUT: ")
        print("")
        if user_input == ("join_group"):
            tool.join_group_cli()
            last_func_called = "join_group"
        elif user_input == ("join_multiple_groups"):
            tool.join_multiple_groups_cli()
            last_func_called = "join_multiple_groups"
        elif user_input == ("single_group_data"):
            tool.save_single_groups_data_cli()
            last_func_called = "single_group_data"
        elif user_input == ("all_groups_data"):
            if test is False:
                tool.save_all_groups_data_cli()
            last_func_called = "all_groups_data"
        elif user_input == ("print_groups"):
            tool.print_groups()
            last_func_called = "print_groups"
        elif user_input == ("generate_csv"):
            df = pd.DataFrame()
            df = scrape.get_message_frame_all_groups(
                system.get_processed_pck_list())
            scrape.generate_message_summary_csv(df)
            last_func_called = "generate_csv"
        elif user_input == ("back"):
            break
        else:
            print(
                "\n\n******** PLEASE ENTER A VALID OPTION OR 'back' TO END PROGRAM.\n"
            )
            last_func_called = "invalid_input"
    print_endpoints()
    return last_func_called
コード例 #2
0
def test_success_join_multiple_groups_cli(monkeypatch):
    if not os.path.exists(test_groups_to_join):
        os.makedirs(test_groups_to_join)
    with open(test_local_groups_path, 'w+') as fp:
        fp.write(success_test_page + "\n")
        fp.write(success_test_page + "\n")
        fp.write(fail_test_page + "\n")
    fp.close()
    group_tools = GroupTools()
    monkeypatch.setattr('builtins.input', lambda _: test_local_groups_file)
    group_tools.join_multiple_groups_cli(groups_to_join_path=test_groups_to_join,
                                         groups_failed_path=test_groups_failed,
                                         timeout=timeout)
    assert sum(1 for line in open(test_groups_failed + test_local_groups_file, 'r')) == 1
    shutil.rmtree(test_groups_to_join, ignore_errors=True)
    shutil.rmtree(test_groups_failed, ignore_errors=True)
コード例 #3
0
def test_back_join_multiple_groups_cli(monkeypatch):
    group_tools = GroupTools()
    monkeypatch.setattr('builtins.input', lambda _: next(test_multi_group_join_responses))
    assert group_tools.join_multiple_groups_cli(groups_to_join_path=test_groups_to_join) is None
    shutil.rmtree(test_groups_to_join, ignore_errors=True)