def voter_information(self, user, form): form['townId'].value = options_dict( form['townId'])[user['city'].upper()] form['firstName'].value = user['first_name'] form['lastName'].value = user['last_name'] (year, month, day) = split_date(user['date_of_birth']) form['Dob'].value = '/'.join([month, day, year]) form['DLNumber'].value = user['state_id_number'] form['email'].value = user['email']
def illinois_identification(self, user): self.browser.open('https://ova.elections.il.gov/Step4.aspx') illinois_identification_form = self.browser.get_form() if user.get('state_id_number'): if user['state_id_number'][0].isalpha(): illinois_identification_form[ 'ctl00$MainContent$tbILDLIDNumber'] = user[ 'state_id_number'][0:4] illinois_identification_form[ 'ctl00$MainContent$tbILDLIDNumber2'] = user[ 'state_id_number'][4:8] illinois_identification_form[ 'ctl00$MainContent$tbILDLIDNumber3'] = user[ 'state_id_number'][8:12] else: raise ValidationError( message= 'A valid Illinois ID number must start with a letter') else: raise ValidationError( message= 'A valid Illinois ID number is required to register to vote online' ) (dob_year, dob_month, dob_day) = split_date(user['date_of_birth']) illinois_identification_form[ 'ctl00$MainContent$tbDOB'].value = '-'.join( [dob_month, dob_day, dob_year]) (id_year, id_month, id_day) = split_date(user['state_id_issue_date']) illinois_identification_form[ 'ctl00$MainContent$tbIDIssuedDate'].value = '-'.join( [id_month, id_day, id_year]) self.browser.submit_form( illinois_identification_form, submit=illinois_identification_form['ctl00$MainContent$btnNext'])
def check_existing(self, user, form): (year, month, day) = split_date(user['date_of_birth']) form['dob'] = '-'.join([month, day, year]) # re-insert dashes, which we removed form['ssn'] = '-'.join( [user['ssn'][0:3], user['ssn'][3:5], user['ssn'][5:9]]) form['driverslicense'] = user['state_id_number'] voter_record = self.lookup_existing_record(form) if voter_record and voter_record['getVoterDataResult'][0]['ctr'] > 0: form['ctr'] = voter_record['getVoterDataResult'][0]['ctr'] else: # TODO, create a new record pass
def personal_information(self, user): personal_info_form = self.browser.get_form() personal_info_form['firstname'].value = user['first_name'] personal_info_form['lastname'].value = user['last_name'] year, month, day = split_date(user['date_of_birth']) personal_info_form['dob'].value = '/'.join([month, day, year]) personal_info_form['ssn3'].value = user['ssn_last4'] personal_info_form['dln'].value = user['state_id_number'] # specify the Continue button, not the "what if I don't know my DL number?" button, also a submit self.browser.submit_form( personal_info_form, submit=personal_info_form['_eventId_continue'], headers=self.get_default_submit_headers())
def identification(self, user): form = self.browser.get_form() form['ctl00$ContentPlaceHolder1$txtStep2FirstName'].value = user[ 'first_name'].upper() form['ctl00$ContentPlaceHolder1$txtStep2LastName'].value = user[ 'last_name'].upper() (year, month, day) = split_date(user['date_of_birth']) form['ctl00$ContentPlaceHolder1$rmtxtStep2DOB'].value = '/'.join( [month, day, year]) form['ctl00$ContentPlaceHolder1$ddlStep2Gender'].value = user[ 'gender'].capitalize() form['ctl00$ContentPlaceHolder1$txtStep2DLID'].value = user[ 'state_id_number'] form['ctl00$ContentPlaceHolder1$rmtxtStep2SSN'].value = user['ssn'] self.browser.submit_form( form, submit=form['ctl00$ContentPlaceHolder1$btnNext_2_19'])
def verify_identification(self, user, form): form['verifyNewVoterForm:voterSearchLastId'].value = user['last_name'] form['verifyNewVoterForm:voterSearchFirstId'].value = user[ 'first_name'] (year, month, day) = split_date(user['date_of_birth']) form['verifyNewVoterForm:voterDOB'].value = '/'.join( [month, day, year]) form['verifyNewVoterForm:driverId'].value = user['state_id_number'] self.browser.submit_form( form, submit=form['verifyNewVoterForm:voterSearchButtonId']) if 'We can\'t find a record that matches your information' in self.browser.response.text: # todo: this really needs to be able to accommodate several fields. self.add_error( 'We could not find your record. Please double-check your first name, last name, date of birth, and driver\'s license number.', field='state_id_number')
def get_started(self, user): form = self.browser.get_form(id='get_started_form') form['first_name'].value = user['first_name'] form['last_name'].value = user['last_name'] # date_of_birth -> parts (year, month, day) = split_date(user['date_of_birth'], padding=False) form['date_of_birth_month'].value = month form['date_of_birth_day'].value = day form['date_of_birth_year'].value = year # street address # can't figure out how to bypass autocomplete, so reassemble parts into string form['address_autocomplete'] = '%(address)s, %(city)s, %(state)s %(zip)s' % user # contact form['email'] = user.get('email') form['mobile_phone'] = user.get('phone') self.browser.submit_form(form)
def personal_information(self, user, form): form = self.browser.get_form("formId") # update form action, this happens in javascript on validateForm form.action = 'reqConsentAndDecline.do' if user.get('has_previous_address'): # change voter registration form['changeType'].value = 'CV' form['_addrChange'].checked = 'checked' # don't actually change registration here, do it later in general information else: # new voter registration form['changeType'].value = 'NV' if user.get('has_previous_name'): form['changeType'].value = 'CV' form['_nmChange'].checked = 'checked' (prev_first, prev_middle, prev_last) = split_name(user.get('previous_name')) form['preFirstName'].value = prev_first form['preLastName'].value = prev_last # county select from list form['county'].value = options_dict( form['county'])[user['county'].upper()] form['lastName'].value = user['last_name'].upper() form['firstName'].value = user['first_name'].upper() (year, month, day) = split_date(user['date_of_birth']) form['dobDate'].value = '/'.join([month, day, year]) form['ddsId'].value = user['state_id_number'] self.browser.submit_form(form, submit=form['next']) return form
def voting_identity(self, user, form): if user.get('privacy_notice'): form['Identity.HasReadPrivacyActNotice'] = "true" else: self.add_error('You must agree to have read the privacy notice', field='privacy_notice') form['Identity.FirstName'].value = user['first_name'] if user.get('middle_name'): form['Identity.MiddleName'].value = user['middle_name'] else: form['Identity.NoMiddleName'] = "true" form['Identity.LastName'].value = user['last_name'] if user.get('suffix'): form['Identity.Suffix'].value = user['suffix'] else: form['Identity.NoSuffix'] = "true" (year, month, day) = split_date(user['date_of_birth']) form['Identity.DateOfBirth'].value = '/'.join([month, day, year]) # values need to be M/F form['Identity.Gender'].value = parse_gender(user['gender']) if user.get('ssn') == "NONE": form['Identity.DoesNotHaveSocialSecurityNumber'] = "true" else: form['Identity.SocialSecurityNumber'] = user.get('ssn') if user.get('state_id_number') and user.get('consent_use_signature'): form['Identity.DmvConsent'] = "Consent" form['Identity.DmvNumber'] = user.get('state_id_number').replace('-', '') elif not user.get('consent_use_signature'): form['Identity.DmvConsent'] = "Decline" elif not user.get('state_id_number'): form['Identity.DmvConsent'] = "DoNotHave" self.browser.submit_form(form)
def rmv_identification(self, user, form): form['ctl00$MainContent$TxtFirstName'].value = user['first_name'] form['ctl00$MainContent$TxtLastName'].value = user['last_name'] (year, month, day) = split_date(user['date_of_birth']) form['ctl00$MainContent$TxtDoB'].value = '/'.join([month, day, year]) form['ctl00$MainContent$TxtRMVID'].value = user['state_id_number'] if user['consent_use_signature']: form['ctl00$MainContent$ChkConsent'].checked = 'checked' form['ctl00$MainContent$ChkConsent'].value = 'on' else: self.add_error( "You must consent to using your signature from the Massachusetts RMV.", field='consent_use_signature') self.browser.submit_form(form, submit=form['ctl00$MainContent$BtnValidate']) if "Your RMV ID cannot be verified" in self.browser.response.text: self.add_error("Your Massachusetts RMV ID cannot be verified.", field='state_id_number')
def step2(self, form, user): # Eligibility form['IsUSCitizen'].value = bool_to_string(user['us_citizen']) if user['will_be_18']: form['RegistrationChoice'].value = '1' # I will be 18 or older by the next election. else: # other options: # form['RegistrationChoice'].value = '2' # I am a 16 or 17 years old and I would like to pre-register to vote. # don't handle this yet, needs update in votebot-api raise ValidationError(message='not eligible', payload={ 'will_be_18': user['will_be_18'], 'date_of_birth': user['date_of_birth'] }) prefix_options = options_dict(form['Prefix']) if 'name_prefix' in user: form['Prefix'].value = prefix_options.get(user['name_prefix']) form['FirstName'].value = user['first_name'] form['MiddleName'].value = user.get('middle_name') form['LastName'].value = user['last_name'] suffix_options = options_dict(form['Suffix']) if 'name_suffix' in user: form['Suffix'].value = suffix_options.get(user['name_suffix']) form['EmailAddress'].value = user.get('email', '') form['ConfirmEmail'].value = user.get('email', '') if user.get('phone'): phone = user.get('phone').replace('+1', '').replace('-', '') form['PhoneNumber'].value = phone # change of name if user.get('has_previous_name'): form['IsPreviouslyRegistered'].checked = 'checked' (prev_first, prev_middle, prev_last) = split_name(user.get('previous_name', '')) form['Previous.FirstName'] = prev_first form['Previous.MiddleName'] = prev_middle form['Previous.LastName'] = prev_last # change of address if user.get('has_previous_adress'): form['IsPreviouslyRegistered'].checked = 'checked' form['Previous.StreetAddress'] = user.get('previous_address', '') form['Previous.ApartmentLotNumber'] = user.get( 'previous_address_unit', '') form['Previous.City'] = user.get('previous_city', '') form['Previous.Zip'] = user.get('previous_zip', '') form['Previous.StateId'] = user.get('previous_state', '') # separate mailing address if user.get('has_separate_mailing_addresss'): form['IsDifferentMailingAddress'].checked = 'checked' mailing_components = get_address_from_freeform( user.get('separate_mailing_address')) form['Mailing.StreetAddress'] = get_street_address_from_components( mailing_components) form[ 'Mailing.ApartmentLotNumber'] = get_address_unit_from_components( mailing_components) form['Mailing.City'] = mailing_components('city_name') form['Mailing.State'] = mailing_components('state_abbreviation') form['Mailing.Zip'] = mailing_components('zipcode') (year, month, day) = split_date(user['date_of_birth'], padding=False) form['MonthOfBirth'].value = month form['DayOfBirth'].value = day form['YearOfBirth'].value = year # ID and last 4 of SSN (CA requires both!) if 'state_id_number' in user: form['CaliforniaID'].value = user.get('state_id_number') else: form['HasNoCaliforniaID'].value = bool_to_string(True) # we actually require this, so shouldn't get here, but just in case if user.get('ssn_last4') == "NONE": form['HasNoSSN'].value = bool_to_string(True) else: form['SSN4'].value = user.get('ssn_last4') # Home and Mailing Address form['Home.StreetAddress'].value = user['address'] form['Home.ApartmentLotNumber'].value = user.get('address_unit') form['Home.City'].value = user['city'] form['Home.Zip'].value = user['zip'] county_options = options_dict(form['Home.CountyId']) try: form['Home.CountyId'].value = county_options.get( user['county'].strip().upper()) except KeyError: raise ValidationError(message='no county match', payload=user['county']) # Ethnicity (optional) if 'ethnicity' in user: ethnicity_options = options_dict(form['EthnicityId']) form['EthnicityId'].value = ethnicity_options.get( user['ethnicity'].upper(), ethnicity_options['OTHER']) # Political Party Preference user["political_party"] = user["political_party"].strip().upper() # they have two inputs with the same name but separated by other elements # so robobrowser's _group_flat_tags creates two entries, which their server won't validate form.fields.pop('PoliticalPreferenceType') # recreate with just one PoliticalPreferenceType = Input( "<input type='radio' name='PoliticalPreferenceType'/>") PoliticalPreferenceType.options = ['1', '2'] form.add_field(PoliticalPreferenceType) if user['political_party'].lower( ) == 'independent' or user['political_party'].lower() == "none": PoliticalPreferenceType.value = '2' PoliticalPreferenceType.checked = 'checked' # also delete the politcal party select form.fields.pop('PoliticalPartyId') else: # mess with the DOM to un-disable Political Party del self.browser.select( 'select[name="PoliticalPartyId"]')[0]['disabled'] PoliticalPreferenceType.value = '1' PoliticalPreferenceType.checked = 'checked' party_options = options_dict(form['PoliticalPartyId']) # do fuzzy match to political party options party_choice = get_party_from_list(user['political_party'], party_options.keys()) if party_choice in party_options.keys(): form['PoliticalPartyId'].value = party_options[party_choice] else: form['PoliticalPartyId'].value = party_options.get('Other') form['OtherPoliticalParty'].value = user['political_party'] self.submit_form_field(form, 'GoToNext')