Countdown

This commit is contained in:
DarkCat09 2022-12-23 17:38:51 +04:00
parent 403f9005a9
commit 413fabb1a9
2 changed files with 50 additions and 0 deletions

View file

@ -217,3 +217,41 @@ 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
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`.
For example:
```python
# Start
serv.start()
# Get the countdown value
print(serv.countdown, 'seconds')
# -1 seconds
# means "null" in countdown field
# Wait for start up
time.sleep(10)
# Refresh info
serv.fetch()
# Get countdown value
print(serv.countdown, 'seconds')
# 377 seconds
# Check if countdown changes
time.sleep(10)
serv.fetch()
print(serv.countdown, 'seconds')
# 367 seconds
# ---
# Convert to minutes and seconds
mins, secs = divmod(serv.countdown, 60)
print(f'{mins}:{secs:02}') # 6:07
# OR
cd = serv.countdown
print(f'{cd // 60}:{cd % 60:02}') # 6:07
```

View file

@ -450,3 +450,15 @@ class AternosServer:
"""
return int(self._info['ram'])
@property
def countdown(self) -> int:
"""Server stop countdown
in seconds
Returns:
Stop countdown
"""
value = self._info['countdown']
return int(value or -1)