Skip to content

Commit 30ce941

Browse files
authored
Merge pull request #12 from Galarzaa90/dev
v2.0.0
2 parents 02ba1a8 + 1cf3233 commit 30ce941

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3392
-435
lines changed

.gitlab-ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
image: python:3.6
22

33
before_script:
4-
- pip install -r requirements.txt
4+
- pip install -U -e .
55
- pip install -U setuptools wheel
66

77
stages:
@@ -21,7 +21,7 @@ build:
2121
docs:
2222
stage: build
2323
script:
24-
- pip install Sphinx
24+
- pip install -U -e .[docs]
2525
- cd docs
2626
- make html
2727
artifacts:
@@ -33,6 +33,7 @@ coverage:
3333
stage: test
3434
script:
3535
- pip install coverage
36+
- pip install -U -e .[test]
3637
- coverage run setup.py test
3738
- coverage report
3839
- coverage html

.readthedocs.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
formats: []
2+
3+
build:
4+
image: latest
5+
6+
python:
7+
version: 3.6
8+
pip_install: true
9+
extra_requirements:
10+
- docs

.travis.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ python:
44
- "3.5"
55
- "3.6"
66
- "3.7-dev"
7+
- "pypy3.5"
78

89
cache: pip
910

1011
install:
11-
- pip install -U -r requirements.txt
12+
- pip install -U -e .
13+
- pip install -U -e .[test]
14+
- pip install -U -e .[docs]
1215
- pip install -U setuptools wheel
1316
- pip install coverage codecov
14-
- pip install -U Sphinx
1517

1618
before_script:
1719
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
@@ -39,4 +41,4 @@ deploy:
3941
keep-history: true
4042
on:
4143
branch: master
42-
python: "3.6"
44+
python: "3.6"

CHANGELOG.rst

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22
Changelog
33
=========
44

5+
.. note::
6+
Due to this library relying on external content, older versions are not guaranteed to work.
7+
Try to always use the latest version.
8+
9+
.. _v2.0.0:
10+
11+
2.0.0 (2019-06-03)
12+
==================
13+
14+
- Added asynchronous client to fetch and parse Tibia.com sections.
15+
- Added news parsing.
16+
- Added kill statistics parsing.
17+
- Added support for tournament worlds.
18+
- Added support for house prices with 'k' suffixes.
19+
520
.. _v1.1.3:
621

722
1.1.3 (2019-01-29)
@@ -58,4 +73,4 @@ Initial release:
5873
- Guild list pages
5974

6075
- Parses content into JSON format strings.
61-
- Parses content into Python objects.
76+
- Parses content into Python objects.

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ pip install git+https://github.com/Galarzaa90/tibia.py.git -U
3131
```
3232

3333
## Usage
34-
In order to use this library, you need to use an external library (`requests`, `aiohttp`) to fetch content from the website.
34+
This library is composed of two parts, parsers and an asynchronous request client.
35+
36+
The asynchronous client (`tibiapy.Client`) contains methods to obtain information from Tibia.com.
37+
38+
The parsing methods allow you to get Python objects given the html content of a page.
3539

3640
```python
3741
import tibiapy
@@ -40,24 +44,25 @@ import tibiapy
4044
import aiohttp
4145

4246
async def get_character(name):
43-
url = tibiapy.Character.get_url(name)
47+
url = tibiapy.Character.get_url(name)
4448

45-
async with aiohttp.ClientSession() as session:
46-
async with session.get(url) as resp:
47-
content = await resp.text()
48-
character = tibiapy.Character.from_content(content)
49-
return character
49+
async with aiohttp.ClientSession() as session:
50+
async with session.get(url) as resp:
51+
content = await resp.text()
52+
character = tibiapy.Character.from_content(content)
53+
return character
5054

5155
# Synchronously
5256
import requests
5357

5458
def get_character_sync(name):
55-
url = tibiapy.Character.get_url(name)
59+
url = tibiapy.Character.get_url(name)
60+
61+
r = requests.get(url)
62+
content = r.text()
63+
character = tibiapy.Character.from_content(content)
64+
return character
5665

