Skip to main content

No project description provided

Project description

# Kutana
## Powerfull processor for vk api: recaive, process, make requests to api.
- Is asynchronous
- Is fast
- Is light
- Is simple
- Is stable
- Offers basic low level control

---

Example code:
```py
from kutana import Manager, method

async def callback(obj_type, obj, group):
if obj_type != "message_new":
return

await method("messages.send", **group, user_id=obj["user_id"],
message="You wrote:\n" + obj["body"])

async def token_callback(action, token, adddata):
print("Token `" + token + "`. Action: " + action +
". Additional data: " + str(adddata))

manager = Manager(
"TOKEN1",
"TOKEN2",
"TOKEN3",
...,
callback=callback, token_callback=token_callback
)

manager.run()
```

---

`Manager(self, \*tokens, callback=None, path=None, conf=None, token_callback=None)`
- Tokens - groups' tokens.
- Path is path to configuration file.
- Conf is dictionary with configuration (replace for path).
- Callback - coroutine for event processing (obj_type, obj, group).
- Token callback - coroutine for subscribing to token adding/removing (action [add, remove], token, data from query).

`Manager.info`
```py
self.info = {
"api": self.api_url, # url for api requests
"list": self.api_url + "/tokens", # url for getting list of tokens
"add": self.api_url + "/addtoken/{token}", # url for token addition
"remove": self.api_url + "/removetoken/{token}" # url for token removal
}
```

---

`Group` from callback.
- Is a dict with group_id in "group_id" and api url in "group_id".
- You can make a post request to api url with required post data:
- `wait` - True if you want result of your request to api.
- `method` - method you are calling to (example: `messages.send`).
- `group_id` - is of the group you want to send request from .
- `kwargs` - json encoded dict with arguments for your request.

---

Default configuration:
```json
{
"host": "localhost",
"port": 5731,
"pause": 0.2,
"accept_events": ["message_new"],

"key": ""
}
```

- Host, port - host and port to serve server on.
- Pause - how many requests to VKAPI is allowed.
- Accept events - group_join, group_leave, message_new e.t.c.
- Key - secret code for url to your server. Random if empty.

---

With helper `Wrapper` you can do neat things.
```py
from kutana import Wrapper

async def callback(obj_type, obj, group):
if obj_type != "message_new":
return

wrapper = Wrapper(obj_type, obj, group)

await wrapper.answer("Text")

with open("image.png", "rb") as o:
raw_photos = await wrapper.upload_photo(o.read())

await wrapper.answer("Photo:", attachments=wrapper.parse_photos(*raw_photos))

print(await wrapper.method("groups.getById"))

...
```

```py
async def callback(*args):
if args[0] != "message_new":
return

await Wrapper(*args).answer("Text")
```

Project details


Release history Release notifications

This version
History Node

1.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
kutana-1.2.tar.gz (7.1 kB) Copy SHA256 hash SHA256 Source None May 10, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page