Skip to main content

Public topic consumer for Chat Wars API

Project description

PyWars

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

🚀 Motivations

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

☄ Quick start

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

from PyWars import Client
app = Client()

This will create a client with an autogenerated id for chat wars v2 api


Specifiying client version

from PyWars import Client
app = Client(version=Client.Version.CW3)

This will create a client for chat wars v3 api


Adding agents

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

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

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

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 page.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PyWars-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file PyWars-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: PyWars-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6

File hashes

Hashes for PyWars-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e5d22fab3fbd9e5c5aeac76969d75dee1e0d3d05a0dc4b9390f02de3354453d
MD5 ec4defdcc73579a20ca8e85b158fd6b8
BLAKE2b-256 5d1172fc41e687e1a724375c478fb08cfde37a815dfe1350ed8f468e70df1d81

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page