lunduke-cli/examples/example.py

39 lines
954 B
Python
Raw Normal View History

2025-04-12 17:16:27 +00:00
from config.configuration import Config
2025-04-11 21:46:02 +00:00
from lunduke.config import DiscourseConfig
from lunduke.auth import DiscourseAuth
from lunduke.client import DiscourseClient
def main():
2025-04-12 17:16:27 +00:00
config_data = Config()
print(config_data)
2025-04-11 21:46:02 +00:00
# Set up configuration
config = DiscourseConfig(
2025-04-12 17:16:27 +00:00
host=config_data.host,
username=config_data.username
2025-04-11 21:46:02 +00:00
)
# Set up authentication
auth = DiscourseAuth(
2025-04-12 17:16:27 +00:00
api_key_file=config_data.api_key_file,
username=config_data.username
2025-04-11 21:46:02 +00:00
)
# 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:
2025-04-12 16:30:44 +00:00
# print(post)
print(post['username'], post['topic_title'], post['excerpt'])
2025-04-11 21:46:02 +00:00
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()