Giter Site home page Giter Site logo

ivanprogramming / telegraph_api Goto Github PK

View Code? Open in Web Editor NEW
6.0 6.0 2.0 66 KB

Asynchronus wrapper for Telegra.ph REST API

Home Page: https://telegraph-api.readthedocs.io/en/latest

License: MIT License

Python 100.00%
aiohttp asynchronous telegraph-api wrapper

telegraph_api's People

Contributors

fireinrain avatar ivanprogramming avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

telegraph_api's Issues

Post method and content in body

Hi, man!
Have a problem with create_page method. I'm trying to create a page with huge text content. And it seems that your library is passing it as query string parameter. So I get 414 Request-URI Too Large.
Telegra.ph supports passing parameters inside the request's body form.

Can you fix this, please?

upload image failed

I am using this lib for create post with images. but i install this lib(latest version),it got exceptions.

you can see code below:

# Importing required package
from telegraph_api import Telegraph
import asyncio
import os


# Declaring asynchronous function for using await
async def main():
    # Creating new Telegraph object
    telegraph = Telegraph()
    # Creating new account
    account = await telegraph.create_account("V2PH public projects", author_name="UnknowMe")
    print(account)
    abspath = os.path.abspath("./土肥圆矮挫丑黑穷《风华绝代的身材若隐若现》 [尤蜜荟YouMi] Vol.165 写真集")
    listdir = os.listdir(abspath)
    filtered_files = [abspath + os.sep + i for i in listdir if i != ".DS_Store" and i.endswith(".jpg")]
    for image in filtered_files:
        image_node = await telegraph.upload_file(image)
        print(image_node)
    print(listdir)
    # Creating new page
    # new_page = await telegraph.create_page(
    #     "My first Telegraph Post",
    #     content_html="<p>Hello world!</p>"  # Html content can be presented
    # )
    # # Printing page url into console
    # print(new_page.url)


if __name__ == '__main__':
    # Running asynchronous function
    asyncio.run(main())

and i run this code, here is the result:
image

As you can see, I can create an telegraph account, but when the code runs on upload file, it cant process.
And I have check the source code in this lib, I found it upload image with get method, and the respose return an text/html. this lib
use json to parse and error raised. So I think we could use post method for upload media, and I also check the telegraph upload url is : https://telegra.ph/upload. When you request that in an browser, it's a post method to the server.

You can use this url to have test: https://likev.github.io/test/upload-image.html

I have fix this problem, and I will make a pr for this lib. Would you make a merge if this is ok?

fix issue:
image
result:
image

Get_page_list is broken

Hello, man, again! :)
According to the API doc, get_page_list returns PageList object.

pages: List[Page] = await self.make_request(APIEndpoints.GET_PAGE_LIST, params=normalize_locals(locals()),
model=List[Page])

As I see here, List[Page] is used as the return type of get_page_list.

For now, I'm getting the following exception, when trying to call get_page_list:

  File "/Users/IvanProgramming/anaconda3/envs/nudes/lib/python3.10/site-packages/IPython/core/interactiveshell.py", line 3369, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-9-f596fc14c206>", line 1, in <cell line: 1>
    created_pages = loop.run_until_complete(tr.tlgh.get_page_list())
  File "/Users/IvanProgramming/anaconda3/envs/nudes/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
    return future.result()
  File "/Users/IvanProgramming/anaconda3/envs/nudes/lib/python3.10/site-packages/telegraph_api/api.py", line 166, in get_page_list
    pages: List[Page] = await self.make_request(APIEndpoints.GET_PAGE_LIST, params=normalize_locals(locals()),
  File "/Users/IvanProgramming/anaconda3/envs/nudes/lib/python3.10/site-packages/telegraph_api/api.py", line 262, in make_request
    return parse_obj_as(model, data)
  File "/Users/IvanProgramming/anaconda3/envs/nudes/lib/python3.10/site-packages/pydantic/tools.py", line 35, in parse_obj_as
    return model_type(__root__=obj).__root__
  File "/Users/IvanProgramming/anaconda3/envs/nudes/lib/python3.10/site-packages/pydantic/main.py", line 406, in __init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 1 validation error for ParsingModel[List]
__root__
  value is not a valid list (type=type_error.list)

It looks like get_page_list is broken. It would be better if you added a PageList class with compatibility with the Telegraph documentation. Changing List[Page] to PageList is a breaking change, but it will fix this method. Because for now, it's:

  1. Return wrong type, List[Page] doesn't have total count property as mentioned in docs;
  2. Raise an exception even when GET returns success.

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.