Skip to main content

An asynchronous and simplified Telegraph API Wrapper in Python

Project description

nusuGraph

An asynchronous and simplified wrapper for the Telegraph API.

Installation

pip install -U nusugraph

Usage

import asyncio
from nusugraph import Telegraph


async def main():
    graph = Telegraph(
        token=None,  # if no token was passed, then an anonymous account will be created
        tokenList=None,  # list of tokens to be used in a cycle
        timeout=10,  # timeout for httpx.AsyncClient
    )

    # Create a Page
    text = "Hello, world!"

    # Account will be created if no token was passed
    response = await graph.createPage(
        author="Nusab Taha", htmlContent="<b>Hello</b>", title="Just Saying Hello"
    )
    url = response["url"]
    print(url)  # https://telegra.ph/Just-Saying-Hello-12-28-4

    # Upload Media from local file
    imagePath = "assets/sample.jpg"
    url = await graph.uploadMediaFromFile(imagePath)
    print(url)  # https://telegra.ph/file/daf9c776a1c25264321cd.jpg

    # Upload Media from it's bytes content
    with open(imagePath, "rb") as file:
        imageBytes = file.read()

    url = await graph.uploadMediaFromBytes(content=imageBytes, fileType="image/jpeg")
    print(url)  # https://telegra.ph/file/3406d7261c8c62869ab91.jpg


if __name__ == "__main__":
    asyncio.run(main())

WHY?

I needed a simple and asynchronous wrapper for the Telegraph API, with the ability to use multiple tokens in a cycle. That's the reason.

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

nusugraph-3.3.tar.gz (11.0 kB view details)

Uploaded Source

File details

Details for the file nusugraph-3.3.tar.gz.

File metadata

  • Download URL: nusugraph-3.3.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.1

File hashes

Hashes for nusugraph-3.3.tar.gz
Algorithm Hash digest
SHA256 f98f4089e0186dc0a50ff8e571585969598c75fe4dadc6c2cd78f0d130386dc1
MD5 473e175702d06a09c1473b2fde0e640a
BLAKE2b-256 0d0b010c63842632fad7c5ace473b8f3200dfe536dd27ea002fbe2cd6ed9a4c6

See more details on using hashes here.

Supported by

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