Skip to content

Commit 8404955

Browse files
committed
Documentation improvements
1 parent d696d64 commit 8404955

File tree

11 files changed

+88
-418
lines changed

11 files changed

+88
-418
lines changed

Dockerfile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
FROM python:3.9-slim
2-
2+
RUN apt-get update \
3+
&& apt-get install gcc -y \
4+
&& apt-get clean
35
WORKDIR /app
46
COPY requirements.txt .
57
RUN pip install -r requirements.txt uvloop
68

9+
LABEL maintainer="Allan Galarza <[email protected]>"
10+
LABEL org.opencontainers.image.licenses="Apache 2.0"
11+
LABEL org.opencontainers.image.authors="Allan Galarza <[email protected]>"
12+
LABEL org.opencontainers.image.url="https://github.com/Galarzaa90/tibia.py"
13+
LABEL org.opencontainers.image.source="https://github.com/Galarzaa90/tibia.py"
14+
LABEL org.opencontainers.image.vendor="Allan Galarza <[email protected]>"
15+
LABEL org.opencontainers.image.title="tibia.py"
16+
LABEL org.opencontainers.image.description="API that parses website content into python data."
17+
18+
719
COPY . .
820
RUN python setup.py install
921
EXPOSE 8000

cli.py

Lines changed: 0 additions & 383 deletions
This file was deleted.

serve.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,21 @@ async def middleware_handler(request: web.Request):
359359
async def init_client(app):
360360
app["tibiapy"] = tibiapy.Client()
361361

362+
363+
async def cleanup_client(app):
364+
await app["tibiapy"].session.close()
365+
366+
362367
if __name__ == "__main__":
363368
normalize_paths = normalize_path_middleware(remove_slash=True, append_slash=False)
364369
app = web.Application(middlewares=[
365370
error_middleware,
366-
normalize_paths])
371+
normalize_paths,
372+
])
367373
app.add_routes(routes)
368374
app.on_startup.append(init_client)
375+
app.on_cleanup.append(cleanup_client)
369376
print("Registered routes:")
370377
for route in routes: # type: RouteDef
371-
print('\t[%s] %s' % (route.method, route.path))
378+
print('- %s %s' % (route.method, route.path))
372379
web.run_app(app, port=8000)

setup.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,13 @@ def get_version(package):
3939
readme = f.read()
4040

4141
extras_require = {
42-
'cli': [
43-
'click',
44-
'requests',
45-
'colorama'
46-
],
4742
'docs': [
4843
'sphinx',
4944
],
5045
'test': [
5146
'asynctest',
5247
'aioresponses',
53-
'coverage'
48+
'coverage',
5449
]
5550
}
5651

@@ -68,6 +63,15 @@ def get_version(package):
6863
long_description_content_type="text/markdown",
6964
packages=find_packages(),
7065
include_package_data=True,
66+
project_urls={
67+
"GitHub: Repo": "https://github.com/Galarzaa90/tibia.py",
68+
"GitHub: Issues": "https://github.com/Galarzaa90/tibia.py/issues",
69+
"Docs: RTD": "https://tibiapy.readthedocs.io/en/stable/",
70+
"Docs: Changelog": "https://tibiapy.readthedocs.io/en/stable/changelog.html",
71+
"Coverage: Codecov": "https://app.codecov.io/gh/Galarzaa90/tibia.py",
72+
"Docker Hub: Repo": "https://hub.docker.com/repository/docker/galarzaa90/tibia.py",
73+
"SonarCloud": "https://sonarcloud.io/dashboard?id=Galarzaa90_tibia.py",
74+
},
7175
classifiers=[
7276
'Development Status :: 5 - Production/Stable',
7377
'Intended Audience :: Developers',
@@ -86,6 +90,6 @@ def get_version(package):
8690
'Topic :: Software Development :: Libraries',
8791
'Topic :: Text Processing :: Markup :: HTML',
8892
'Topic :: Utilities',
89-
'Typing :: Typed'
93+
'Typing :: Typed',
9094
]
9195
)

tibiapy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '3.7.1'
1+
__version__ = '4.0.0'
22
__author__ = 'Allan Galarza'
33

44
import logging

tibiapy/bazaar.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ def _parse_data_table(cls, table) -> Dict[str, str]:
11331133
data[name] = value
11341134
return data
11351135

