コード例 #1
0
ファイル: menus.py プロジェクト: sonipta/test
    def handle_input():
        """
        Prompts the user for a choice and calls the function from the 'modules' folder that corresponds
        with that choice.
        """
        userChoice = input()

        # Choice 1 is downloading all json and pdf files.
        if userChoice == "1":
            clear()
            print(
                "\nUpon pressing ENTER, a file browser will open.\nPlease select your input CSV file."
            )
            input()
            # Opens a graphical file browser and returns the path to the csv file that the user selected.
            csvChoice = file_browser.browseCSVFiles()

            # Assigns the choice to a global variable, so other modules can find the path that the user specified.
            global_variables.CSV_INPUT_PATH = csvChoice
            clear()
            menus.select_paths_menu()
            clear()
            menus.specify_client_matter_menu()
            print(msg)
            get_json_and_pdfs()
        # Choice 2 is donwloading only JSON files.
        elif userChoice == "2":
            clear()
            print(
                "\nUpon pressing ENTER, a file browser will open.\nPlease select your input CSV file."
            )
            input()
            # Opens a graphical file browser and returns the path to the csv file that the user selected.
            csvChoice = file_browser.browseCSVFiles()
            # Assigns the choice to a global variable, so other modules can find the path that the user specified.
            global_variables.CSV_INPUT_PATH = csvChoice
            clear()
            menus.select_paths_menu(pdfOption=False)
            menus.specify_client_matter_menu()
            print(msg)
            get_json.thread_download_json()
        # Choice 3 is downloading only PDF files.
        elif userChoice == "3":
            clear()
            menus.select_paths_menu()
            menus.specify_client_matter_menu()
            print(msg)
            link_list = get_pdfs.get_urls("json-output")
            get_pdfs.thread_download_pdfs(link_list)
        elif userChoice == "4":
            spreadsheet_generator_menu()
        elif userChoice == "5":
            clear()
            menus.other_options_menu()

        # If the user enters anything other than a valid choice, then it tells them their choice is invalid and
        # restarts this function, prompting them to make a choice again.
        else:
            print("Please Enter Valid input (1, 2 or 3)")
            return handle_input()
コード例 #2
0
ファイル: menus.py プロジェクト: sonipta/test
def select_paths_menu(pdfOption=True):
    """
    This displays a menu to the user allowing them to choose file paths to save their downloaded data to.
    It handles their choices and changes the global variables representing the file paths for saving.
    """
    print("Below are the current settings for finding and saving files:\n")
    print(
        f"[1] The CSV file filled with docket numbers is located at:\n{os.path.abspath(global_variables.CSV_INPUT_PATH)}\n"
    )
    print(
        f"[2] JSON Files are saved to and retrieved from:\n{os.path.abspath(global_variables.JSON_INPUT_OUTPUT_PATH)}\n"
    )
    if pdfOption == True:
        print(
            f"[3] PDF Files are saved to:\n{os.path.abspath(global_variables.PDF_OUTPUT_PATH)}\n"
        )
    print(
        "To change these paths. Type the number for the path you want to change and press ENTER.\n"
    )
    print(
        Fore.RED +
        "[WARNING] A lot of files can be generated in the PDF and JSON directories you choose! Choose carefully!\n"
        + Style.RESET_ALL)
    if global_variables.IS_CACHED == False:
        print(
            Fore.RED +
            "[WARNING] You are making an UNCACHED search that may result in extra charges. Restart the program to make a CACHED search.\n"
            + Style.RESET_ALL)
    print("If you are happy with the current selection, simply press ENTER.\n")

    # Prompts the user for a choice and saves it in a variable.
    userChoice = input()

    # Choice 1 is to edit the path to the input csv full of docket numbers.
    if userChoice == "1":
        print("Select the path of your input csv file.")
        print("Press ENTER to open the file browser.")
        input()

        # Opens the file browser and returns the path to the file that the user selected.
        csvChoice = file_browser.browseCSVFiles()

        # We store this choice to a global variable to be used elsewhere in the script where
        # we need to access this choice.
        global_variables.CSV_INPUT_PATH = csvChoice

        clear()

        # Reloads path select menu, relflecting any changes.
        select_paths_menu()

    # Choice 2 is to edit the path to the json files.
    if userChoice == "2":
        print("Select the path where you would like to store your JSON files.")
        print("Press ENTER to open the file browser.")
        input()

        # Stores the users choice in a variable
        jsonChoice = file_browser.browseDirectories('json-output')

        # Stores the choice to a global variable so this choice can be used throughout this script,
        # not only in the context of this file.
        global_variables.JSON_INPUT_OUTPUT_PATH = jsonChoice

        clear()
        # Reloads path select menu, relflecting any changes.
        select_paths_menu()

    # Choice 3 is to edit the path where the folders full of PDF files will be saved.
    if userChoice == "3":
        print("Select the path where you would like to store your PDF files.")
        print("Press ENTER to open the file browser.")
        input()

        # Opens a file explorer and returns the path to the directory the user selected as a string.
        pdfChoice = file_browser.browseDirectories('pdf-output')

        # Saves the chosen file path to a global variable so it can be accessed elsewhere in the script when
        # we need to access this path.
        global_variables.PDF_OUTPUT_PATH = pdfChoice

        clear()
        # Reloads path select menu, relflecting any changes.
        select_paths_menu()

    # If the user doesnt make a choice and just presses ENTER, the program exits this menu and moves forward
    else:
        clear()
