diff --git a/social_scheduler/workers/facebook.py b/social_scheduler/workers/facebook.py index 2fb118f..83cce71 100644 --- a/social_scheduler/workers/facebook.py +++ b/social_scheduler/workers/facebook.py @@ -1,12 +1,26 @@ import facebook +from . import Worker -class FacebookWorker(object): + +class FacebookWorker(Worker): def __init__(self, page_id, oauth_access_token): self.page_id = page_id self.oauth_access_token = oauth_access_token self.api = facebook.GraphAPI(self.oauth_access_token) - def post(self, image, caption): + def post_single(self, caption, image): with open(image, 'rb') as photo: - self.api.put_object(self.page_id, 'photos', message=caption, source=photo.read()) + self.api.put_object(self.page_id, 'photos', message=caption, + source=photo.read()) + + def post_multiple(self, message, images): + ids = [] + for image, msg in images.items: + with open(image, 'rb') as photo: + result = self.api.put_object(self.page_id, 'photos', + message=msg, source=photo.read(), + published=False) + ids.append(result['id']) + self.api.put_object(self.page_id, 'feed', message=message, + attached_media=ids) diff --git a/social_scheduler/workers/instagram.py b/social_scheduler/workers/instagram.py index 9c2d351..0519f77 100644 --- a/social_scheduler/workers/instagram.py +++ b/social_scheduler/workers/instagram.py @@ -1,10 +1,21 @@ from InstagramAPI import InstagramAPI +from .worker import Worker -class InstagramWorker(object): + +class InstagramWorker(Worker): def __init__(self, username, password): self.api = InstagramAPI(username, password) self.api.login() - def post(self, image, caption): + def post_single(self, caption, image): self.api.uploadPhoto(image, caption) + + def post_multiple(self, message, images): + imgs = list() + for image in images.keys(): + imgs.append({ + 'type': 'photo', + 'file': image + }) + self.api.uploadAlbum(imgs, caption=message) diff --git a/social_scheduler/workers/worker.py b/social_scheduler/workers/worker.py new file mode 100644 index 0000000..45d40cb --- /dev/null +++ b/social_scheduler/workers/worker.py @@ -0,0 +1,6 @@ +class Worker(object): + def post_single(self, caption, image): + raise NotImplementedError('post_single has to be implemented') + + def post_multiple(self, message, images): + raise NotImplementedError('post_multiple has to be implemented') \ No newline at end of file