Metadata-Version: 2.1
Name: pywars
Version: 0.1.1
Summary: Public topic consumer for Chat Wars API
License: MIT
Author: Jesús Enrique
Author-email: jesusefg12@gmail.com
Requires-Python: >=3.6,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Provides-Extra: dev
Requires-Dist: faust (==1.10.4)
Requires-Dist: illiterate (>=0.4,<0.5); (python_version >= "3.6" and python_version < "4.0") and (extra == "dev")
Requires-Dist: mkdocs (>=1.0.4,<2.0.0); extra == "dev"
Requires-Dist: mkdocs-material (>=4.6.0,<5.0.0); extra == "dev"
Requires-Dist: pymdown-extensions (>=8.2,<9.0); extra == "dev"
Description-Content-Type: text/markdown

# PyWars

> A public topic consumer for Chat Wars ... **with steroids**


## 🚀 Motivations

- 🤖 Build a bot? 
- 👥 Help comunity? 
- 🚀 Personal training?


## ☄ Quick start

```python
from PyWars import *

app = Client()

@app.agent(Deal)
async def deals(stream:Stream[Deal]):
    async for deal in stream:
        print(deal)

app.run()
```
## 📚 Overview

### Dummy client creation

```python
from PyWars import Client
app = Client()
```
>This will create a client with an autogenerated id for chat wars **v2** api

----------


### Specifiying client version

```python
from PyWars import Client
app = Client(version=Client.Version.CW3)
```
>This will create a client for chat wars **v3** api

----------

### Adding agents

```python
from PyWars import *
app = Client()

@app.agent(Deal)
async def deals(stream:Stream[Deal]):
    async for deal in stream:
        print(deal)

app.run()
```
The **Client.agent** method recieves an allowed record. The allowed records are:

- **Deal** for *cw\*-deals* topic
- **Duel** for *cw\*-duels* topic
- **Offer** for *cw\*-offers* topic
- **SexDigest** for *cw\*-sex_digest* topic
- **YellowPage** for *cw\*-yellow_pages* topic
- **AuctionDigest** for *cw\*-au_digest* topic

----------

### Adding timers

```python
from PyWars import *
app = Client()
procesed_deals = 0

@app.agent(Deal)
async def deals(stream:Stream[Deal]):
    async for deal in stream:
        procesed_deals += 1

@app.timer(60)
async def print_procesed():
    print(procesed_deals)
    procesed_deals = 0

app.run()
```
A timer is a courutine that is triggered every *n* seconds in the previous examples we used *60 seconds*.

----------

### Using executions loops

```python
from PyWars import *
import asyncio

app = Client(loop=asyncio.get_event_loop())

@app.agent(Deal)
async def deals(stream:Stream[Deal]):
    async for deal in stream:
        print(deal)
try:
    app.start()
finally:
    app.stop()
```

The magical start and stop methods were thought to run and stop client with his execution loop smootly

----------

### Bulking

```python
from PyWars import *

app = Client()

@app.agent(Deal)
async def deals(stream:Stream[Deal]):
    async for bulk in stream.take(100, 10):
        print(bulk)

app.run()
```
A bulk is just the use of **Stream.take** method from **faust**. It will try to take bulks of 100 objetcs, in case that it can´t return the 100 objects its going to wait for 10 seconds and return any amount gathered in that time.

----------

For extended documentation see for the [docs](https://Gaspect.github.io/PyWars/) page.