1136-
def parse_skills_table(self, table):
1136+
def _parse_skills_table(self, table):
11371137
"""Parses the skills table.
11381138
11391139
Parameters
@@ -1248,7 +1248,7 @@ def _parse_bestiary_table(self, table):
12481248
self.bestiary_progress.append(BestiaryEntry(name_c, kills, step))
12491249

12501250
@classmethod
1251-
def parse_page_items(cls, content, entry_class):
1251+
def _parse_page_items(cls, content, entry_class):
12521252
"""Parses the elements of a page in the items, mounts and outfits.
12531253
12541254
Attributes
@@ -1260,7 +1260,6 @@ def parse_page_items(cls, content, entry_class):
12601260
12611261
Returns
12621262
-------
1263-
-
12641263
The entries contained in the page.
12651264
"""
12661265
parsed_content = parse_tibiacom_content(content, builder='html5lib')
@@ -1291,7 +1290,7 @@ def _parse_general_table(self, table):
12911290
self.titles_count = parse_integer(general_stats.get("titles", "0"))
12921291
self.blessings_count = parse_integer(re.sub(r"/d+", "", general_stats.get("blessings", "0")))
12931292

1294-
self.parse_skills_table(content_containers[1])
1293+
self._parse_skills_table(content_containers[1])
12951294

12961295
additional_stats = self._parse_data_table(content_containers[2])
12971296
self.creation_date = parse_tibia_datetime(additional_stats.get("creation_date", "").replace("\xa0", " "))

tibiapy/client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ async def _request(self, method, url, data=None, headers=None):
187187
async with self.session.request(method, url, data=data, headers=headers) as resp:
188188
diff_time = time.perf_counter()-init_time
189189
if "maintenance.tibia.com" in str(resp.url):
190-
log.info(f"%s | %s | %s %s | maintenance.tibia.com", url, method, resp.status, resp.reason)
190+
log.info(f"%s | %s | %s %s | maintenance.tibia.com", url, resp.method, resp.status, resp.reason)
191191
raise SiteMaintenanceError("Tibia.com is down for maintenance.")
192-
log.info(f"%s | %s | %s %s | %dms", url, method, resp.status, resp.reason, int(diff_time*1000))
192+
log.info(f"%s | %s | %s %s | %dms", url, resp.method, resp.status, resp.reason, int(diff_time*1000))
193193
self._handle_status(resp.status)
194194
response = RawResponse(resp, diff_time)
195195
response.content = await resp.text()
@@ -337,7 +337,7 @@ async def _fetch_all_pages(self, auction_id, paginator, item_type):
337337
current_page = 2
338338
while current_page <= paginator.total_pages:
339339
content = await self._fetch_ajax_page(auction_id, item_type, current_page)
340-
entries = AuctionDetails.parse_page_items(content, paginator.entry_class)
340+
entries = AuctionDetails._parse_page_items(content, paginator.entry_class)
341341
paginator.entries.extend(entries)
342342
current_page += 1
343343
paginator.fully_fetched = True
@@ -668,6 +668,8 @@ async def fetch_boosted_creature(self):
668668
"""Fetches today's boosted creature.
669669
670670
.. versionadded:: 2.1.0
671+
.. versionchanged:: 4.0.0
672+
The return type of the data returned was changed to :class:`Creature`, previous type was removed.
671673
672674
Returns
673675
-------
@@ -1096,7 +1098,7 @@ async def fetch_news_archive(self, begin_date, end_date, categories=None, types=
10961098
if NewsType.NEWS_TICKER in types:
10971099
data["filter_ticker"] = "ticker"
10981100

1099-
response = await self._request("post", News.get_list_url(), data)
1101+
response = await self._request("POST", News.get_list_url(), data)
11001102
start_time = time.perf_counter()
11011103
news = ListedNews.list_from_content(response.content)
11021104
parsing_time = time.perf_counter() - start_time

tibiapy/enums.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ class AuctionStatus(BaseEnum):
110110

111111

112112
class BattlEyeType(NumericEnum):
113-
"""The possible BattlEye statuses a world can have."""
113+
"""The possible BattlEye statuses a world can have.
114+
115+
.. versionadded:: 4.0.0
116+
"""
114117
UNPROTECTED = 0
115118
"""Worlds without any BattlEye protection."""
116119
PROTECTED = 1
@@ -132,9 +135,15 @@ class BattlEyeHighscoresFilter(NumericEnum):
132135
UNPROTECTED = 0
133136
"""Worlds without any BattlEye protection."""
134137
YELLOW = PROTECTED
135-
"""Alias for protected worlds."""
138+
"""Alias for protected worlds.
139+
140+
.. versionadded:: 4.0.0
141+
"""
136142
GREEN = INITIALLY_PROTECTED
137-
"""Alias for initially protected worlds."""
143+
"""Alias for initially protected worlds.
144+
145+
.. versionadded:: 4.0.0
146+
"""
138147

139148

140149
class BattlEyeTypeFilter(NumericEnum):
@@ -146,9 +155,15 @@ class BattlEyeTypeFilter(NumericEnum):
146155
NOT_PROTECTED = 3
147156
"""Worlds without any BattlEye protection."""
148157
YELLOW = PROTECTED
149-
"""Alias for protected worlds."""
158+
"""Alias for protected worlds.
159+
160+
.. versionadded:: 4.0.0
161+
"""
150162
GREEN = INITIALLY_PROTECTED
151-
"""Alias for initially protected worlds."""
163+
"""Alias for initially protected worlds.
164+
165+
.. versionadded:: 4.0.0
166+
"""
152167

153168

154169
class BazaarType(BaseEnum):

tibiapy/forum.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ class ForumAuthor(abc.BaseCharacter, abc.Serializable):
446446
Whether the author is deleted or not.
447447
traded: :class:`bool`
448448
Whether the author is traded or not.
449+
450+
.. versionadded:: 4.0.0
449451
"""
450452

451453
__slots__ = (

tibiapy/utils.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_tibia_url(section, subtopic=None, *args, anchor=None, **kwargs):
5252
5353
You can also build a dictionary and pass it like:
5454
55-
>>> params = {'world': "Gladera", }
55+
>>> params = {'world': "Gladera"}
5656
>>> get_tibia_url("community", "worlds", **params)
5757
https://www.tibia.com/community/?subtopic=worlds&world=Gladera
5858
"""
@@ -115,7 +115,7 @@ def parse_tibia_datetime(datetime_str) -> Optional[datetime.datetime]:
115115
Returns
116116
-----------
117117
:class:`datetime.datetime`, optional
118-
The represented datetime, in UTC.
118+
The represented datetime, in UTC (timezone aware).
119119
"""
120120
try:
121121
datetime_str = datetime_str.replace(",", "").replace("&#160;", " ")
@@ -158,7 +158,7 @@ def parse_tibia_date(date_str) -> Optional[datetime.date]:
158158
Returns
159159
-----------
160160
:class:`datetime.date`, optional
161-
The represented date."""
161+
The represented date, in UTC (timezone aware)."""
162162
try:
163163
t = datetime.datetime.strptime(date_str.strip(), "%b %d %Y")
164164
return t.date()
@@ -187,7 +187,7 @@ def parse_tibia_forum_datetime(datetime_str, utc_offset=1):
187187
Returns
188188
-------
189189
:class:`datetime`
190-
The datetime represented by the text, in UTC.
190+
The represented datetime, in UTC (timezone aware).
191191
"""
192192
t = datetime.datetime.strptime(datetime_str.strip(), "%d.%m.%Y %H:%M:%S")
193193
# Add/subtract hours to get the real time
@@ -210,7 +210,7 @@ def parse_tibia_full_date(date_str) -> Optional[datetime.date]:
210210
Returns
211211
-----------
212212
:class:`datetime.date`, optional
213-
The represented date.
213+
The represented date, in UTC (timezone aware).
214214
"""
215215
try:
216216
t = datetime.datetime.strptime(date_str.strip(), "%B %d, %Y")
@@ -280,7 +280,7 @@ def try_datetime(obj) -> Optional[datetime.datetime]:
280280
Returns
281281
-------
282282
:class:`datetime.datetime`, optional
283-
The represented datetime, or :obj:`None` if conversion wasn't possible.
283+
The represented datetime, in UTC (timezone aware), or :obj:`None` if conversion wasn't possible.
284284
"""
285285
if obj is None:
286286
return None
@@ -304,7 +304,7 @@ def try_date(obj) -> Optional[datetime.date]:
304304
Returns
305305
-------
306306
:class:`datetime.date`, optional
307-
The represented date.
307+
The represented date, in UTC (timezone aware).
308308
"""
309309
if obj is None:
310310
return None
@@ -386,9 +386,8 @@ def parse_tibia_money(argument):
386386
387387
Returns
388388
-------
389-
int:
389+
:class:`int`:
390390
The value represented by the string.
391-
392391
"""
393392
try:
394393
return int(argument)

0 commit comments

Comments
 (0)