Code Monkey home page Code Monkey logo

firstcyclingapi's Introduction

First Cycling API

Documentation Status GitHub license GitHub Repo stars

An unofficial Python API wrapper for https://firstcycling.com/.

Usage

The API wrapper currently supports the following endpoints:

  • Race pages
  • Rider pages
  • Rankings pages

A few examples are shown below.

For full documentation, see https://firstcyclingapi.readthedocs.io/en/latest/.

Race Results:

>>> from first_cycling_api import RaceEdition
>>> amstel_2019 = RaceEdition(race_id=9, year=2019) # The race_id comes from the race page URL
>>> amstel_2019.results().results_table.head() # A pandas DataFrame of the race results
Pos Rider Team Time UCI Rider_ID Rider_Country Team_ID
0 01 van der Poel Mathieu Corendon - Circus 6:28:18 500 16672 NED 13279
1 02 Clarke Simon EF Education First + 00 400 568 AUS 13208
2 03 Fuglsang Jakob Astana Pro Team + 00 325 264 DEN 13198
3 04 Alaphilippe Julian Deceuninck - Quick Step + 00 275 12474 FRA 13206
4 05 Schachmann Maximilian Bora - Hansgrohe + 00 225 16643 GER 13200

Rider Results:

>>> from first_cycling_api import Rider
>>> roglic = Rider(18655) # The rider ID comes from the rider page URL
>>> roglic.year_results(2020).results_df.head() # A pandas DataFrame of Roglic's 2020 results
Date Pos GC Race_Country Race CAT UCI Unnamed: 8 Race_ID
0 8.11 1 nan ESP Vuelta a España 2.UWT 850 Show more 23
1 4.1 1 nan BEL Liège-Bastogne-Liège 1.UWT 500 Show more 11
2 20.09 2 nan FRA Tour de France 2.UWT 800 Show more 17
3 27.09 6 nan UCI World Championship RR WCRR 225 Show more 26
4 9.08 1 nan FRA Tour de l'Ain 2.1 125 Show more 63

Rankings Pages:

>>> from first_cycling_api import Ranking
>>> ranking = Ranking(h=1, rank=1, y=2020, page=2) # Parameters from corresponding URL
>>> ranking.table.head() # A pandas DataFrame of the rankings table
Pos Rider Nation Team Points Rider_ID Team_ID Team_Country
0 101 Egan Bernal Colombia INEOS Grenadiers 425 58275 17536 GBR
1 102 Bauke Mollema Netherlands Trek-Segafredo 420 581 17540 USA
2 103 Tim Declercq Belgium Deceuninck-Quick Step 415 1970 17529 BEL
3 104 Oliver Naesen Belgium AG2R La Mondiale 411 22682 17524 FRA
4 105 Alex Aranburu Spain Astana Pro Team 410 27307 17525 KAZ

Contributing

Contributions are welcome! Please feel free to open issues, pull requests, and/or discussions.

Especially, there is room to help with:

  • Mapping additional endpoints (e.g. pages starting with https://firstcycling.com/team.php?)
  • Parsing results from additional pages (e.g. race startlists, race statistics)

To run tests, first pip install pytest and pip install vcrpy. Then run py.test in a shell from the root directory.

License

See the file called LICENSE. This project is not affiliated in any way with firstcycling.com.

firstcyclingapi's People

Contributors

baronet2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

firstcyclingapi's Issues

KeyError: "None of ['Information'] are in the columns"

Discussed in #17

Originally posted by bfransol June 4, 2022
Hello,
I'm currently trying to use this repository for my studies, however I get the following error whent trying to retreive data from Rider.

code:

from first_cycling_api import Rider
roglic = Rider(16672)
print(roglic.best_results())

error:

Traceback (most recent call last):
  File "C:/Users/2de Master/Predictive and Prescriptive Analytics/FirstCyclingAPI-main/ExtractData.py", line 10, in <module>
    print(roglic.best_results())
  File "C:\Users\2de Master\Predictive and Prescriptive Analytics\FirstCyclingAPI-main\first_cycling_api\rider\rider.py", line 43, in best_results
    return self._get_endpoint(high=1)
  File "C:\Users\2de Master\Predictive and Prescriptive Analytics\FirstCyclingAPI-main\first_cycling_api\objects.py", line 25, in _get_endpoint
    return endpoint(response)
  File "C:\Users\2de Master\Predictive and Prescriptive Analytics\FirstCyclingAPI-main\first_cycling_api\endpoints.py", line 39, in __init__
    self._parse_result()
  File "C:\Users\2de Master\Predictive and Prescriptive Analytics\FirstCyclingAPI-main\first_cycling_api\endpoints.py", line 43, in _parse_result
    self._parse_soup()
  File "C:\Users\2de Master\Predictive and Prescriptive Analytics\FirstCyclingAPI-main\first_cycling_api\rider\endpoints.py", line 25, in _parse_soup
    self._get_sidebar_details()
  File "C:\Users\2de Master\Predictive and Prescriptive Analytics\FirstCyclingAPI-main\first_cycling_api\rider\endpoints.py", line 44, in _get_sidebar_details
    details = pd.Series(details_df.set_index('Information')['Information.1'])
  File "C:\Users\anaconda3\lib\site-packages\pandas\util\_decorators.py", line 311, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\anaconda3\lib\site-packages\pandas\core\frame.py", line 5451, in set_index
    raise KeyError(f"None of {missing} are in the columns")
KeyError: "None of ['Information'] are in the columns"

I was wondering if someone could help me out with it.
Thanks in advance!

Seems to no longer work

When I run py.test in the root directory I get the following result.

Python version is 3.9.7

================================================= test session starts ==================================================
platform darwin -- Python 3.9.7, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /Users/admin/Documents/GitHub/FirstCyclingAPI
plugins: anyio-2.2.0
collected 0 items / 3 errors

======================================================== ERRORS ========================================================
_________________________________________ ERROR collecting tests/test_race.py __________________________________________
ImportError while importing test module '/Users/admin/Documents/GitHub/FirstCyclingAPI/tests/test_race.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../opt/anaconda3/lib/python3.9/importlib/init.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/test_race.py:1: in
from first_cycling_api import Race, RaceEdition
first_cycling_api/init.py:8: in
from .rider import Rider
first_cycling_api/rider/init.py:23: in
from .rider import Rider
first_cycling_api/rider/rider.py:3: in
from ..api import fc
first_cycling_api/api.py:8: in
from slumber import API
E ModuleNotFoundError: No module named 'slumber'
________________________________________ ERROR collecting tests/test_ranking.py ________________________________________
ImportError while importing test module '/Users/admin/Documents/GitHub/FirstCyclingAPI/tests/test_ranking.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../opt/anaconda3/lib/python3.9/importlib/init.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/test_ranking.py:1: in
from first_cycling_api import Ranking
first_cycling_api/init.py:8: in
from .rider import Rider
first_cycling_api/rider/init.py:23: in
from .rider import Rider
first_cycling_api/rider/rider.py:3: in
from ..api import fc
first_cycling_api/api.py:8: in
from slumber import API
E ModuleNotFoundError: No module named 'slumber'
_________________________________________ ERROR collecting tests/test_rider.py _________________________________________
ImportError while importing test module '/Users/admin/Documents/GitHub/FirstCyclingAPI/tests/test_rider.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
../../../opt/anaconda3/lib/python3.9/importlib/init.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/test_rider.py:1: in
from first_cycling_api import Rider
first_cycling_api/init.py:8: in
from .rider import Rider
first_cycling_api/rider/init.py:23: in
from .rider import Rider
first_cycling_api/rider/rider.py:3: in
from ..api import fc
first_cycling_api/api.py:8: in
from slumber import API
E ModuleNotFoundError: No module named 'slumber'
=============================================== short test summary info ================================================
ERROR tests/test_race.py
ERROR tests/test_ranking.py
ERROR tests/test_rider.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 3 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================== 3 errors in 15.89s ==================================================

Installing the Library

Hey there, just wondering if this library is available on PyPi? I don't see anything in the docs about how to install this library.

Convert endpoints to properties

Returning Endpoint instances rather than storing these as properties introduces unnecessary complexity to the Rider and Race sections. It would be better to return the relevant result directly, or return the raw response if it is not being parsed.

For example,Race(XX).victory_table().table should become Race(XX).victory_table.

Such calls should automatically update properties common to all endpoints of that instance, such as Race(XX).header_details. To avoid losing data, all raw responses should be accessible somehow.

Where we accept parameters for the methods, we can separate these into separate attributes or use dictionary syntax instead. For example, Rider(XX).year_results(2020).results_df should become Rider(XX).year_results[2020].

Parse details in rider sidebar

As identified in #17 , due to a recent change to the website layout, the old code to parse the sidebar information on rider pages no longer works. It would be nice to bring back this functionality.

RaceEditionResults endpoint broken

Hi, thx for the library, it is really helping. In race/race.py there is

self._get_endpoint(endpoint=RaceEditionResults, l=classification_num, e=zero_padded_stage_num)

And in constants.py I see
classifications = {'general': 1, 'youth': 2, 'points': 3, 'mountain': 4, 'sprint': 6}

So I suppose that l=1 should give me the general. However, it does not. FirstCycling seems not to work anymore like that. Can you confirm the current state?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.