Merge branch 'master' into add-django
This commit is contained in:
commit
92b133ffbe
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
Loading…
Reference in New Issue