lunduke-cli/examples/example.py

35 lines
850 B
Python

from lunduke.config import DiscourseConfig
from lunduke.auth import DiscourseAuth
from lunduke.client import DiscourseClient
def main():
# Set up configuration
config = DiscourseConfig(
host='forum.lunduke.com',
username='gmgauthier'
)
# Set up authentication
auth = DiscourseAuth(
api_key_file='../keys/cli_key.txt',
username=config.username
)
# Create client
client = DiscourseClient(config, auth)
# Use the client
try:
response = client.get('/posts.json')
posts = response['latest_posts']
print(f"Found {len(posts)} posts")
for post in posts:
# print(post)
print(post['username'], post['topic_title'], post['excerpt'])
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()