Interact with discourse from Python?

항상 다른 사람의 인터페이스를 사용할 필요는 없습니다.

내장된 requests 라이브러리를 통해 이 작업을 수행하는 것은 그리 번거롭지 않으며, 어떤 도구(예: 이미 설정해 둔 Postman)를 사용하면 API 명세를 가져와 코드를 생성할 수 있습니다:

그리고 필요에 맞게 수정합니다:

import json
import pandas
import requests

url = "https://try.discourse.org/categories.json?include_subcategories=false"

payload = {}
headers = {
  'Accept': 'application/json'
}

response = requests.request("GET", url, headers=headers, data=payload)
response_data = json.loads(response.text)
data = pandas.DataFrame(response_data['category_list']['categories']).set_index('id')

이제 카테고리 정보를 가졌습니다:

            name   color text_color  ... uploaded_background_dark                                             topics can_vote
id                                   ...                                                                                     
5        general  25AAE2     FFFFFF  ...                     None  [{'fancy_title': 'Testing dulu ya jangan di hi...      NaN
4         videos  258af1     FFFFFF  ...                     None  [{'fancy_title': 'Ikan ganteng yang’&rdq...      NaN
86      calendar  12A89D     FFFFFF  ...                     None  [{'fancy_title': 'Category Calendar demo topic...      NaN
2           tech     444     FFFFFF  ...                     None  [{'fancy_title': 'Poll: What’s your pref...      NaN
1      discourse  00B355     FFFFFF  ...                     None  [{'fancy_title': 'Welcome to our demo!', 'id':...      NaN
53  Topic Voting  F7941D     FFFFFF  ...                     None  [{'fancy_title': 'Is this topic worth voting f...     True
6         gaming  800080     FFFFFF  ...                     None  [{'fancy_title': 'Impressions Games City Build...      NaN
8         movies  B22222     FFFFFF  ...                     None  [{'fancy_title': 'What’s your all-time f...      NaN
9         sports  0000FF     FFFFFF  ...                     None  [{'fancy_title': 'Modernizing the antiquated b...      NaN

[9 rows x 45 columns]

보호된 정보에 접근하려면 API 키를 사용해야 합니다.