57-
r = requests.get(url)
58-
content = r.text()
59-
character = tibiapy.Character.from_content(content)
60-
return character
6166
```
6267

6368
## Documentation

cli.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import colorama
1111
colorama.init()
1212
except ImportError:
13+
click = None
14+
requests = None
15+
colorama = None
1316
print("Use as a command-line interface requires optional dependencies: click, requests and colorama")
1417
exit()
1518

@@ -106,6 +109,7 @@ def cli_world(name, tibiadata, json):
106109
@click.option("-td", "--tibiadata", default=False, is_flag=True)
107110
@click.option("-js", "--json", default=False, is_flag=True)
108111
def cli_worlds(tibiadata, json):
112+
"""Displays the list of worlds and their data."""
109113
worlds = _fetch_and_parse(ListedWorld.get_list_url, ListedWorld.list_from_content,
110114
ListedWorld.get_list_url_tibiadata, ListedWorld.list_from_tibiadata,
111115
tibiadata)
@@ -116,18 +120,19 @@ def cli_worlds(tibiadata, json):
116120
import json as _json
117121
print(_json.dumps(worlds, default=ListedWorld._try_dict, indent=2))
118122
return
119-
print(print_world_overview(worlds))
123+
print(print_world_list(worlds))
120124

121125

122126
@cli.command(name="house")
123-
@click.argument('id')
127+
@click.argument('house_id')
124128
@click.argument('world')
125129
@click.option("-td", "--tibiadata", default=False, is_flag=True)
126130
@click.option("-js", "--json", default=False, is_flag=True)
127-
def cli_house(id, world, tibiadata, json):
131+
def cli_house(house_id, world, tibiadata, json):
132+
"""Displays information about a house."""
128133
house = _fetch_and_parse(House.get_url, House.from_content,
129134
House.get_url_tibiadata, House.from_tibiadata,
130-
tibiadata, id, world)
135+
tibiadata, house_id, world)
131136
if json and house:
132137
print(house.to_json(indent=2))
133138
return
@@ -141,6 +146,7 @@ def cli_house(id, world, tibiadata, json):
141146
@click.option("-js", "--json", default=False, is_flag=True)
142147
@click.option("-gh", "--guildhalls", default=False, is_flag=True)
143148
def cli_houses(world, town, tibiadata, json, guildhalls):
149+
"""Displays the list of houses of a world."""
144150
town = " ".join(town)
145151
house_type = HouseType.GUILDHALL if guildhalls else HouseType.HOUSE
146152
houses = _fetch_and_parse(ListedHouse.get_list_url, ListedHouse.list_from_content,
@@ -221,7 +227,7 @@ def get_character_string(character: Character): # NOSONAR
221227
content += build_header("Other Characters")
222228
for other_char in character.other_characters:
223229
content += "- %s - %s - %s\n" % (other_char.name, other_char.world, "online" if other_char.online else
224-
("deleted" if other_char.deleted else "offline"))
230+
("deleted" if other_char.deleted else "offline"))
225231
return content
226232

227233

@@ -311,14 +317,12 @@ def print_world(world: World):
311317
return content
312318

313319

314-
def print_world_overview(world_overview):
320+
def print_world_list(world_list):
315321
content = build_header("Game World Overview", "=")
316-
content += get_field("Total online", world_overview.total_online)
317-
content += get_field("Overall Maximum", "%d players on %s" % (world_overview.record_count,
318-
world_overview.record_date))
322+
content += get_field("Total online", sum(w.online_count for w in world_list))
319323

320324
content += build_header("Worlds")
321-
for world in world_overview.worlds:
325+
for world in world_list:
322326
content += "%s - %d Online - %s - %s\n" % (world.name, world.online_count, world.location, world.pvp_type)
323327
return content
324328

@@ -335,7 +339,7 @@ def get_house_string(house):
335339
if house.status == "auctioned":
336340
content += get_field("Highest bid", "%d gold by %s, auction ends on %s" %
337341
(house.highest_bid, house.highest_bidder, house.auction_end)
338-
if house.highest_bidder else "None")
342+
if house.highest_bidder else "None")
339343
else:
340344
content += get_field("Rented by", "%s, paid until %s" % (house.owner, house.paid_until))
341345
if house.transfer_date:

0 commit comments

Comments
 (0)