konebeta

PY

API 재업

picok1010
picok1010
2025-05-17 17:49:26
조회 1956 · 좋아요 2

페이스트빈


# 클라이언트 초기화
from koneAPI import KoneClient
import json
import os
from typing import Dict, Any

def print_response(title: str, response) -> None:
    """API 응답을 출력하는 헬퍼 함수

    Args:
        title: 응답 제목
        response: API 응답 객체
    """
    print("\n" + "=" * 50)
    print(f"[{title}] 상태 코드: {response.status_code}")

    try:
        json_data = response.json()
        print(f"응답 데이터: {json.dumps(json_data, indent=2, ensure_ascii=False)}")
    except:
        print(f"응답 내용: {response.text[:200]}...")  # 응답 내용 일부만 출력

    print("=" * 50)


def main():
    # 환경 변수에서 쿠키 값 가져오기 (보안을 위해)
    # export KONE_COOKIE="여기에_실제_쿠키_값_입력" 명령으로 환경 변수 설정 가능
    secure_neko_cookie = os.environ.get("KONE_COOKIE", "")

    if not secure_neko_cookie:
        print("오류: KONE_COOKIE 환경 변수가 설정되지 않았습니다.")
        print("export KONE_COOKIE='쿠키값' 명령으로 환경 변수를 설정하세요.")
        return

    # 다른 서브를 사용하는 클라이언트 생성
    kone_client = KoneClient(secure_neko_cookie, "kone")

    print("\n\n=== 다른 서브 (kone) API 호출 예시 ===")

    # 다른 서브의 배너 정보 가져오기
    kone_banner_response = kone_client.api.get_sub_banner()
    print_response("kone 서브 배너", kone_banner_response)

    # 다른 서브의 운영자 목록 가져오기
    kone_moderators_response = kone_client.api.get_sub_moderators()
    print_response("kone 서브 운영자 목록", kone_moderators_response)

    # 다른 서브의 웹 페이지 가져오기
    kone_web_response = kone_client.web.get_sub_posts()
    print(kone_web_response)

    # 아티클 수정 테스트
    kone_client.api.edit_sub_article("게시글 아이디", "제목", "<p>내용(HTML)</p>")

    # 아티클 가져오기 테스트
    kone_web_article_response = kone_client.web.get_article_info("게시글 아이디")
    print(kone_web_article_response)

    # 댓글 작성 테스트
    # kone_client.api.post_comment("댓글 아이디", "테스트")



if __name__ == "__main__":
    main()

재업

2

댓글 5

binary는 호남선

관리는 restful하게 api 있으면 좋을 것 같은데 자고 일어나서 뜯어봐야겠네 자작추

picok1010

게시글 조회하면 HTML로 통짜로 넘기는 형식이라 하려면 파싱같은거 좀 필요할듯함

picok1010

@picok1010 테스트

picok1010

테스트2 @picok1010

분탕
분탕
05.17(05.17)

삭제된 댓글입니다.

default_user_icon
0/500자