Example #1
0
 def get_recipients(self, state, county):
     if state != None:
         if county != None:
             recv = recipients.get_county(state, county)
         else:
             recv = recipients.get_state(state)
     else:
         recv = recipients.get_all()
     return recv
Example #2
0
def prompt_recipients():
    print("\nWhich state officials do you want to send emails to?\n")
    state_options = { v:k for v,k in enumerate(recipients.get_states()) }
    for idx, opt in state_options.items():
        print(idx, "->", opt)
    
    state_idx = input("\nType the number corresponding to the state here (if blank, all states will be used): ")
    
    if state_idx:
        county_options = { v:k for v,k in enumerate(recipients.get_counties(state_options[int(state_idx)])) }
        print("\nWhich county officials do you want to send emails to?\n")
        for idx, opt in county_options.items():
            print(idx, "->", opt)
        county_idx = input("\nType the number corresponding to the county here (if blank, all counties will be used): ")
    
        if county_idx:
            recv = recipients.get_county(state_options[int(state_idx)], county_options[int(county_idx)])
        else:
            recv = recipients.get_state(state_options[int(state_idx)])
    
    else:
        recv = recipients.get_all()
    return recv
Example #3
0
def prompt_recipients():
    recv = set()
    cart = set()

    # Choose a state
    while True:
        print_barrier()
        print("Which state officials do you want to send emails to?")
        if cart: print(f'Cities chosen: {cart}\n')
        state_options = { v:k for v,k in enumerate(recipients.get_states()) }
        for idx, opt in state_options.items():
            print(idx, "->", opt)
        print("Enter blank (nothing) when done.")
        
        state_idx = input("\nType the number corresponding to the state here: ")
        print_barrier()
        # Blank -> Done
        if not state_idx:
            break
        # 0 -> All States
        elif int(state_idx) == 0:
            recv.update(recipients.get_all())
            break
        # (1 to N) -> Individual States
        elif int(state_idx) in state_options.keys():
            state = state_options[int(state_idx)]
            subcart = set()

            # Choose a city
            while True:
                city_options = { v:k for v,k in enumerate(recipients.get_cities(state)) }
                print_barrier()
                print("Which city officials do you want to send emails to?")
                if subcart: print(f'Cities chosen: {subcart}\n')
                for idx, opt in city_options.items():
                    print(idx, "->", opt)
                print("Enter blank (nothing) when done.")
                city_idx = input("\nType the number corresponding to the city here: ")
        
                if not city_idx:
                    break
                elif int(city_idx) == 0:
                    subcart.update(recipients.get_cities(state))
                    subcart.remove('Select All')
                    recv.update(recipients.get_state(state))
                    break
                elif int(city_idx) in city_options.keys():
                    subcart.add(city_options[int(city_idx)])
                    recv.update(recipients.get_city(state, city_options[int(city_idx)]))
                else:
                    print("Invalid index")
            # Add (city, state) to cart)
            for city in subcart:
                cart.add("%s, %s" % (city, states.abbreviate(state)))
            print_barrier()
        
        else:
            print("Invalid index")
    print_barrier()

    if not recv:
        sys.exit("ABORT: no recipients selected.")

    print(f'\n{len(recv)} recipients selected.\n')

    return recv
Example #4
0
def prompt_recipients():
    recv = set()
    cart = set()
    more_state = True

    # Choose a state
    while more_state:
        more_city = True
        print("\nWhich STATE officials do you want to send emails to?")
        state_options = {v: k for v, k in enumerate(recipients.get_states())}
        for idx, opt in state_options.items():
            print(idx, "->", opt)
        print("Don't input anything and press 'Enter' when done. \n")

        if len(cart) > 0:
            print(f'Cities chosen: {cart}')
        state_idx = input(
            "\nType the number corresponding to the STATE here "
            "(Don't input anything and press 'Enter' when done): ")

        if len(str(state_idx)) == 0:
            more_state = False
        elif int(state_idx) == 0:
            cart.update(recipients.get_states())
            cart.remove('Select All')
            for state in cart:
                recv.update(recipients.get_state(state))
            more_state = False
        else:
            # 0 -> All States
            if int(state_idx) == 0:
                recv.update(recipients.get_all())
            # (1 to N) -> Individual States
            elif int(state_idx) in state_options.keys():
                state = state_options[int(state_idx)]
                subcart = set()

                # Choose a city
                while more_city:
                    city_options = {
                        v: k
                        for v, k in enumerate(recipients.get_cities(state))
                    }

                    # Print question for city
                    print(
                        "\nWhich CITY officials do you want to send emails to?"
                    )
                    for idx, opt in city_options.items():
                        print(idx, "->", opt)
                    print(
                        "Don't input anything and press 'Enter' when done. \n")

                    # Ask user and print confirmation of cities
                    if subcart:
                        print(f'Cities chosen: {subcart}')
                    city_idx = input(
                        "\nType the number corresponding to the CITY here (Don't input anything and "
                        "press 'Enter' when done): ")

                    # get out of loop or get the city
                    if len(str(city_idx)) == 0:
                        more_city = False
                    else:
                        if int(city_idx) == 0:
                            subcart.update(recipients.get_cities(state))
                            subcart.remove('Select All')
                            recv.update(recipients.get_state(state))
                        elif int(city_idx) in city_options.keys():
                            subcart.add(city_options[int(city_idx)])
                            recv.update(
                                recipients.get_city(
                                    state, city_options[int(city_idx)]))
                        else:
                            print(
                                "\033[1;31;48mWe don't have that CITY number. Please input the correct number"
                            )
                            print("\033[1;37;48m")
                        for city in subcart:
                            cart.add("%s, %s" %
                                     (city, states.abbreviate(state)))
                        print(f'{len(recv)} recipients selected.\n')
            else:
                print(
                    "\033[1;31;48mWe don't have that STATE number. Please input the correct number"
                )
                print("\033[1;37;48m")
    print("\033[1;32;48m\nYou have chosen " + str(len(recv)) + " recipients")
    print("\033[1;37;48m")

    return recv