Web scraper for race results hosted on Athlinks.
Project description
athlinks_races: web scraper for race results hosted on Athlinks
NOTE
This is a fork of the original scrapy-athlinks. I decided to take over as I want to add features that were not originally available on the project.
Introduction
athlinks_races provides the RaceSpider class.
This spider crawls through all results pages from a race hosted on athlinks.com, building and following links to each athlete's individual results page, where it collects their split data. It also collects some metadata about the race itself.
By default, the spider returns one race metadata object (RaceItem), and one AthleteItem per participant.
Each AthleteItem consists of some basic athlete info and a list of RaceSplitItem containing data from each
split they recorded.
How to use this package
Using uv
If you have installed uv, is as simple as this:
uvx --from athlinks-races athlinks_races_cli --tui --race_url https://www.athlinks.com/event/382111/results/Event/1093108/Results
python scripts
Scrapy can be operated entirely from python scripts. See the scrapy documentation for more info.
Installation
The package is available on PyPi and can be installed with pip:
python -m venv "$HOME/virtualenv/athlinks_races/"
. $HOME/virtualenv/athlinks_races/bin/activate
pip install athlinks_races
Example usage
A demo script is included in this repo. It has plenty of features but is also monolithic on purpose.
"""
Demonstrate the available classes.
You can run as python athlinks_races/demo.py
"""
from scrapy.crawler import CrawlerProcess
from athlinks_races import RaceSpider, AthleteItem, RaceItem
def main():
# Make settings for two separate output files: one for athlete data,
# one for race metadata.
settings = {
'FEEDS': {
# Athlete data. Inside this file will be a list of dicts containing
# data about each athlete's race and splits.
'athletes.json': {
'format': 'json',
'overwrite': True,
'item_classes': [AthleteItem],
},
# Race metadata. Inside this file will be a list with a single dict
# containing info about the race itself.
'metadata.json': {
'format': 'json',
'overwrite': True,
'item_classes': [RaceItem],
},
}
}
process = CrawlerProcess(settings=settings)
# Crawl results for the 2022 Leadville Trail 100 Run
process.crawl(RaceSpider, 'https://www.athlinks.com/event/33913/results/Event/1018673/')
process.start()
if __name__ == "__main__":
main()
If you do a pip install --editable .[lint,dev] then you can run as
athlinks_cli
Then you can build the wheelhouse to install locally if needed:
python -m build .
Command line
Alternatively, you may clone this repo for use like a typical Scrapy project that you might create on your own.
Installation
python -m venv `$HOME/virtualenv/athlink_races`
. $HOME/virtualenv/athlink_races/bin/activate
git clone https://github.com/josevnz/athlinks-races
cd athlink-races
python install --editable .[lint,dev]
Example usage
Run a RaceSpider, few races with different years:
cd athlinks_races
scrapy crawl race -a url=https://www.athlinks.com/event/33913/results/Event/1018673 -O $HOME/1018673.json
scrapy crawl race -a url=https://www.athlinks.com/event/382111/results/Event/1093108 -O $HOME/1093108.json
scrapy crawl race -a url=https://www.athlinks.com/event/382111/results/Event/1062909 -O $HOME/1093108.json
Or the newer thlinks_races_cli, with the --tui argument:
(athlinks-races) [josevnz@dmaf5 athlinks_races]$ athlinks_races_cli --tui
2025-01-12 14:56:31 [scrapy.middleware] INFO: Enabled item pipelines:
[]
2025-01-12 14:56:31 [scrapy.core.engine] INFO: Spider opened
2025-01-12 14:56:31 [scrapy.extensions.logstats] INFO: Crawled 0 pages (at 0 pages/min), scraped 0 items (at 0 items/min)
2025-01-12 14:56:31 [scrapy.extensions.telnet] INFO: Telnet console listening on 127.0.0.1:6023
2025-01-12 14:56:31 [asyncio] DEBUG: Using selector: EpollSelector
Dependencies
All that is required is Scrapy and Textual (and its dependencies).
Testing
. $HOME/virtualenv/athlink_races/bin/activate
pytest tests/*.py
Example session:
(athlinks_races) [josevnz@dmaf5 athlinks_races]$ pytest /home/josevnz/athlinks_races/tests/tests.py
============================================================= test session starts =============================================================
platform linux -- Python 3.11.6, pytest-8.3.3, pluggy-1.5.0
rootdir: /home/josevnz/athlinks_races
configfile: pyproject.toml
collected 6 items
tests/tests.py ...... [100%]
============================================================== 6 passed in 0.33s ==============================================================
License
This project is licensed under the MIT License. See LICENSE file for details.
Contact
You can get in touch with me here:
- GitHub: https://github.com/josevnz
Original Author
If you want to take a look at the original project. He is not in charge of this forked version.
- GitHub: github.com/aaron-schroeder
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file athlinks_races-0.0.7.tar.gz.
File metadata
- Download URL: athlinks_races-0.0.7.tar.gz
- Upload date:
- Size: 18.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ecacc15e7d6b13069afe0df7232268264ff45e360b464b4cbb4b03d207fbd7f
|
|
| MD5 |
ef62739cd17f44a77929ed450737315e
|
|
| BLAKE2b-256 |
2fe29055df6c68c8dde2b82433282ab27975e00ba34495e55dae5c305bfb29ba
|
File details
Details for the file athlinks_races-0.0.7-py3-none-any.whl.
File metadata
- Download URL: athlinks_races-0.0.7-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efdc72e347107cc32de1895961b7f813e6044d4927d33a019aaeca0a83156bd2
|
|
| MD5 |
18c4597248144c8da45b0ce63dba8cff
|
|
| BLAKE2b-256 |
310065e876248da20cf1d46d4132ce40adf022550ff5d2fc4dfbe26881b5efde
|