Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:scrapd/scrapd into issues/106/dec…
Browse files Browse the repository at this point in the history
…eased-field
  • Loading branch information
anthonybaulo committed Jun 7, 2019
2 parents 6e02e7d + 9b9174c commit 555c3b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
4 changes: 1 addition & 3 deletions scrapd/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@
show_default=True,
)
@click.option('--from', 'from_', help='start date')
@click.option('--gcontributors', help='comma separated list of contributors')
@click.option('--gcredentials', type=click.Path(), help='path of the google credentials file')
@click.option('--pages', default=-1, help='number pages to process')
@click.option('--to', help='end date')
@click.option('-v', '--verbose', count=True, help='adjust the log level')
@click.pass_context
def cli(ctx, format_, from_, gcontributors, gcredentials, pages, to, verbose): # noqa: D403
def cli(ctx, format_, from_, pages, to, verbose): # noqa: D403
"""Retrieve APD's traffic fatality reports."""
ctx.obj = {**ctx.params}
ctx.auto_envvar_prefix = 'VZ'
Expand Down
16 changes: 14 additions & 2 deletions scrapd/core/apd.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,13 @@ def parse_name(name):
:return: a dictionary representing just the victim's first and last name
:rtype: dict
"""
GENERATIONAL_TITLES = ['jr', 'jr.', 'sr', 'sr.']
d = {}
try:
d["last"] = name[-1].replace(',', '')
for i in range(1, len(name)):
d["last"] = name[-i].replace(',', '')
if d["last"].lower() not in GENERATIONAL_TITLES:
break
d["first"] = name[0].replace(',', '')
except (IndexError, TypeError):
pass
Expand Down Expand Up @@ -742,7 +746,15 @@ async def fetch_and_parse(session, url):


async def async_retrieve(pages=-1, from_=None, to=None):
"""Retrieve fatality data."""
"""
Retrieve fatality data.
:param str pages: number of pages to retrieve or -1 for all
:param str from_: the start date
:param str to: the end date
:return: the list of fatalities and the number of pages that were read.
:rtype: tuple
"""
res = {}
page = 1
has_entries = False
Expand Down
6 changes: 5 additions & 1 deletion tests/core/test_apd.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,11 @@ def test_parse_deceased_field_00(deceased, expected):
}),
(None, {
'first': None,
'last': None
'last': None,
}),
(['Carlos', 'Cardenas', 'Jr.'], {
'first': 'Carlos',
'last': 'Cardenas',
}),
))
def test_parse_name(name, expected):
Expand Down

0 comments on commit 555c3b9

Please sign in to comment.