mirror of
https://github.com/status-im/status-python-sdk.git
synced 2026-08-30 21:51:14 +00:00
properties: bio
- Add bio functionality - Add documentation
This commit is contained in:
+31
-1
@@ -1,4 +1,4 @@
|
||||
from typing import Optional, Union, Generator
|
||||
from typing import Optional, Union, Generator, Any
|
||||
import requests, datetime, re
|
||||
from .signal import Signal
|
||||
|
||||
@@ -129,6 +129,7 @@ class Account:
|
||||
"compressed_key": event["compressedKey"],
|
||||
"mnemonic": event["mnemonic"],
|
||||
"display_name": event["display-name"],
|
||||
"bio": event.get("bio", ""),
|
||||
"password": password,
|
||||
"wallet_address": event["address"],
|
||||
"logged_in_timestamp": datetime.datetime.now()
|
||||
@@ -180,6 +181,35 @@ class Account:
|
||||
self.signal.get("envelope.sent")
|
||||
self.__info["display_name"] = name
|
||||
|
||||
@property
|
||||
def bio(self) -> str:
|
||||
"""
|
||||
Get the current bio
|
||||
"""
|
||||
return self.info["bio"]
|
||||
|
||||
@bio.setter
|
||||
def bio(self, bio: Any):
|
||||
if isinstance(bio, type(None)):
|
||||
bio = ""
|
||||
|
||||
bio = str(bio).strip()
|
||||
# Limit based from Status App
|
||||
CHARACTERS = 240
|
||||
if len(bio) > CHARACTERS:
|
||||
raise ValueError(f"Bio cannot be longer than {CHARACTERS} characters...")
|
||||
|
||||
self.__call_rpc("messaging", "setBio", [bio])
|
||||
# It seems that if a valid bio is given, it will be instantly updated
|
||||
# However after tracing the signals, an `envelope.sent` is sent a bit
|
||||
# after the bio has been updated.
|
||||
self.signal.get("envelope.sent")
|
||||
self.__info["bio"] = bio
|
||||
|
||||
@bio.deleter
|
||||
def bio(self):
|
||||
self.bio = ""
|
||||
|
||||
@property
|
||||
def contacts(self) -> dict[str, dict]:
|
||||
"""
|
||||
|
||||
+56
-1
@@ -530,7 +530,7 @@ account.login(**params)
|
||||
print(account.display_name)
|
||||
```
|
||||
|
||||
You can also update the display name by assigning a new value:
|
||||
You can update the display name by assigning a new value:
|
||||
|
||||
```python
|
||||
from bot import Account
|
||||
@@ -548,3 +548,58 @@ print(account.display_name)
|
||||
```
|
||||
|
||||
**Note**: Next time you login with the changed display name, you will have to put in the new display name, instead of the initial one.
|
||||
|
||||
### `bio`
|
||||
|
||||
Get or update the **bio** of the currently logged‑in account. The length of the bio (as in Status App) is 240 characters.
|
||||
|
||||
Returns `str` when reading the property.
|
||||
|
||||
```python
|
||||
from bot import Account
|
||||
|
||||
account = Account()
|
||||
params = {
|
||||
"display_name": "status-app-bot",
|
||||
"password": "SNTPUMP"
|
||||
}
|
||||
account.login(**params)
|
||||
|
||||
# Read the current bio
|
||||
print(account.bio)
|
||||
```
|
||||
|
||||
The value assigned to `bio` will automatically be converted to a string before being sent to the backend. You can update the bio by assigning a new value:
|
||||
|
||||
```python
|
||||
from bot import Account
|
||||
|
||||
account = Account()
|
||||
params = {
|
||||
"display_name": "status-app-bot",
|
||||
"password": "SNTPUMP"
|
||||
}
|
||||
account.login(**params)
|
||||
|
||||
# Update the bio
|
||||
account.bio = "Monitoring Status communities and chats"
|
||||
print(account.bio)
|
||||
```
|
||||
|
||||
You can also **clear the bio** by deleting the property:
|
||||
|
||||
```python
|
||||
from bot import Account
|
||||
|
||||
account = Account()
|
||||
params = {
|
||||
"display_name": "status-app-bot",
|
||||
"password": "SNTPUMP"
|
||||
}
|
||||
account.login(**params)
|
||||
|
||||
# Clears the bio - same as:
|
||||
# account.bio = ""
|
||||
# account.bio = None
|
||||
del account.bio
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user