Improved docs, fixed some typos

This commit is contained in:
DarkCat09 2022-12-25 19:17:49 +04:00
parent 496049c9b5
commit 2d0af206ca
5 changed files with 46 additions and 42 deletions

View file

@ -97,8 +97,10 @@ so you don't need to do it by yourself now.
Before, you should save session manually: Before, you should save session manually:
```python ```python
# ****
# This code is useless in new versions, # This code is useless in new versions,
# because they do it automatically. # because they do it automatically.
# ****
from python_aternos import Client from python_aternos import Client
@ -119,13 +121,13 @@ myserv = at.list_servers()[0]
... ...
``` ```
Function `save_session()` writes session cookie and cached servers list to `.aternos` file in your home directory. Function `save_session()` writes the session cookie and the cached servers list to `.aternos` file in your home directory.
`restore_session()` creates Client object from session cookie and restores servers list. `restore_session()` creates a Client object from the session cookie and restores the servers list.
This feature reduces the count of network requests and allows you to log in and request servers much faster. This feature reduces the count of network requests and allows you to log in and request servers much faster.
If you created a new server, but it doesn't appear in `list_servers` result, call it with `cache=False` argument. If you have created a new server, but it doesn't appear in `list_servers` result, call it with `cache=False` argument.
```python ```python
# Refreshing list # Refresh the list
servers = at.list_servers(cache=False) servers = at.list_servers(cache=False)
``` ```
@ -167,7 +169,7 @@ at.change_password_hashed(my_passwd, new_passwd)
## Two-Factor Authentication ## Two-Factor Authentication
2FA is a good idea if you think that the password 2FA is a good idea if you think that the password
is not enough to protect your account. is not enough to protect your account.
It has been recently added to python-aternos. It was recently added to python-aternos.
### Log in with code ### Log in with code
Here's how to log in to an account: Here's how to log in to an account:
@ -198,12 +200,12 @@ Also, the library allows to enable it.
>>> response >>> response
{'qrcode': 'data:image/png;base64,iV...', 'secret': '7HSM...'} {'qrcode': 'data:image/png;base64,iV...', 'secret': '7HSM...'}
``` ```
As you can see, Aternos responses with As you can see, Aternos responds with
QR code picture encoded in base64 a QR code picture encoded in base64
and a plain secret code. and a plain secret code.
- Enter this code into your 2FA application - Enter the secret code into your 2FA application
**or** save the QR into a file: **OR** save the QR into a file:
```python ```python
>>> qr = response.get('qrcode', '') >>> qr = response.get('qrcode', '')
>>> at.save_qr(qr, 'test.png') >>> at.save_qr(qr, 'test.png')

View file

@ -38,7 +38,7 @@ but I chose an easier name for the class.)
- `FileType.dir` and `FileType.directory` - `FileType.dir` and `FileType.directory`
- `size` - File size in bytes, float. - `size` - File size in bytes, float.
`0.0` for directories and `0.0` for directories and
`-1.0` when error occures. `-1.0` when an error occurs.
- `deleteable`, `downloadable` and `editable` are explained in the next section. - `deleteable`, `downloadable` and `editable` are explained in the next section.
### File ### File
@ -208,18 +208,23 @@ def read():
def write(content): def write(content):
# set_text and set_content # set_text and set_content
# uses the same URLs. # uses the same URLs,
# I prefer set_content # so there's no point in checking
# if the file is editable/downloadable
# but we need to convert content to bytes # Code for set_text:
#ops.set_text(content)
# Code for set_content:
# Convert the str to bytes
content = content.encode('utf-8') content = content.encode('utf-8')
# Edit
ops.set_content(content) ops.set_content(content)
# It contains empty list [] by default # ops.json contains an empty list [] by default
oper_raw = read() oper_raw = read()
# Convert to Python list # Convert it to a Python list
oper_lst = json.loads(oper_raw) oper_lst = json.loads(oper_raw)
# Add an operator # Add an operator

View file

@ -1,6 +1,6 @@
# How-To 3: Players lists # How-To 3: Players lists
You can add a player to operators, You can add a player to operators,
include in the whitelist or ban include into the whitelist or ban him
using this feature. using this feature.
## Common usage ## Common usage
@ -33,7 +33,7 @@ For example, I want to ban someone:
serv.players(Lists.ban).add('someone') serv.players(Lists.ban).add('someone')
``` ```
And give myself operator rights: And give myself the operator rights:
```python ```python
serv.players(Lists.ops).add('DarkCat09') serv.players(Lists.ops).add('DarkCat09')
``` ```

View file

