Skip to content

Commit

Permalink
Merge pull request #49 from justjasongreen/scrape_horse
Browse files Browse the repository at this point in the history
Fix Invalid Foaled Dates (fixes #48)
  • Loading branch information
justjasongreen committed Jul 26, 2016
2 parents 4b2a319 + 0115bcb commit 74bb063
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).


## [Unreleased]

### Fixed

- Fix parsing of missing foaled dates when scraping horses (from @justjasongreen)


## [1.0.0b6] - 2016-07-25

### Fixed
Expand Down
5 changes: 4 additions & 1 deletion punters_client/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ def parse_name(html):
elif label == 'foaled':
value = get_child_text(row, 'td')
if value is not None:
profile['foaled'] = self.SOURCE_TIMEZONE.localize(datetime.strptime(value, '%d/%m/%Y'))
try:
profile['foaled'] = self.SOURCE_TIMEZONE.localize(datetime.strptime(value, '%d/%m/%Y'))
except (TypeError, ValueError):
profile['foaled'] = None

return profile

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ first_value = 1

[pytest]
flake8-ignore =
*.py E241
tests/* E501
flake8-max-line-length = 120

11 changes: 11 additions & 0 deletions tests/scraper/scrape_horse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ def test_expected_values(expected_values, scraped_values):
"""The scrape_horse method should return a dictionary containing all expected values"""

assert scraped_values == expected_values


def test_invalid_foaled_date(scraper):

runner = {
'horse_url': 'https://www.punters.com.au/horses/Bonner_152493/'
}

horse = scraper.scrape_horse(runner)

assert horse['foaled'] is None

0 comments on commit 74bb063

Please sign in to comment.