Git Product home page Git Product logo

randomstuff.py's Introduction

Development Notice

As of April 2023, due to lack of activity and maintanence of Random Stuff API and busy schedule of the maintainer of this package, this package is not being maintained and is not likely to work for the newer (or even older) versions of API.

randomstuff.py

A simple and easy to use, async-ready API wrapper around Random Stuff API.


Features

  • Easy to use, pythonic and Object Oriented interface
  • Implements the entire API
  • Support for both synchronous and asynchronous usage

Installation

Installation can be done easily using the python package manager pip

python -m pip install -U randomstuff.py

To install development (potentially unstable) version:

python -m pip install git+https://github.com/nerdguyahmad/randomstuff.py

Quickstart

Make sure to get the API key from here

Basic Usage

import randomstuff

with randomstuff.Client(api_key='api-key-here') as client:
  response = client.get_ai_response("Hi there")
  print(response.message)

Async Usage

import randomstuf

async with randomstuff.AsyncClient(api_key='api-key-here') as client:
  response = await client.get_ai_response('Hey there')
  print(response.message)

More examples can be found in documentation

Contribution

Feel free to contribute by either opening an issue or a pull request.

See the Contribution Guide for more info.

randomstuff.py's People

Contributors

devinfinix avatar hunter2809 avatar izxxr avatar marzaelise avatar sachin-sankar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

randomstuff.py's Issues

AttributeError on rate limits

API returns a list with first element as message which causes the library to raise AttributeError:

'str' object has no attribute get

[TODO] Warnings not coloured properly

The warnings that are supposed to be orange in terminal are only orange on Linux based systems. On windows, It simply prints the raw code.

Possible Workaround

Use colorama.init() on windows.

`randomstuff.AuthError` not raising when providing wrong API key.

Description

When you provide the wrong API key in randomstuff.Client or randomstuff.AsyncClient, It is supposed to raise randomstuff.errors.AuthError on next API call but it doesn't. Instead, It simply returns "unauthorized".

Steps to Reproduce

  1. Make an instance of randomstuff.Client or randomstuff.AsyncClient with wrong or invalid API key in key parameter.
  2. Make an API call.

Expected results

It should raise randomstuff.errors.AuthError.

Obtained results

It returns unauthorized message as a string.

Possible fixes

The error code in if statement on line 39 in client.py probably has wrong status code.

Update and add examples

More examples should be added in favor of customisations support in AI response to examples directory and previous ones should be updated according to new changes

Support for version 4 & version 2 deprecation

Version 4 has been officially released and I'm working on adding support in the API. This issue covers what needs to be implemented in wrapper & what should be removed. This issue is for you to read if you're looking to contribute to the wrapper towards version 4 support.

get_ai_response_beta() method raises KeyError because endpoint has changed.

  • Endpoint for version 4 is now https://api.pgamerx.com/v4/

Changes

These are current apparent changes to wrapper design and methods. Version 4 seems to be leading to redesign of AI response method.

  • AI response: Parameters have changed. We would have to use kwargs for this method from now to keep up with the API.
  • Other methods don't have anything changed yet. Jokes are expected to change but they are same for now.
  • Add "4" in constants.VERSIONS
  • I don't know about responses yet but they are apparently same, if there's any change, I'll put it here.

Removals

This mainly includes deprecation of version 2.

  • Remove conditionals checking for version 2 as well as requests to version 2.
  • Remove "2" from constants.VERSIONS

Release

Version 4 support of wrapper is expected to be available in 1 or 2 days.

Warning for version 2 users

The version 2 of API has been deprecated both by API and wrapper. If you are using version 2 still, Please change to version 3 as soon as possible. There are no code changes. The wrapper handles all the stuff for you.

Consequences of not migrating

  • Even if you don't update wrapper, Once version 2 is deprecated by API itself, you simply will get errors when using it.
  • After updating wrapper, Using version 2 will cause you to get errors.VersionError.

[ TODO ] NameError on invalid plan, server, or type

Description

When invalid plan or server is selected it raises a NameError

Expected behaviour

InvalidPlanError or InvalidServerError should be raised.

Actual behaviour

NameError is raised.

Possible fix

Simply replace the old exceptions names i.e ServerError and PlanError with new names, InvalidPlanError and InvalidServerError.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.