@ -1,6 +1,6 @@
# How-To 2: Controlling Minecraft server # How-To 2: Controlling Minecraft server
In the previous part we logged into account and started a server. In the previous part we've logged into an account and have started a server.
But python-aternos can do much more. But python-aternos can do much more.
## Basic methods ## Basic methods
@ -32,7 +32,7 @@ serv.confirm()
`start()` can be called with arguments: `start()` can be called with arguments:
- headstart (bool): Start server in headstart mode - headstart (bool): Start server in headstart mode
which allows you to skip all queue. which allows you to skip all the queue.
- accepteula (bool): Automatically accept Mojang EULA. - accepteula (bool): Automatically accept Mojang EULA.
If you want to launch your server instantly, use this code: If you want to launch your server instantly, use this code:
@ -45,18 +45,18 @@ serv.start(headstart=True)
This object contains an error code, on which depends an error message. This object contains an error code, on which depends an error message.
- EULA was not accepted (code: `eula`) - - EULA was not accepted (code: `eula`) -
remove `accepteula=False` or run `serv.eula()` before startup. remove `accepteula=False` or run `serv.eula()` before the server startup.
- Server is already running (code: `already`) - - Server is already running (code: `already`) -
you don't need to start server, it is online. you don't need to start the server, it is online.
- Incorrect software version installed (code: `wrongversion`) - - Incorrect software version installed (code: `wrongversion`) -
if you have *somehow* installed non-existent software version (e.g. `Vanilla 2.16.5`). if you have *somehow* installed non-existent software version (e.g. `Vanilla 2.16.5`).
- File server is unavailable (code: `file`) - - File server is unavailable (code: `file`) -
problems in Aternos servers, view [https://status.aternos.gmbh](https://status.aternos.gmbh) problems on Aternos servers, view [https://status.aternos.gmbh](https://status.aternos.gmbh)
- Available storage size limit has been reached (code: `size`) - - Available storage size limit has been reached (code: `size`) -
files on your Minecraft server have reached 4GB limit files on your Minecraft server have reached 4GB limit
(for exmaple, too much mods or loaded chunks). (for exmaple, too much mods or loaded chunks).
Always wrap `start` into try-catch. Always wrap `start` into try-except.
```python ```python
from python_aternos import ServerStartError from python_aternos import ServerStartError
@ -72,7 +72,7 @@ except ServerStartError as err:
## Cancellation ## Cancellation
Server launching can be cancelled only when you are waiting in a queue. Server launching can be cancelled only when you are waiting in a queue.
After queue, when the server starts and writes something to the log, After queue, when the server starts and writes something to the log,
you can just `stop()` it, not `cancel()`. you can just `stop()` it, **not** `cancel()`.
## Server info ## Server info
```python ```python
@ -130,7 +130,7 @@ False
>>> serv.restart() >>> serv.restart()
# Title on web site: "Loading" # Title on the web site: "Loading"
>>> serv.css_class >>> serv.css_class
'loading' 'loading'
>>> serv.status >>> serv.status
@ -144,7 +144,7 @@ False
>>> serv.status_num == Status.starting >>> serv.status_num == Status.starting
False False
# Title on web site: "Preparing" # Title on the web site: "Preparing"
>>> serv.css_class >>> serv.css_class
'loading' 'loading'
>>> serv.status >>> serv.status
@ -158,7 +158,7 @@ False
>>> serv.status_num == Status.on >>> serv.status_num == Status.on
False False
# Title on web site: "Starting" # Title on the web site: "Starting"
>>> serv.css_class >>> serv.css_class
'loading starting' 'loading starting'
>>> serv.status >>> serv.status
@ -175,7 +175,7 @@ False
``` ```
## Changing subdomain and MOTD ## Changing subdomain and MOTD
To change server subdomain or Message-of-the-Day, To change the server's subdomain or Message-of-the-Day,
just assign a new value to the corresponding fields: just assign a new value to the corresponding fields:
```python ```python
serv.subdomain = 'new-test-server123' serv.subdomain = 'new-test-server123'
@ -183,13 +183,13 @@ serv.motd = 'Welcome to the New Test Server!'
``` ```
## Updating status ## Updating status
python-aternos don't refresh server information by default. Python-Aternos don't refresh server information by default.
This can be done with [WebSockets API](websocket) automatically This can be done with [WebSockets API](/howto/websocket) automatically
(but it will be explained later in the 6th part of how-to guide), (but it will be explained later in the 6th part of how-to guide),
or with `fetch()` method manually (much easier). or with `fetch()` method manually (much easier).
`fetch()` called also when an AternosServer object is created `fetch()` is also called when an AternosServer object is created
to get info about the server: to get this info about the server:
- full address, - full address,
- MOTD, - MOTD,
@ -198,7 +198,7 @@ to get info about the server:
- status, - status,
- etc. - etc.
Use it if you want to see new data one time: Use it if you want to see the new data *one time*:
```python ```python
import time import time
from python_aternos import Client from python_aternos import Client
@ -214,13 +214,13 @@ time.sleep(10)
serv.fetch() serv.fetch()
print('Server is', serv.status) # Server is online print('Server is', serv.status) # Server is online
``` ```
But this method is **not** a good choice if you want to get real-time updates. But this method is **not** a good choice if you want to get *real-time* updates.
Read [How-To 6: Real-time updates](websocket) about WebSockets API Read [How-To 6: Real-time updates](/howto/websocket) about WebSockets API
and use it instead of refreshing data in a while-loop. and use it instead of refreshing data in a while-loop.
## Countdown ## Countdown
Aternos stops a server when there are no players connected. Aternos stops a server when there are no players connected.
You can get remained time in seconds using `serv.countdown`. You can get the remained time in seconds using `serv.countdown`.
For example: For example:
```python ```python

View file

@ -42,12 +42,9 @@ class AternosConnect:
self.atcookie = '' self.atcookie = ''
def add_args(self, **kwargs) -> None: def add_args(self, **kwargs) -> None:
"""Pass arguments to CloudScarper """Pass arguments to CloudScraper
session object __init__ session object __init__
if kwargs is not empty if kwargs is not empty
Args:
**kwargs: Keyword arguments
""" """
if len(kwargs) < 1: if len(kwargs) < 1: