MCPcopy
hub / github.com/probberechts/soccerdata / read_versions

Method read_versions

soccerdata/sofifa.py:125–168  ·  view source on GitHub ↗

Retrieve available FIFA releases and rating updates. Parameters ---------- max_age : int for age in days, or timedelta object The max. age of the locally cached release history before a new version is downloaded. Raises ------

(self, max_age: Union[int, timedelta] = 1)

Source from the content-addressed store, hash-verified

123 )
124
125 def read_versions(self, max_age: Union[int, timedelta] = 1) -> pd.DataFrame:
126 """Retrieve available FIFA releases and rating updates.
127
128 Parameters
129 ----------
130 max_age : int for age in days, or timedelta object
131 The max. age of the locally cached release history before a new
132 version is downloaded.
133
134 Raises
135 ------
136 TypeError
137 If max_age is not an integer or timedelta object.
138
139 Returns
140 -------
141 pd.DataFrame
142 """
143 # read home page (overview)
144 filepath = self.data_dir / "index.html"
145 reader = self.get(SO_FIFA_API, filepath, max_age)
146
147 # extract FIFA releases
148 versions = []
149 tree = html.parse(reader)
150 for i, node_fifa_edition in enumerate(tree.xpath("//header/section/p/select[1]/option")):
151 fifa_edition = node_fifa_edition.text
152 filepath = self.data_dir / f"updates_{fifa_edition}.html"
153 url = SO_FIFA_API + node_fifa_edition.get("value")
154 # check for updates on latest FIFA edition only
155 reader = self.get(url, filepath, max_age=max_age if i == 0 else None)
156 tree = html.parse(reader)
157
158 for node_fifa_update in tree.xpath("//header/section/p/select[2]/option"):
159 href = node_fifa_update.get("value")
160 version_id = re.search(r"r=(\d+)", href).group(1) # type: ignore
161 versions.append(
162 {
163 "version_id": int(version_id),
164 "fifa_edition": fifa_edition,
165 "update": node_fifa_update.text,
166 }
167 )
168 return pd.DataFrame(versions).set_index("version_id").sort_index()
169
170 def read_teams(self) -> pd.DataFrame:
171 """Retrieve all teams for the selected leagues.

Callers 1

__init__Method · 0.95

Calls 2

getMethod · 0.80
parseMethod · 0.80

Tested by

no test coverage detected