Skip to main content

Asynchronous API wrapper for the Dagbot API (http://dagpi.tk)

Reason this release was yanked:

Depreceated, Will 100% not work. PLEASE USE Version 2+

Project description

asyncdagpi

An async wrapper for http://dagpi.tk

Build Status License codestyle version python

Documentation for asyncdagpi

1) Obtain a token


Join the discord server here and verify yourself. Once done you can easily apply for a token via the process detailed.

2) Install the library


Use pip to install the library

pip install asyncdagpi

3) Initialise the client


from asycncdagpi import Client
API_CLIENT = Client('insert_your_token')

With this you should have a working API client that can help you authenticate and process api requests

4) Use One of the Features listed below with your client instance


  • staticimage
  • gif
  • usertextimage
  • textimage

These categories have a lot of features. A list of features can be found below or in the API documentation at docs

You can use the client with a feature as follows:

async def wanted(image_url:str):
    response = await API_CLIENT.staticimage('wanted'image_url)

5) Using the Response


The client returns an BytesIO object as a default response. The BytesIO response can be used in a lot of ways. Read the documentation here : BytesIOdocs in the BytesIO section.

The examples below depict a few use cases

Saving Response to file

async def wanted(image_url:str):
    response = await API_CLIENT.staticimage('wanted',image_url)
    with open('wanted.png''wb') as out:
        out.write(response.read())

Opening The response with Pillow (PIL)

from PIL import Image
async def wanted(image_url:str):
    response = await API_CLIENT.staticimage('wanted',image_url)
    image = Image.open(response)

Using the Discord.py library and sending response as a file

please do remember to get a discord api token and run the bot using that.

Get help with discord.py at dpy server

import discord
from discord.ext import commands
bot = commands.Bot(command_prefix = '.')
@bot.command()
async def wanted(ctximage_url:str):
    response = await API_CLIENT.staticimage('wanted',image_url)
    file = discord.File(response,filename='wanted.png')
    await ctx.send(file=file)  

6) Handling Exceptions


- InvalidOption

This exception is raised when the feature chose ie. wanted is not a valid feature from the available options.

- BadUrl

The api uses regex to validate urls. When an improper url is passed to the API this exception is raised

- ValueError

This is when the API returns a non 200 code ie means an error occurred. This exception throws the status code along with a message explaining the status code. The description of status codes can be found in the API docs.

Categories and their subsequent features


staticimage

This returns an png image (as BytesIO) and requires the image_url for a static image.

API_CLIENT.usertextimage(feature,image_url)

# feature - one of the features
# image_url - a static image url

Features:

  • wanted
  • evil
  • bad
  • hitler
  • angel
  • trash
  • satan

Gif

Returns a gif (as BytesIO). Takes either a static_image url or a gif url and returns a gif. Irrespective of the inupt output is always a gif.

API_CLIENT.usertextimage(feature,image_url)

# feature - one of the features
# image_url - a gif or static image_url

Features:

  • paint
  • solar
  • blur
  • invert
  • pixel
  • sepia
  • wasted
  • gay
  • charcoal

usertextimage

Returns a png (as BytesIO). Takes in the following arguments

API_CLIENT.usertextimage(feature,image_url,text,name)

# feature - one of the features
# image_url - a static image url
# text - the text the person will say
# name - the username that will be used for the person

Features:

  • tweet
  • quote (discord message)

textimage

Depending in the feature and imput either returns a static or gif image as BytesIO.

API_CLIENT.usertextimage(feature,image_url,text)

# feature - one of the features
# image_url - a static image url
# text - the text the person will say

Features:

  • Thoughtimage: always returns a static response
  • meme : based in type of input image_url returns a gif or png as BytesIO

Project details


Download files

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

Source Distribution

asyncdagpi-1.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

asyncdagpi-1.1.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file asyncdagpi-1.1.0.tar.gz.

File metadata

  • Download URL: asyncdagpi-1.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1

File hashes

Hashes for asyncdagpi-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e11b564d7bf09038f33424d7bb30a9ca9d25fa5cbd7becfc0f09e9554834c573
MD5 668e1bd3f4f8849c4710bf625496335e
BLAKE2b-256 02c04ffe64d8b62732135f57b19042ca9f042bb96b8c18764fb7127101266cd9

See more details on using hashes here.

File details

Details for the file asyncdagpi-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: asyncdagpi-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.1

File hashes

Hashes for asyncdagpi-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad05ae8949cb0a2183a50f715f4019a0808b30bbf2ae7c8108475bcc1a5f0397
MD5 f5ceb62209d86781f072bd6f739f5b06
BLAKE2b-256 4031fc2f9c7875436c3fde806e5b3897e6dfcf19b243b2a9c99c6b133d9e908c

See more details on using hashes here.

Supported by

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