lunduke-cli/examples/example.py

38 lines
931 B
Python

from config.configuration import Config
from lunduke.config import DiscourseConfig
from lunduke.auth import DiscourseAuth
from lunduke.client import DiscourseClient
def main():
config_data = Config()
# Set up configuration
config = DiscourseConfig(
host=config_data.host,
username=config_data.username
)
# Set up authentication
auth = DiscourseAuth(
api_key_file=config_data.api_key_file,
username=config_data.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()