コード例 #3
0
def spreadsheet_generator_menu():
    import generate_spreadsheets
    clear()

    csv_generator_instructions = """
Instructions:

Make a Docket Alarm search query or import a csv full of case numbers and 4 spreadsheets will be generated containing data from all of the returned results.
You will browse for an output folder to save your spreadsheets to.
These are not the same format as the spreadsheets used as input for downloading PDFs and JSON.

Press ENTER to continue.
    """

    input_preference_msg = """
How would you like to select your cases?

[1/blank] Docket Alarm search query

[2] Input CSV

Enter your choice [1/2], and press ENTER to continue.
"""

    sort_results_msg = """

How would you like to sort your results?

[1/blank] Search by relevance, which considers matching keywords, court level, and recentness.

[2] Oldest first by docket/document filing date.

[3] Newest first by docket/document filing date.

[4] Order dockets by the date of the most recent entry listed on the docket ascending.

[5] Order dockets by the date of the most recent entry listed on the docket descending.

[6] Random order. (good for sampling)

Enter your choice below. [1/2/3/4/5/6] [blank=1]

"""
    print(Fore.RED + msg2)
    print("\nPress ENTER to begin" + Style.RESET_ALL)
    input()
    clear()
    print(csv_generator_instructions)

    print(input_preference_msg)
    input_preference_choice = input()

    if input_preference_choice == "1" or not input_preference_choice:
        clear()
        print("\nEnter a Docket Alarm search query.\n")
        print(
            "(This is the same query that you would enter on docketalarm.com.\nFull search documentation can be found at https://www.docketalarm.com/posts/2014/6/23/Terms-and-Connectors-Searching-With-Docket-Alarm/)\n\n"
        )
        users_search_query = input()
        clear()
        print("Calculating maximum number of results, please wait...")
        user = login.Credentials()
        amountOfResults = requests.get(
            "https://www.docketalarm.com/api/v1/search/",
            params={
                "login_token": user.authenticate(),
                "q": users_search_query,
                "limit": "1"
            },
            timeout=60).json()['count']
        clear()
        print(f"Maximum number of results: {amountOfResults}")
        print(
            "\nEnter the number of results you want to return (or blank for all)\n\n"
        )
        result = input()
        users_number_of_results = int(
            result) if result.strip() else amountOfResults
        clear()
        print(sort_results_msg)
        sort_choice_input = input()
        if sort_choice_input == "1" or not sort_choice_input.strip():
            sort_choice = None
        elif sort_choice_input == "2":
            sort_choice = "date_filed"
        elif sort_choice_input == "3":
            sort_choice = "-date_filed"
        elif sort_choice_input == "4":
            sort_choice = "date_last_filing"
        elif sort_choice_input == "5":
            sort_choice = "-date_last_filing"
        elif sort_choice_input == "6":
            sort_choice = "random"
        else:
            print("Invalid choice. Press ENTER to return to menu.")
            input()
            spreadsheet_generator_menu()
    elif input_preference_choice == "2":
        clear()
        print(
            "Please browse to the CSV file you will use as input. Press ENTER to open file browser."
        )
        input()
        input_csv = file_browser.browseCSVFiles()

    clear()

    default_dir = os.path.join(file_dir, 'data')
    try:
        os.mkdir(default_dir)
    except:
        pass
    print("""
Select which directory you would like to save the data:

[1] Default folder:
    %s

[2] Use a file browser to select the directory.""" % default_dir)
    response = input()
    if not response or response == '1':
        users_output_path = default_dir
    else:
        users_output_path = file_browser.browseDirectories("csv-output")

    if input_preference_choice == "1" or not input_preference_choice:
        generate_spreadsheets.query_to_tables(users_search_query,
                                              users_number_of_results,
                                              users_output_path,
                                              result_order=sort_choice)

    elif input_preference_choice == "2":
        generate_spreadsheets.query_to_tables("",
                                              "",
                                              users_output_path,
                                              input_csv=input_csv)
