Files
goodtimes/manage_events/management/commands/test_twitter_api.py
2024-07-25 00:48:24 +05:30

29 lines
1001 B
Python

import os
from django.core.management.base import BaseCommand
from goodtimes.services import TwitterAPI, TwitterPoster
from ...models import Event
class Command(BaseCommand):
help = 'Test Twitter posting functionality'
def handle(self, *args, **kwargs):
event = Event.objects.get(id=19)
if not event:
self.stdout.write(self.style.ERROR("No event found."))
if not event.image:
self.stdout.write(self.style.ERROR("No image found."))
image_path = event.image.path
caption = f"{event.title}\nDuration: {event.start_date} to {event.end_date}\nAddress: {event.venue.address}"
twitter_api = TwitterAPI()
twitter_poster = TwitterPoster(twitter_api)
response = twitter_poster.post_image_with_caption(image_path, caption)
if response['success']:
self.stdout.write(self.style.SUCCESS(response['message']))
else:
self.stdout.write(self.style.ERROR(response['message']))