Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update fork #1

Merged
merged 35 commits into from Nov 2, 2016
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cf756ad
return blank on error
mlambright Oct 24, 2014
e2ae14c
skip geocode if error
mlambright Oct 24, 2014
7feb5d1
add Kentucky
mlambright Oct 24, 2014
c3ab935
add support for st lucie and lake counties
mlambright Oct 24, 2014
793d9d0
add starting Texas
mlambright Oct 25, 2014
5c0c249
add Dallas county
mlambright Oct 25, 2014
9ce5e91
texas with dallas
mlambright Oct 25, 2014
1954e3d
remove unnecessary function
mlambright Oct 25, 2014
33a00ba
add SC
mlambright Oct 25, 2014
b423d6f
add beginning WV
mlambright Oct 25, 2014
f9ff8ae
update wv
mlambright Oct 25, 2014
bca3d69
remove leftover hidden fields
mlambright Oct 25, 2014
ab0fc85
last attempt with session
mlambright Oct 25, 2014
281d815
fixed button
mlambright Oct 25, 2014
b295390
fix submit button
mlambright Oct 26, 2014
84b6366
add sleep
mlambright Oct 26, 2014
00cf8a9
Merge branch 'wv'
mlambright Oct 26, 2014
a78a2c2
add EPC
mlambright Oct 27, 2014
dd55a38
add Denton county
mlambright Oct 27, 2014
febb6ee
fix denton odditites
mlambright Oct 27, 2014
1850308
add NM
mlambright Oct 29, 2014
e454840
add hidalgo county
mlambright Oct 29, 2014
bcacd73
add fort bend county
mlambright Oct 29, 2014
53d7262
add montgomery
mlambright Oct 29, 2014
884de37
add Jefferson county
mlambright Oct 29, 2014
4080499
allow precincts without pps
mlambright Oct 29, 2014
1d17422
collect NM precincts
mlambright Oct 30, 2014
798bfea
fix precincts
mlambright Oct 30, 2014
5bb6544
add election-day tool which only pulls precincts
mlambright Nov 2, 2014
81fd1c9
working election-day sites
mlambright Nov 2, 2014
ee2d7fc
collect pp list url where available
mlambright Nov 2, 2014
f305d0a
add main and VIP readmes
mlambright Nov 2, 2014
6fa1e95
add main and VIP readmes
mlambright Nov 2, 2014
64d696a
add DECC readme
mlambright Nov 2, 2014
c2c823f
fix readme
mlambright Nov 2, 2014
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

add SC

  • Loading branch information
mlambright committed Oct 25, 2014
commit 33a00bab341b9c7abb187f13cb4b8d008a3cc3a7
@@ -21,8 +21,8 @@
'NH': 'New Hampshire', 'TN': 'Tennessee', 'LA': 'Louisiana',
'IL': 'Illinois', 'IN': 'Indiana', 'ID': 'Idaho', 'GA': 'Georgia',
'MA': 'Massachusetts', 'SD': 'South Dakota', 'VT': 'Vermont',
'FL': 'Florida', 'MS': 'Mississippi', 'KY': 'Kentucky',
'TX': 'Texas'}
'FL': 'Florida', 'MS': 'Mississippi', 'KY': 'Kentucky',
'TX': 'Texas', 'SC': 'South Carolina'}

scope1 = 'https://spreadsheets.google.com/feeds'
scope2 = 'https://www.googleapis.com/auth/drive'
@@ -0,0 +1,85 @@
from bs4 import BeautifulSoup
from requests import Session


def getValues(row):
fname = row['tsmart_first_name']
lname = row['tsmart_last_name']
county = row['vf_county_name']
dobStr = row['voterbase_dob']
dob = '{0}/{1}/{2}'.format(int(dobStr[4:6]), int(dobStr[6:8]),
int(dobStr[:4]))
return fname, lname, dob, county


def getCounties(soup):
counties = {}
selectName = 'ctl00$cphMain$ddlCounty$input'
select = soup.find('select', {'name': selectName})
for item in select.find_all('option'):
counties[item.text.strip().upper()] = item.get('value')
return counties


def getOutputValues(soup):
ppid = ''
name = ''
address = ''
baseName = 'ctl00_cphMain_VoterInfoUserControl_{0}_DisplayOnly'
ppidSoup = soup.find('span', {'id': baseName.format('VotingPrecinctControl')})
nameSoup = soup.find('span', {'id': baseName.format('PrecinctLocationControl')})
addressSoup = soup.find('span', {'id': baseName.format('PrecinctAddress')})
if ppidSoup is not None:
ppid = ppidSoup.get_text().strip()
name = nameSoup.get_text().strip()
address = addressSoup.get_text().strip()
return ppid, name, address


def getHiddenValues(soup):
form = soup.find('form', {'name': 'aspnetForm'})
fields = {}
for item in form.find_all('input', {'type': 'hidden'}):
fields[item.get('name')] = item.get('value')
fields['hiddenInputToUpdateATBuffer_CommonToolkitScripts'] = '1'
fields['ctl00$pnlMenu_CollapsiblePanelExtender_ClientState'] = 'true'
fields['ctl00$AccordionStateBoardMenu_AccordionExtender_ClientState'] = 0
fields['ctl00$mtbSearch'] = ''
return fields


def query(fname, lname, dob, county, fields, counties, formURL, session):
resultsURL = 'https://info.scvotes.sc.gov/Eng/VoterInquiry/'
resultsURL += 'VoterInformation.aspx'
county = counties[county.upper()]
fields['ctl00$cphMain$txtFirstName$input'] = fname
fields['ctl00$cphMain$txtLastName$input'] = lname
fields['ctl00$cphMain$dobDateOfBirth$input'] = dob
fields['ctl00$cphMain$ddlCounty$input'] = county
fields['ctl00$buttonContent$txtHiddenCountyValue'] = county
fields['ctl00$buttonContent$btnSubmit'] = 'Submit'
session.post(formURL, data=fields)
response = session.get(resultsURL)
html = response.text
return html


def run(row):
formURL = 'https://info.scvotes.sc.gov/eng/voterinquiry/'
formURL += 'VoterInformationRequest.aspx?PageMode=VoterInfo'
try:
session = Session()
fname, lname, dob, county = getValues(row)
response = session.get(formURL)
soup = BeautifulSoup(response.text)
hiddenFields = getHiddenValues(soup)
counties = getCounties(soup)
html = query(fname, lname, dob, county, hiddenFields, counties,
formURL, session)
soup = BeautifulSoup(html)
pollingInfo = getOutputValues(soup)
return pollingInfo
except Exception as inst:
print type(inst)
print inst
return '', '', ''
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.