32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
import os
|
|
from django.conf import settings
|
|
from django.core.management.base import BaseCommand
|
|
from goodtimes.services import FacebookAPI, FacebookPoster
|
|
from ...models import Event
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Test facebook posting functionality'
|
|
|
|
def handle(self, *args, **kwargs):
|
|
event = Event.objects.get(id=20)
|
|
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."))
|
|
|
|
base_domain = settings.BASE_DOMAIN
|
|
image_path = f"{base_domain}{event.image.url}"
|
|
print(f"complete path of image {image_path}")
|
|
caption = f"{event.title}\nDuration: {event.start_date} to {event.end_date}\nAddress: {event.venue.address}"
|
|
|
|
facebook_api = FacebookAPI()
|
|
facebook_poster = FacebookPoster(facebook_api)
|
|
|
|
response = facebook_poster.post_photo(image_path, caption)
|
|
|
|
if response['success']:
|
|
self.stdout.write(self.style.SUCCESS(response['message']))
|
|
else:
|
|
self.stdout.write(self.style.ERROR(response['message']))
|