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:
```python
# ****
# This code is useless in new versions,
# because they do it automatically.
# ****
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.
`restore_session()` creates Client object from session cookie and restores servers list.
Function `save_session()` writes the session cookie and the cached servers list to `.aternos` file in your home directory.
`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.
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
# Refreshing list
# Refresh the list
servers = at.list_servers(cache=False)
```
@ -167,7 +169,7 @@ at.change_password_hashed(my_passwd, new_passwd)
## Two-Factor Authentication
2FA is a good idea if you think that the password
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
Here's how to log in to an account:
@ -198,12 +200,12 @@ Also, the library allows to enable it.
>>> response
{'qrcode': 'data:image/png;base64,iV...', 'secret': '7HSM...'}
```
As you can see, Aternos responses with
QR code picture encoded in base64
As you can see, Aternos responds with
a QR code picture encoded in base64
and a plain secret code.
- Enter this code into your 2FA application
**or** save the QR into a file:
- Enter the secret code into your 2FA application
**OR** save the QR into a file:
```python
>>> qr = response.get('qrcode', '')
>>> at.save_qr(qr, 'test.png')

View file

@ -25,7 +25,7 @@ let's assign it to `fm` variable:
## File info
AternosFile object can point to
both a file and a directory
and contain almost the same properties and methods.
and contain almost the same properties and methods.
(So it's more correct to call it "Object in the server's filesystem",
but I chose an easier name for the class.)
@ -38,7 +38,7 @@ but I chose an easier name for the class.)
- `FileType.dir` and `FileType.directory`
- `size` - File size in bytes, float.
`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.
### File
@ -208,18 +208,23 @@ def read():
def write(content):
# set_text and set_content
# uses the same URLs.
# I prefer set_content
# uses the same URLs,
# 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')
# Edit
ops.set_content(content)
# It contains empty list [] by default
# ops.json contains an empty list [] by default
oper_raw = read()
# Convert to Python list
# Convert it to a Python list
oper_lst = json.loads(oper_raw)
# Add an operator

View file

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

View file

@ -1,6 +1,6 @@
# 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.
## Basic methods
@ -32,7 +32,7 @@ serv.confirm()
`start()` can be called with arguments:
- 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.
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.
- 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`) -
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`) -
if you have *somehow* installed non-existent software version (e.g. `Vanilla 2.16.5`).
- 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`) -
files on your Minecraft server have reached 4GB limit
(for exmaple, too much mods or loaded chunks).
Always wrap `start` into try-catch.
Always wrap `start` into try-except.
```python
from python_aternos import ServerStartError
@ -72,7 +72,7 @@ except ServerStartError as err:
## Cancellation
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,
you can just `stop()` it, not `cancel()`.
you can just `stop()` it, **not** `cancel()`.
## Server info
```python
@ -130,7 +130,7 @@ False
>>> serv.restart()
# Title on web site: "Loading"
# Title on the web site: "Loading"
>>> serv.css_class
'loading'
>>> serv.status
@ -144,7 +144,7 @@ False
>>> serv.status_num == Status.starting
False
# Title on web site: "Preparing"
# Title on the web site: "Preparing"
>>> serv.css_class
'loading'
>>> serv.status
@ -158,7 +158,7 @@ False
>>> serv.status_num == Status.on
False
# Title on web site: "Starting"
# Title on the web site: "Starting"
>>> serv.css_class
'loading starting'
>>> serv.status
@ -175,7 +175,7 @@ False
```
## 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:
```python
serv.subdomain = 'new-test-server123'
@ -183,13 +183,13 @@ serv.motd = 'Welcome to the New Test Server!'
```
## Updating status
python-aternos don't refresh server information by default.
This can be done with [WebSockets API](websocket) automatically
Python-Aternos don't refresh server information by default.
This can be done with [WebSockets API](/howto/websocket) automatically
(but it will be explained later in the 6th part of how-to guide),
or with `fetch()` method manually (much easier).
`fetch()` called also when an AternosServer object is created
to get info about the server:
`fetch()` is also called when an AternosServer object is created
to get this info about the server:
- full address,
- MOTD,
@ -198,7 +198,7 @@ to get info about the server:
- status,
- 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
import time
from python_aternos import Client
@ -214,13 +214,13 @@ time.sleep(10)
serv.fetch()
print('Server is', serv.status) # Server is online
```
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
But this method is **not** a good choice if you want to get *real-time* updates.
Read [How-To 6: Real-time updates](/howto/websocket) about WebSockets API
and use it instead of refreshing data in a while-loop.
## Countdown
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:
```python

View file

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