Make workers and django play together
This commit is contained in:
parent
92b133ffbe
commit
680c71a5c6
|
|
@ -2,6 +2,6 @@ from .workers.instagram import InstagramWorker
|
||||||
from .workers.facebook import FacebookWorker
|
from .workers.facebook import FacebookWorker
|
||||||
|
|
||||||
|
|
||||||
def run_scheduler():
|
def run_scheduler(accounts):
|
||||||
#facebook = FacebookWorker('', '')
|
#facebook = FacebookWorker('', '')
|
||||||
#instagram = InstagramWorker('', '')
|
#instagram = InstagramWorker('', '')
|
||||||
|
|
|
||||||
|
|
@ -3,18 +3,33 @@ from datetime import datetime
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
|
|
||||||
from social_scheduler.web.posts.models import Post, Image
|
from social_scheduler.web.posts.models import Post, Image
|
||||||
|
from social_scheduler.workers.instagram import InstagramWorker
|
||||||
|
from social_scheduler.workers.facebook import FacebookWorker
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = 'Post all scheduled posts.'
|
help = 'Post all scheduled posts.'
|
||||||
|
|
||||||
|
def post(self, message, images):
|
||||||
|
self.facebook = FacebookWorker('', '')
|
||||||
|
self.instagram = InstagramWorker('', '')
|
||||||
|
if len(images) > 1:
|
||||||
|
self.facebook.post_multiple(message, images)
|
||||||
|
self.instagram.post_multiple(message, images[0:9])
|
||||||
|
elif len(images) == 1:
|
||||||
|
for image in images:
|
||||||
|
self.facebook.post_single(message, image)
|
||||||
|
self.instagram.post_single(message, image)
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
posts = Post.objects.filter(
|
posts = Post.objects.filter(
|
||||||
publication_date__lte=datetime.now().astimezone(),
|
publication_date__lte=datetime.now().astimezone(),
|
||||||
posted=False)
|
posted=False)
|
||||||
for post in posts:
|
for post in posts:
|
||||||
print(post.id)
|
|
||||||
images = Image.objects.filter(post_id=post.id)
|
images = Image.objects.filter(post_id=post.id)
|
||||||
self.stdout.write(self.style.SUCCESS(post.message))
|
|
||||||
imgs = {img.path.path: img.caption for img in images}
|
imgs = {img.path.path: img.caption for img in images}
|
||||||
|
|
||||||
|
self.post(post.message, imgs)
|
||||||
|
self.stdout.write(self.style.SUCCESS(post.message))
|
||||||
self.stdout.write(self.style.SUCCESS(imgs))
|
self.stdout.write(self.style.SUCCESS(imgs))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import facebook
|
import facebook
|
||||||
|
|
||||||
from . import Worker
|
from .worker import Worker
|
||||||
|
|
||||||
|
|
||||||
class FacebookWorker(Worker):
|
class FacebookWorker(Worker):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue