Package: intervalsicu-to-influxdb
Intervals.icu to InfluxDBIntervalsicu-to-influxdb is a personal project to extract data from Intervals.icu to InfluxDB (oh, really?). But if Intervals.icu already shows a lot of graphics, statistics and more, why I need to extract it?Full documentation can be found inhereWhyWell, as a sportsman and techie, it's just a personal project, but the main reason is because I want to create my own dashboards (using Grafana in this case).So, for example, I can combine activity data with sleep time or quality, compare the evolution between pace/bpm for the similar activities or whatever.How it worksThis project exports some data fromintervals.icutoinfluxDB. To retrieve the information the officialintervals.icu APIis used.Exported dataNot all information is exported. This project has been created to extract data from activities and wellness. Besides, information about data account (like email, location, preferences, etc.), calendar or workouts are not retrieved neither (for now).Currently the following data is exported:Wellness*: this data contains information like sleep time and quality, atl/ctl or VO2MaxActivities*: general information about every activity, like elapsed time, time in zones (hr or pace), distance, average pace/hr, etc.Streams**: streams contains detailed information about activities, like hr/pace for every second.* There are som extra fields generated, just to facilitate the use for the dashboards (seeEntities)** Currently working on it.How to useThere are 2 ways (3 if you count 'from source code') to use the project: with Docker or directly with Python (or from source code), but in both cases you need to create a.envfile to save your credentials for Intervals.icu and InfluxDB as follow:INFLUXDB_TOKEN=
INFLUXDB_ORG=
INFLUXDB_URL=
INFLUXDB_BUCKET=
INFLUXDB_TIMEOUT=10000
INTERVALS_ATHLETE_ID=
INTERVALS_API_KEY=DockerTo use with Docker, just run the following command:dockerrun--env-filePATH/TO/FILE-it--rmtmllull/intervals-to-influxdbapp.py[-h][--start-dateSTART_DATE][--end-dateEND_DATE][--streams][--reset]ArgumentsAll the arguments are optional, but take in consideration the following variations when run it:No arguments: retrieve the wellness and activities data for today (this is the basic use to run with a cronjob)Start date: retrieve data from the starting date (in format YYYY-MM-DD) until todayEnd date: retrieve data until specified date (in format YYYY-MM-DD). Use it withstart-dateStreams: retrieve the streams for the activitiesReset: delete the current bucket and recreate againNOTE: on the first run, the bucket is created automatically if not exists on InfluxDBWith PythonIf you want to run it directly with Python, first install the dependency:pipinstallintervalsicu-to-influxdbThen, the minimum code to run it is (remember to put the.envfile on the same folder):fromintervalsicu_to_influxdb.extractorimportIntervalsToInfluxextractor=IntervalsToInflux()extractor.all_data()To run it, just save asapp.pyand run it:pythonapp.pyArgumentsAs the Docker way, we can pass arguments when create the extractor. For example:extractor=IntervalsToInflux(start_date="2023-01-01")extractor=IntervalsToInflux(streams=True)extractor=IntervalsToInflux(start_date="2023-01-01",end_date="2023-05-01")Dynamic scriptIf you want to create a more dynamic script, here is a more complete example:importargparsefromintervalsicu_to_influxdb.extractorimportIntervalsToInfluxparser=argparse.ArgumentParser()parser.add_argument("--start-date",type=str,help="Start date in format YYYY-MM-DD")parser.add_argument("--end-date",type=str,help="End date in format YYYY-MM-DD")parser.add_argument("--streams",action="store_true",help="Export streams for the activities",)parser.add_argument("--reset",action="store_true",help="Reset influx bucket (delete and create)")args=parser.parse_args()ifargs.start_date:start_date=args.start_dateelse:start_date=Noneifargs.end_date:end_date=args.end_dateelse:end_date=Noneifargs.streams:streams=Trueelse:streams=Falseifargs.reset:reset=Trueelse:reset=Falseextractor=IntervalsToInflux(start_date,end_date,reset,streams)extractor.all_data()Then, just run the script as before, but you will can use arguments (same as the Docker section):pythonapp.py[-h][--start-dateSTART_DATE][--end-dateEND_DATE][--streams][--reset]From source codeIf you want to run it from source code, just clone the project, and the follow the next steps (remember to create the.envfile):Run with DockerFirst, compile the imagedockerbuild--tagintervals-to-influxdb.And then, just run it like the Docker section above (but with the image name)dockerrun--env-filePATH/TO/FILE-it--rmintervals-to-influxdbapp.py[-h][--start-dateSTART_DATE][--end-dateEND_DATE][--streams][--reset]Run with Python
First, install dependencies from sourcepip install .And then, run the scriptpython app.py [-h] [--start-date START_DATE] [--end-date END_DATE] [--streams] [--reset]