コード例 #4
0
def welcome():
    """
    The code that executes at launch. It guides the user through menus and starts other functions from the other folders
    based on the users choices.
    """
    clear()
    print(msg)
    print(Style.RESET_ALL)
    print("\n")
    print("Welcome!")
    input("Press ENTER key to begin!")
    clear()
    print(feesNotice)
    input()
    clear()

    # Checks to see if the account information was stored on the local machine previously
    if not os.path.isfile(
            os.path.join(CURRENT_DIR, "sav", "credentials.pickle")):

        # If the user hasn't successfullly logged in before, it takes them to a menu sequence to log in, and saves the info locally
        # for the next time the script is run.
        login.login_interface()

    user = login.Credentials()

    print(f"You are logged in as: {user.username}")
    instructions = """
Instructions:

This program takes in a csv file full of docket numbers and will automatically
populate 2 folders with the raw JSON data and all of the PDF documents associated
with that docket.

You will now select the path where your input csv is located.
Press ENTER to open the file browser.
    """
    print(instructions)
    input()
    clear()

    # Opens a graphical file browser and returns the path to the csv file that the user selected.
    csvChoice = file_browser.browseCSVFiles()

    # Assigns the choice to a global variable, so other modules can find the path that the user specified.
    global_variables.CSV_INPUT_PATH = csvChoice

    options = """
Type in one of the following numbers and press ENTER to specify your choice:

[1] Get all JSON files and PDF files.

[2] Get JSON files only.

[3] Get PDF files only.
    ( Only select 3 if you already have a directory full of JSON files. )
    ( The JSON files are needed to extract the download links from.     )

[4] More options.

Enter your response below.[1/2/3/4]
    """
    print(options)

    def handle_input():
        """
        Prompts the user for a choice and calls the function from the 'modules' folder that corresponds
        with that choice.
        """
        userChoice = input()

        # Choice 1 is downloading all json and pdf files.
        if userChoice == "1":
            clear()
            menus.select_paths_menu()
            clear()
            menus.specify_client_matter_menu()
            print(msg)
            get_json_and_pdfs()
        # Choice 2 is donwloading only JSON files.
        elif userChoice == "2":
            clear()
            menus.select_paths_menu(pdfOption=False)
            menus.specify_client_matter_menu()
            print(msg)
            get_json.thread_download_json()
        # Choice 3 is downloading only PDF files.
        elif userChoice == "3":
            clear()
            menus.select_paths_menu()
            menus.specify_client_matter_menu()
            print(msg)
            link_list = get_pdfs.get_urls("json-output")

            # get_pdfs.multiprocess_download_pdfs(link_list)
            get_pdfs.thread_download_pdfs(link_list)
        elif userChoice == "4":
            clear()
            menus.other_options_menu()

        # If the user enters anything other than a valid choice, then it tells them their choice is invalid and
        # restarts this function, prompting them to make a choice again.
        else:
            print("Please Enter Valid input (1, 2 or 3)")
            return handle_input()

    handle_input()
    try:
        os.startfile(os.path.join(CURRENT_DIR, "log"))
    except:
        pass

    print("\nDone.")
    input()