From beb95c9bee111eb8739821aeeaa40e20db0bd40e Mon Sep 17 00:00:00 2001 From: Patrick Neff Date: Sat, 2 Mar 2019 18:26:30 +0100 Subject: [PATCH 1/2] Add gitignore --- .gitignore | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0447b8b --- /dev/null +++ b/.gitignore @@ -0,0 +1,116 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ From fe0cdd6b9ebfc537eab37591bce89cdebfdcc5e2 Mon Sep 17 00:00:00 2001 From: Patrick Neff Date: Sat, 2 Mar 2019 19:03:17 +0100 Subject: [PATCH 2/2] Add methods to upload an album of images --- social_scheduler/workers/facebook.py | 20 +++++++++++++++++--- social_scheduler/workers/instagram.py | 15 +++++++++++++-- social_scheduler/workers/worker.py | 6 ++++++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 social_scheduler/workers/worker.py 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