zpdatafetch 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Doug Morris
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.1
2
+ Name: zpdatafetch
3
+ Version: 0.2.0
4
+ Summary: A package for fetching data from Zwiftpower
5
+ Home-page: https://github.com/puckdoug/zpdatafetch
6
+ Author: Doug Morris
7
+ Author-email: "Doug Morris" <doug@mhost.com>
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: httpx>=0.27.0
11
+ Requires-Dist: beautifulsoup4>=4.12.3
12
+ Requires-Dist: keyring>=25.2.0
13
+ Requires-Dist: lxml>=5.2.1
14
+
15
+ # zpdatafetch
16
+
17
+ A python library for fetching data from zwiftpower
18
+
19
+ ## installation
20
+
21
+ 1. Install this package
22
+ 2. Install the requirements
23
+
24
+ ```sh
25
+ pip install -r requirements.txt
26
+ ```
27
+
28
+ 3. Set up your keyring. You may want to use a separate account on zwiftpower for this.
29
+
30
+ ```sh
31
+ keyring set zpdatafetch username
32
+ keyring set zpdatafetch password
33
+ ```
34
+
35
+ 4. Run the downloader
36
+
37
+ ```sh
38
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/zp.py
39
+ ```
40
+
41
+ ## Cyclist example
42
+
43
+ ```shell
44
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/cyclist.py -v -r <zwift_id>
45
+ ```
46
+
47
+ ## Team example
48
+
49
+ ```shell
50
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/team.py -v -r <team_id>
51
+ ```
52
+
53
+ ## Signup example
54
+
55
+ ```shell
56
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/signup.py -v -r <race_id>
57
+ ```
58
+
59
+ ## Result example
60
+
61
+ ```shell
62
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/result.py -v -r <race_id>
63
+ ```
64
+
65
+ ## Primes example
66
+
67
+ ```shell
68
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/primes.py -v -r <race_id>
69
+ ```
@@ -0,0 +1,55 @@
1
+ # zpdatafetch
2
+
3
+ A python library for fetching data from zwiftpower
4
+
5
+ ## installation
6
+
7
+ 1. Install this package
8
+ 2. Install the requirements
9
+
10
+ ```sh
11
+ pip install -r requirements.txt
12
+ ```
13
+
14
+ 3. Set up your keyring. You may want to use a separate account on zwiftpower for this.
15
+
16
+ ```sh
17
+ keyring set zpdatafetch username
18
+ keyring set zpdatafetch password
19
+ ```
20
+
21
+ 4. Run the downloader
22
+
23
+ ```sh
24
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/zp.py
25
+ ```
26
+
27
+ ## Cyclist example
28
+
29
+ ```shell
30
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/cyclist.py -v -r <zwift_id>
31
+ ```
32
+
33
+ ## Team example
34
+
35
+ ```shell
36
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/team.py -v -r <team_id>
37
+ ```
38
+
39
+ ## Signup example
40
+
41
+ ```shell
42
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/signup.py -v -r <race_id>
43
+ ```
44
+
45
+ ## Result example
46
+
47
+ ```shell
48
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/result.py -v -r <race_id>
49
+ ```
50
+
51
+ ## Primes example
52
+
53
+ ```shell
54
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/primes.py -v -r <race_id>
55
+ ```
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = [ "setuptools", "wheel" ]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.ruff]
6
+ # Exclude a variety of commonly ignored directories.
7
+ exclude = [
8
+ ".bzr",
9
+ ".direnv",
10
+ ".eggs",
11
+ ".git",
12
+ ".git-rewrite",
13
+ ".hg",
14
+ ".ipynb_checkpoints",
15
+ ".mypy_cache",
16
+ ".nox",
17
+ ".pants.d",
18
+ ".pyenv",
19
+ ".pytest_cache",
20
+ ".pytype",
21
+ ".ruff_cache",
22
+ ".svn",
23
+ ".tox",
24
+ ".venv",
25
+ ".vscode",
26
+ "__pypackages__",
27
+ "_build",
28
+ "buck-out",
29
+ "build",
30
+ "dist",
31
+ "node_modules",
32
+ "site-packages",
33
+ "venv",
34
+ ]
35
+
36
+ line-length = 80
37
+ indent-width = 2
38
+
39
+ [tool.ruff.format]
40
+ quote-style = "single"
41
+ indent-style = "space"
42
+ line-ending = "auto"
@@ -0,0 +1,37 @@
1
+ [metadata]
2
+ name = zpdatafetch
3
+ version = 0.2.0
4
+ url = https://github.com/puckdoug/zpdatafetch
5
+ author = Doug Morris
6
+ author_email = "Doug Morris" <doug@mhost.com>
7
+ description = A package for fetching data from Zwiftpower
8
+ long_description = file: README.md
9
+ long_description_content_type = text/markdown
10
+
11
+ [options]
12
+ package_dir =
13
+ =src
14
+ packages = find:
15
+ install_requires =
16
+ httpx>=0.27.0
17
+ beautifulsoup4>=4.12.3
18
+ keyring>=25.2.0
19
+ lxml>=5.2.1
20
+
21
+ [options.packages.find]
22
+ where = src
23
+ exclude = test*
24
+
25
+ [tox:tox]
26
+ isolated_build = True
27
+ envlist = py310,py311,py312
28
+
29
+ [testenv]
30
+ commands = pytest {posargs}
31
+ deps =
32
+ pytest
33
+
34
+ [egg_info]
35
+ tag_build =
36
+ tag_date = 0
37
+
@@ -0,0 +1,9 @@
1
+ from zpdatafetch.zp import ZP
2
+ from zpdatafetch.config import Config
3
+ from zpdatafetch.cyclist import Cyclist
4
+ from zpdatafetch.primes import Primes
5
+ from zpdatafetch.result import Result
6
+ from zpdatafetch.signup import Signup
7
+ from zpdatafetch.team import Team
8
+
9
+ __all__ = ['ZP', 'Cyclist', 'Primes', 'Result', 'Config', 'Signup', 'Team']
@@ -0,0 +1,66 @@
1
+ import sys
2
+ import keyring
3
+ from getpass import getpass
4
+ # ===============================================================================
5
+
6
+
7
+ class Config:
8
+ verbose: bool = False
9
+ domain: str = 'zpdatafetch'
10
+ username: str = None
11
+ password: str = None
12
+ keyring: keyring.backend.KeyringBackend
13
+
14
+ # -----------------------------------------------------------------------------
15
+ def __init__(self):
16
+ self.keyring = keyring.get_keyring()
17
+
18
+ # self.load()
19
+
20
+ # -----------------------------------------------------------------------------
21
+ def set_keyring(self, kr):
22
+ keyring.set_keyring(kr)
23
+
24
+ # -----------------------------------------------------------------------------
25
+ def replace_domain(self, domain):
26
+ self.domain = domain
27
+
28
+ # -----------------------------------------------------------------------------
29
+ def save(self):
30
+ keyring.set_password(self.domain, 'username', self.username)
31
+ keyring.set_password(self.domain, 'password', self.password)
32
+
33
+ # -----------------------------------------------------------------------------
34
+ def load(self):
35
+ self.username = keyring.get_password(self.domain, 'username')
36
+ self.password = keyring.get_password(self.domain, 'password')
37
+
38
+ # -----------------------------------------------------------------------------
39
+ def setup(self, username='', password=''):
40
+ if username:
41
+ self.username = username
42
+ else:
43
+ self.username = input('zwiftpower username (for use with zpdatafetch): ')
44
+ keyring.set_password(self.domain, 'username', self.username)
45
+
46
+ if password:
47
+ self.password = password
48
+ else:
49
+ self.password = getpass('zwiftpower password (for use with zpdatafetch): ')
50
+ keyring.set_password(self.domain, 'password', self.password)
51
+
52
+ # -----------------------------------------------------------------------------
53
+ def dump(self):
54
+ print(f'username: {self.username}')
55
+ print(f'password: {self.password}')
56
+
57
+
58
+ # ===============================================================================
59
+ def main():
60
+ c = Config()
61
+ c.dump()
62
+
63
+
64
+ # ===============================================================================
65
+ if __name__ == '__main__':
66
+ sys.exit(main())
@@ -0,0 +1,83 @@
1
+ # import js2py
2
+ from argparse import ArgumentParser
3
+ from zpdatafetch.zp import ZP
4
+
5
+
6
+ # ===============================================================================
7
+ class Cyclist:
8
+ _url = 'https://zwiftpower.com/cache3/profile/'
9
+ _profile = 'https://zwiftpower.com/profile.php?z='
10
+ _url_end = '_all.json'
11
+ verbose = False
12
+ raw = {}
13
+
14
+ # -------------------------------------------------------------------------------
15
+ # def extract_zp_vars(self, y):
16
+ # soupjs = BeautifulSoup(y, 'lxml')
17
+ # f = soupjs.find_all('script')
18
+ # zp_js = ''
19
+ # zp_vars = {}
20
+ # for s in f:
21
+ # c = s.string
22
+ # try:
23
+ # if re.search('ZP_VARS =', c):
24
+ # zp_js = c
25
+ # except Exception:
26
+ # pass
27
+
28
+ # zp_js = zp_js + '; ZP_VARS.athlete_id'
29
+ # strava = js2py.eval_js(zp_js)
30
+ # zp_vars['strava'] = f'https://www.strava.com/athletes/{strava}'
31
+ # return zp_vars
32
+
33
+ # -------------------------------------------------------------------------------
34
+ def fetch(self, *zwift_id):
35
+ zp = ZP()
36
+ if self.verbose:
37
+ zp.verbose = True
38
+
39
+ for z in zwift_id:
40
+ url = f'{self._url}{z}{self._url_end}'
41
+ x = zp.fetch_json(url)
42
+ self.raw[z] = x
43
+ prof = f'{self._profile}{z}'
44
+ zp.fetch_page(prof)
45
+ # js2py is broken in 3.12 right now. pull request pending to fix it.
46
+ # zp_vars = self.extract_zp_vars(y)
47
+
48
+ return self.raw
49
+
50
+
51
+ # ===============================================================================
52
+ def main():
53
+ desc = """
54
+ Module for fetching cyclist data using the Zwifpower API
55
+ """
56
+ p = ArgumentParser(description=desc)
57
+ p.add_argument(
58
+ '--verbose',
59
+ '-v',
60
+ action='store_const',
61
+ const=True,
62
+ help='provide feedback while running',
63
+ )
64
+ p.add_argument(
65
+ '--raw', '-r', action='store_const', const=True, help='raw results'
66
+ )
67
+ p.add_argument('zwift_id', type=int, nargs='+', help='a list of zwift_ids')
68
+ args = p.parse_args()
69
+
70
+ x = Cyclist()
71
+
72
+ if args.verbose:
73
+ x.verbose = True
74
+
75
+ x.fetch(*args.zwift_id)
76
+
77
+ if args.raw:
78
+ print(x.raw)
79
+
80
+
81
+ # ===============================================================================
82
+ if __name__ == '__main__':
83
+ main()
@@ -0,0 +1,96 @@
1
+ import re
2
+ import datetime
3
+ from argparse import ArgumentParser
4
+ from zpdatafetch.zp import ZP
5
+
6
+
7
+ # ===============================================================================
8
+ class Primes:
9
+ # https://zwiftpower.com/api3.php?do=event_primes&zid={race_id}&category={cat}&prime_type={type}
10
+ _url_base = 'https://zwiftpower.com/api3.php?do=event_primes'
11
+ _url_race_id = '&zid='
12
+ _url_category = '&category='
13
+ _url_primetype = '&prime_type='
14
+ _cat = ['A', 'B', 'C', 'D', 'E']
15
+ _type = ['msec', 'elapsed']
16
+ raw = None
17
+ verbose = False
18
+
19
+ # -------------------------------------------------------------------------------
20
+ @classmethod
21
+ def set_primetype(cls, t):
22
+ match t:
23
+ case 'msec':
24
+ return 'FAL'
25
+ case 'elapsed':
26
+ return 'FTS'
27
+ case _:
28
+ return ''
29
+
30
+ # -------------------------------------------------------------------------------
31
+ def fetch(self, *race_id):
32
+ zp = ZP()
33
+ p = {}
34
+
35
+ ts = int(re.sub(r'\.', '', str(datetime.datetime.now().timestamp())[:-3]))
36
+
37
+ if self.verbose:
38
+ zp.verbose = True
39
+
40
+ for race in race_id:
41
+ p[race] = {}
42
+ for cat in self._cat:
43
+ if cat not in p[race]:
44
+ p[race][cat] = {}
45
+ for primetype in self._type:
46
+ url = f'{self._url_base}{self._url_race_id}{race}{self._url_category}{cat}{self._url_primetype}{primetype}&_={ts}'
47
+ res = zp.fetch_json(url)
48
+ if self.verbose:
49
+ if len(res['data']) == 0:
50
+ print('No Results')
51
+ else:
52
+ print(f'Results found for {primetype} in pen {cat}')
53
+ p[race][cat][primetype] = res
54
+ ts = ts + 1
55
+
56
+ self.raw = p
57
+
58
+ return self.raw
59
+
60
+
61
+ # ===============================================================================
62
+ def main():
63
+ desc = """
64
+ Module for fetching primes using the Zwiftpower API
65
+ """
66
+ p = ArgumentParser(description=desc)
67
+ p.add_argument(
68
+ '--verbose',
69
+ '-v',
70
+ action='store_const',
71
+ const=True,
72
+ help='provide feedback while running',
73
+ )
74
+ p.add_argument(
75
+ '--raw',
76
+ '-r',
77
+ action='store_const',
78
+ const=True,
79
+ help='print all returned data',
80
+ )
81
+ p.add_argument('race_id', type=int, nargs='+', help='one or more race_ids')
82
+ args = p.parse_args()
83
+
84
+ x = Primes()
85
+ if args.verbose:
86
+ x.verbose = True
87
+
88
+ x.fetch(*args.race_id)
89
+
90
+ if args.raw:
91
+ print(x.raw)
92
+
93
+
94
+ # ===============================================================================
95
+ if __name__ == '__main__':
96
+ main()
@@ -0,0 +1,66 @@
1
+ from argparse import ArgumentParser
2
+ from zpdatafetch.zp import ZP
3
+
4
+
5
+ # ===============================================================================
6
+ class Result:
7
+ # race = "https://zwiftpower.com/cache3/results/3590800_view.json"
8
+ _url = 'https://zwiftpower.com/cache3/results/'
9
+ _url_end = '_view.json'
10
+ raw = None
11
+ verbose = False
12
+
13
+ # -------------------------------------------------------------------------------
14
+ def fetch(self, *race_id):
15
+ zp = ZP()
16
+ content = {}
17
+ if self.verbose:
18
+ zp.verbose = True
19
+
20
+ for r in race_id:
21
+ url = f'{self._url}{r}{self._url_end}'
22
+ if zp.verbose:
23
+ print(f'fetching: {url}')
24
+ content[r] = zp.fetch_json(url)
25
+
26
+ self.raw = content
27
+
28
+ return self.raw
29
+
30
+
31
+ # ===============================================================================
32
+ def main():
33
+ desc = """
34
+ Module for fetching race data using the Zwifpower API
35
+ """
36
+ p = ArgumentParser(description=desc)
37
+ p.add_argument(
38
+ '--verbose',
39
+ '-v',
40
+ action='store_const',
41
+ const=True,
42
+ help='provide feedback while running',
43
+ )
44
+ p.add_argument(
45
+ '--raw',
46
+ '-r',
47
+ action='store_const',
48
+ const=True,
49
+ help='print all returned data',
50
+ )
51
+ p.add_argument('race_id', type=int, nargs='+', help='one or more race_ids')
52
+ args = p.parse_args()
53
+
54
+ x = Result()
55
+ if args.verbose:
56
+ x.verbose = True
57
+
58
+ x.fetch(*args.race_id)
59
+
60
+ if args.raw:
61
+ print(x.raw)
62
+
63
+
64
+ # ===============================================================================
65
+ if __name__ == '__main__':
66
+ main()
@@ -0,0 +1,65 @@
1
+ from argparse import ArgumentParser
2
+ from zpdatafetch.zp import ZP
3
+
4
+
5
+ # ===============================================================================
6
+ class Signup:
7
+ # race = "https://zwiftpower.com/cache3/results/3590800_signups.json"
8
+ _url = 'https://zwiftpower.com/cache3/results/'
9
+ _url_end = '_signups.json'
10
+ raw = None
11
+ verbose = False
12
+
13
+ # -------------------------------------------------------------------------------
14
+ def fetch(self, *race_id_list):
15
+ zp = ZP()
16
+ signups_by_race_id = {}
17
+ if self.verbose:
18
+ zp.verbose = True
19
+
20
+ for race_id in race_id_list:
21
+ url = f'{self._url}{race_id}{self._url_end}'
22
+ if zp.verbose:
23
+ print(f'fetching: {url}')
24
+ signups_by_race_id[race_id] = zp.fetch_json(url)
25
+
26
+ self.raw = signups_by_race_id
27
+
28
+ return self.raw
29
+
30
+
31
+ # ===============================================================================
32
+ def main():
33
+ p = ArgumentParser(
34
+ description='Module for fetching race signup data using the Zwifpower API'
35
+ )
36
+ p.add_argument(
37
+ '--verbose',
38
+ '-v',
39
+ action='store_const',
40
+ const=True,
41
+ help='provide feedback while running',
42
+ )
43
+ p.add_argument(
44
+ '--raw',
45
+ '-r',
46
+ action='store_const',
47
+ const=True,
48
+ help='print all returned data',
49
+ )
50
+ p.add_argument('race_id', type=int, nargs='+', help='one or more race_ids')
51
+ args = p.parse_args()
52
+
53
+ x = Signup()
54
+ if args.verbose:
55
+ x.verbose = True
56
+
57
+ x.fetch(*args.race_id)
58
+
59
+ if args.raw:
60
+ print(x.raw)
61
+
62
+
63
+ # ===============================================================================
64
+ if __name__ == '__main__':
65
+ main()
@@ -0,0 +1,66 @@
1
+ from argparse import ArgumentParser
2
+ from zpdatafetch.zp import ZP
3
+
4
+
5
+ # ===============================================================================
6
+ class Team:
7
+ # "https://zwiftpower.com/cache3/teams/{team_id}_riders.json"
8
+ _url = 'https://zwiftpower.com/cache3/teams/'
9
+ _url_end = '_riders.json'
10
+ raw = None
11
+ verbose = False
12
+
13
+ # -------------------------------------------------------------------------------
14
+ def fetch(self, *team_id):
15
+ zp = ZP()
16
+ content = {}
17
+ if self.verbose:
18
+ zp.verbose = True
19
+
20
+ for t in team_id:
21
+ url = f'{self._url}{t}{self._url_end}'
22
+ if zp.verbose:
23
+ print(f'fetching: {url}')
24
+ content[t] = zp.fetch_json(url)
25
+
26
+ self.raw = content
27
+
28
+ return self.raw
29
+
30
+
31
+ # ===============================================================================
32
+ def main():
33
+ p = ArgumentParser(
34
+ description='Module for fetching cyclist data using the Zwifpower API'
35
+ )
36
+ p.add_argument(
37
+ '--verbose',
38
+ '-v',
39
+ action='store_const',
40
+ const=True,
41
+ help='provide feedback while running',
42
+ )
43
+ p.add_argument(
44
+ '--raw',
45
+ '-r',
46
+ action='store_const',
47
+ const=True,
48
+ help='print all returned data',
49
+ )
50
+ p.add_argument('team_id', type=int, nargs='+', help='a list of team_ids')
51
+ args = p.parse_args()
52
+
53
+ x = Team()
54
+
55
+ if args.verbose:
56
+ x.verbose = True
57
+
58
+ x.fetch(*args.team_id)
59
+
60
+ if args.raw:
61
+ print(x.raw)
62
+
63
+
64
+ # ===============================================================================
65
+ if __name__ == '__main__':
66
+ main()
@@ -0,0 +1,140 @@
1
+ import httpx
2
+ from zpdatafetch.config import Config
3
+ from bs4 import BeautifulSoup
4
+ import json
5
+
6
+
7
+ # ===============================================================================
8
+ class ZP:
9
+ _client: httpx.Client = None
10
+ verbose: bool = False
11
+
12
+ # -------------------------------------------------------------------------------
13
+ def __init__(self):
14
+ self.config = Config()
15
+ self.config.load()
16
+ self.username = self.config.username
17
+ self.password = self.config.password
18
+
19
+ # -------------------------------------------------------------------------------
20
+ def login(self):
21
+ if self.verbose:
22
+ print('Logging in to Zwiftpower')
23
+ self._client = httpx.Client(follow_redirects=True)
24
+ page = self._client.get(
25
+ 'https://zwiftpower.com/ucp.php?mode=login&login=external&oauth_service=oauthzpsso'
26
+ )
27
+ self._client.cookies.get('phpbb3_lswlk_sid')
28
+ soup = BeautifulSoup(page.text, 'lxml')
29
+ login_url = soup.form['action'][0:]
30
+ data = {'username': self.username, 'password': self.password}
31
+ self.login = self._client.post(
32
+ login_url, data=data, cookies=self._client.cookies
33
+ )
34
+
35
+ # -------------------------------------------------------------------------------
36
+ def fetch_json(self, endpoint):
37
+ if self._client is None:
38
+ self.login()
39
+
40
+ if self.verbose:
41
+ print(f'Fetching: {endpoint}')
42
+ pres = self._client.get(endpoint, cookies=self._client.cookies)
43
+ try:
44
+ res = pres.json()
45
+ except json.decoder.JSONDecodeError:
46
+ res = {}
47
+ return res
48
+
49
+ # -------------------------------------------------------------------------------
50
+ def fetch_page(self, endpoint):
51
+ if self._client is None:
52
+ self.login()
53
+
54
+ if self.verbose:
55
+ print(f'Fetching: {endpoint}')
56
+
57
+ pres = self._client.get(endpoint, cookies=self._client.cookies)
58
+ res = pres.text
59
+ return res
60
+
61
+ # -------------------------------------------------------------------------------
62
+ def close(self):
63
+ try:
64
+ self._client.close()
65
+ except Exception:
66
+ pass
67
+
68
+ # -------------------------------------------------------------------------------
69
+ def __del__(self):
70
+ self.close()
71
+
72
+ # -------------------------------------------------------------------------------
73
+ @classmethod
74
+ def set_pen(cls, label):
75
+ match label:
76
+ case 0:
77
+ return 'E'
78
+ case 1:
79
+ return 'A'
80
+ case 2:
81
+ return 'B'
82
+ case 3:
83
+ return 'C'
84
+ case 4:
85
+ return 'D'
86
+ case 5:
87
+ return 'E'
88
+ case _:
89
+ return str(label)
90
+
91
+ # -------------------------------------------------------------------------------
92
+ @classmethod
93
+ def set_rider_category(cls, div):
94
+ match div:
95
+ case 0:
96
+ return ''
97
+ case 10:
98
+ return 'A'
99
+ case 20:
100
+ return 'B'
101
+ case 30:
102
+ return 'C'
103
+ case 40:
104
+ return 'D'
105
+ case _:
106
+ return str(div)
107
+
108
+ # -------------------------------------------------------------------------------
109
+ @classmethod
110
+ def set_category(cls, div):
111
+ match div:
112
+ case 0:
113
+ return 'E'
114
+ case 10:
115
+ return 'A'
116
+ case 20:
117
+ return 'B'
118
+ case 30:
119
+ return 'C'
120
+ case 40:
121
+ return 'D'
122
+ case _:
123
+ return str(div)
124
+
125
+
126
+ # ===============================================================================
127
+ def main():
128
+ """
129
+ Core module for accessing Zwiftpower API endpoints
130
+ """
131
+ zp = ZP()
132
+ zp.verbose = True
133
+ zp.login()
134
+ print(zp.login.status_code)
135
+ zp.close()
136
+
137
+
138
+ # ===============================================================================
139
+ if __name__ == '__main__':
140
+ main()
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.1
2
+ Name: zpdatafetch
3
+ Version: 0.2.0
4
+ Summary: A package for fetching data from Zwiftpower
5
+ Home-page: https://github.com/puckdoug/zpdatafetch
6
+ Author: Doug Morris
7
+ Author-email: "Doug Morris" <doug@mhost.com>
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: httpx>=0.27.0
11
+ Requires-Dist: beautifulsoup4>=4.12.3
12
+ Requires-Dist: keyring>=25.2.0
13
+ Requires-Dist: lxml>=5.2.1
14
+
15
+ # zpdatafetch
16
+
17
+ A python library for fetching data from zwiftpower
18
+
19
+ ## installation
20
+
21
+ 1. Install this package
22
+ 2. Install the requirements
23
+
24
+ ```sh
25
+ pip install -r requirements.txt
26
+ ```
27
+
28
+ 3. Set up your keyring. You may want to use a separate account on zwiftpower for this.
29
+
30
+ ```sh
31
+ keyring set zpdatafetch username
32
+ keyring set zpdatafetch password
33
+ ```
34
+
35
+ 4. Run the downloader
36
+
37
+ ```sh
38
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/zp.py
39
+ ```
40
+
41
+ ## Cyclist example
42
+
43
+ ```shell
44
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/cyclist.py -v -r <zwift_id>
45
+ ```
46
+
47
+ ## Team example
48
+
49
+ ```shell
50
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/team.py -v -r <team_id>
51
+ ```
52
+
53
+ ## Signup example
54
+
55
+ ```shell
56
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/signup.py -v -r <race_id>
57
+ ```
58
+
59
+ ## Result example
60
+
61
+ ```shell
62
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/result.py -v -r <race_id>
63
+ ```
64
+
65
+ ## Primes example
66
+
67
+ ```shell
68
+ PYTHONPATH=`pwd`/src python src/zpdatafetch/primes.py -v -r <race_id>
69
+ ```
@@ -0,0 +1,24 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.cfg
5
+ src/zpdatafetch/__init__.py
6
+ src/zpdatafetch/config.py
7
+ src/zpdatafetch/cyclist.py
8
+ src/zpdatafetch/primes.py
9
+ src/zpdatafetch/result.py
10
+ src/zpdatafetch/signup.py
11
+ src/zpdatafetch/team.py
12
+ src/zpdatafetch/zp.py
13
+ src/zpdatafetch.egg-info/PKG-INFO
14
+ src/zpdatafetch.egg-info/SOURCES.txt
15
+ src/zpdatafetch.egg-info/dependency_links.txt
16
+ src/zpdatafetch.egg-info/requires.txt
17
+ src/zpdatafetch.egg-info/top_level.txt
18
+ test/test_config.py
19
+ test/test_cyclist.py
20
+ test/test_primes.py
21
+ test/test_result.py
22
+ test/test_signup.py
23
+ test/test_team.py
24
+ test/test_zp.py
@@ -0,0 +1,4 @@
1
+ httpx>=0.27.0
2
+ beautifulsoup4>=4.12.3
3
+ keyring>=25.2.0
4
+ lxml>=5.2.1
@@ -0,0 +1 @@
1
+ zpdatafetch
@@ -0,0 +1,32 @@
1
+ from keyrings.alt.file import PlaintextKeyring
2
+
3
+
4
+ def test_setup(config):
5
+ assert config is not None
6
+
7
+
8
+ def test_setup_has_no_default_creds(config):
9
+ assert config.username is None
10
+ assert config.password is None
11
+
12
+
13
+ def test_domain_can_be_changed(config):
14
+ config.domain = 'test-zpdatafetch'
15
+ assert config.domain == 'test-zpdatafetch'
16
+
17
+
18
+ def test_load_config_has_no_creds_before_set(config):
19
+ config.domain = 'test-zpdatafetch'
20
+ config.load()
21
+ assert config.username is None
22
+ assert config.password is None
23
+
24
+
25
+ def test_after_load_config_has_creds(config):
26
+ tuser = 'test_username'
27
+ tpass = 'test_password'
28
+ config.set_keyring(PlaintextKeyring())
29
+ config.domain = 'test-zpdatafetch'
30
+ config.setup(username=tuser, password=tpass)
31
+ assert config.username == tuser
32
+ assert config.password == tpass
@@ -0,0 +1,2 @@
1
+ def test_cyclist(cyclist):
2
+ assert cyclist is not None
@@ -0,0 +1,2 @@
1
+ def test_primes(primes):
2
+ assert primes is not None
@@ -0,0 +1,2 @@
1
+ def test_result(result):
2
+ assert result is not None
@@ -0,0 +1,2 @@
1
+ def test_signup(signup):
2
+ assert signup is not None
@@ -0,0 +1,2 @@
1
+ def test_team(team):
2
+ assert team is not None
@@ -0,0 +1,26 @@
1
+ def test_pen(zp):
2
+ assert zp.set_pen(0) == 'E'
3
+ assert zp.set_pen(1) == 'A'
4
+ assert zp.set_pen(2) == 'B'
5
+ assert zp.set_pen(3) == 'C'
6
+ assert zp.set_pen(4) == 'D'
7
+ assert zp.set_pen(5) == 'E'
8
+ assert zp.set_pen(6) == '6'
9
+
10
+
11
+ def test_rider_category(zp):
12
+ assert zp.set_rider_category(0) == ''
13
+ assert zp.set_rider_category(10) == 'A'
14
+ assert zp.set_rider_category(20) == 'B'
15
+ assert zp.set_rider_category(30) == 'C'
16
+ assert zp.set_rider_category(40) == 'D'
17
+ assert zp.set_rider_category(50) == '50'
18
+
19
+
20
+ def test_category(zp):
21
+ assert zp.set_category(0) == 'E'
22
+ assert zp.set_category(10) == 'A'
23
+ assert zp.set_category(20) == 'B'
24
+ assert zp.set_category(30) == 'C'
25
+ assert zp.set_category(40) == 'D'
26
+ assert zp.set_category(50) == '50'