CurlingZone scraper API.
Project description
Welcome to czapi
A basic API for scraping curling boxscores off of the popular CurlingZone website.
Install
pip install czapi
How to use
import czapi.api as api
General Information
The czapi is based around the LinescorePage object which represents a linescore page, shown below:
Creating an instance of the LinescorePage class gives access to every boxscore on that linescore page.
linescore_page = api.LinescorePage(cz_event_id = 6400, cz_draw_id = 2)
The boxscores on the linescore page can be accessed through the boxscores
property which returns a list of boxscores.
linescore_page.boxscores
[defaultdict(list,
{'Wayne Tuck Jr.': defaultdict(list,
{'href': 'event.php?view=Team&eventid=6400&teamid=144353&profileid=12486#1',
'hammer': True,
'score': ['0',
'2',
'0',
'0',
'0',
'0',
'1',
'1',
'1',
'0'],
'finalscore': '5'}),
'Matthew Hall': defaultdict(list,
{'href': 'event.php?view=Team&eventid=6400&teamid=144347&profileid=12435#1',
'hammer': False,
'score': ['0',
'0',
'4',
'0',
'0',
'1',
'0',
'0',
'0',
'2'],
'finalscore': '7'})}),
defaultdict(list,
{'Dayna Deruelle': defaultdict(list,
{'href': 'event.php?view=Team&eventid=6400&teamid=144346&profileid=26636#1',
'hammer': False,
'score': ['0',
'0',
'1',
'0',
'0',
'0',
'0',
'X',
'',
''],
'finalscore': '1'}),
'Tyler Stewart': defaultdict(list,
{'href': 'event.php?view=Team&eventid=6400&teamid=144352&profileid=12477#1',
'hammer': True,
'score': ['0',
'2',
'0',
'2',
'1',
'1',
'4',
'X',
'',
''],
'finalscore': '10'})}),
defaultdict(list,
{'Mark Kean': defaultdict(list,
{'href': 'event.php?view=Team&eventid=6400&teamid=144348&profileid=25961#1',
'hammer': True,
'score': ['2',
'0',
'1',
'0',
'0',
'0',
'1',
'3',
'X',
''],
'finalscore': '7'}),
'Jason March': defaultdict(list,
{'href': 'event.php?view=Team&eventid=6400&teamid=144350#1',
'hammer': False,
'score': ['0',
'0',
'0',
'0',
'2',
'1',
'0',
'0',
'X',
''],
'finalscore': '3'})}),
defaultdict(list,
{'Richard Krell': defaultdict(list,
{'href': 'event.php?view=Team&eventid=6400&teamid=144349&profileid=25962#1',
'hammer': True,
'score': ['2',
'0',
'1',
'0',
'2',
'1',
'1',
'X',
'',
''],
'finalscore': '7'}),
'Rob Ainsley': defaultdict(list,
{'href': 'event.php?view=Team&eventid=6400&teamid=144345&profileid=15779#1',
'hammer': False,
'score': ['0',
'0',
'0',
'1',
'0',
'0',
'0',
'X',
'',
''],
'finalscore': '1'})})]
A boxscore is returned as a dictionary of team names, game information dictionary key, value pairs.
Each game information dictionary contains:
- 'href' key with a corresponding string value of CurlingZone IDs identifying the team.
- 'hammer' key with corresponding boolean value of whether or not that team started the game with hammer.
- 'score' key with corresponding list of string value of end-by-end results for that team.
- 'finalscore' key with corresponding final score for the team.
Individual boxscores can be accessed through the get_boxscore_from
method.
boxscore = linescore_page.get_boxscore_from(cz_game_id = 1)
boxscore
defaultdict(list,
{'Wayne Tuck Jr.': defaultdict(list,
{'href': 'event.php?view=Team&eventid=6400&teamid=144353&profileid=12486#1',
'hammer': True,
'score': ['0',
'2',
'0',
'0',
'0',
'0',
'1',
'1',
'1',
'0'],
'finalscore': '5'}),
'Matthew Hall': defaultdict(list,
{'href': 'event.php?view=Team&eventid=6400&teamid=144347&profileid=12435#1',
'hammer': False,
'score': ['0',
'0',
'4',
'0',
'0',
'1',
'0',
'0',
'0',
'2'],
'finalscore': '7'})})
cz_game_id
argument corresponds to the number the boxscore appears in on the linescore page.
The LinescorePage object contains these properties which details information on the boxscores:
- event_name
- event_date
- draw
print(linescore_page.event_name,',',linescore_page.event_date,',' ,linescore_page.draw)
Ontario Tankard - Open Qualifier , Jan 17 - 19, 2020 , Draw: 2
The boxscore dictionary can be flattened into a list of lists using the flatten_boxscore
helper function.
api.flatten_boxscore(boxscore=boxscore)
[['Wayne Tuck Jr.',
'event.php?view=Team&eventid=6400&teamid=144353&profileid=12486#1',
True,
['0', '2', '0', '0', '0', '0', '1', '1', '1', '0'],
'5'],
['Matthew Hall',
'event.php?view=Team&eventid=6400&teamid=144347&profileid=12435#1',
False,
['0', '0', '4', '0', '0', '1', '0', '0', '0', '2'],
'7']]
About czapi
czapi is a Python library for scraping curling linescores.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.