Docker Image

https://img.shields.io/docker/v/codingman000/pyptt/latest https://img.shields.io/docker/pulls/codingman000/pyptt?color=orange https://img.shields.io/docker/image-size/codingman000/pyptt/latest?color=green https://img.shields.io/docker/stars/codingman000/pyptt?color=succes
是的,PyPtt 也支援 Docker Image。
只要一行指令就可以啟動一個 PyPtt 的 Docker Image,並且可以在 Docker Image 中使用 PyPtt。

安裝

docker pull codingman000/pyptt:latest

啟動

docker run -d -p 8787:8787 codingman000/pyptt:latest

連線

物件編碼的方法你可以在這裏了解 程式碼

import PyPtt
import requests

from src.utils import object_encode
from tests import config

if __name__ == '__main__':
    params = {
        "api": "login",
        "args": object_encode({
            'ptt_id': config.PTT_ID,
            'ptt_pw': config.PTT_PW
        })
    }
    r = requests.get("http://localhost:8787/api", params=params)
    print(r.json())

    params = {
        "api": "get_time",
    }
    r = requests.get("http://localhost:8787/api", params=params)
    print(r.json())

    params = {
        "api": "get_newest_index",
        "args": object_encode({
            'board': 'Gossiping',
            'index_type': PyPtt.NewIndex.BOARD
        })
    }
    r = requests.get("http://localhost:8787/api", params=params)
    print(r.json())

    ##############################

    content = """此內容由 PyPtt image 執行 PO 文

    測試換行 123
    測試換行 456
    測試換行 789
    """

    params = {
        "api": "post",
        "args": object_encode({
            'board': 'Test',
            'title_index': 1,
            'title': 'test',
            'content': content,
        })
    }
    r = requests.get("http://localhost:8787/api", params=params)
    print(r.json())

    ##############################

    params = {
        "api": "logout",
    }
    r = requests.get("http://localhost:8787/api", params=params)
    print(r.json())