diff options
Diffstat (limited to 'app/syndication')
-rw-r--r-- | app/syndication/models.py | 6 | ||||
-rw-r--r-- | app/syndication/syndicators.py | 13 |
2 files changed, 11 insertions, 8 deletions
diff --git a/app/syndication/models.py b/app/syndication/models.py index 946b5cf..2be7237 100644 --- a/app/syndication/models.py +++ b/app/syndication/models.py @@ -7,7 +7,7 @@ from django.contrib.contenttypes.fields import GenericForeignKey from django.db.models.signals import post_save from django.dispatch import receiver -from .syndicators import post_to_medium, build_facebook_feed, post_to_twitter, post_photo_to_flickr +from .syndicators import post_to_medium, build_facebook_feed, post_to_twitter, post_photo_to_flickr, post_to_facebook class FBOAuthToken(models.Model): @@ -74,10 +74,12 @@ def post_save_events(sender, update_fields, created, instance, **kwargs): instance.status = 2 if item.name == "Twitter": print("calling function") - post_to_twitter(instance.content_object, instance.content_type.name) + #post_to_twitter(instance.content_object, instance.content_type.name) if item.name == "Flickr": if instance.content_type.name == "lux image": post_photo_to_flickr(instance.content_object) + if item.name == "Facebook": + post_to_facebook(instance.content_object, instance.content_type.name) post_save.disconnect(post_save_events, sender=SyndicatedItem) instance.status = "2" instance.save() diff --git a/app/syndication/syndicators.py b/app/syndication/syndicators.py index 9393d4d..764f455 100644 --- a/app/syndication/syndicators.py +++ b/app/syndication/syndicators.py @@ -1,3 +1,4 @@ +import os from django.conf import settings from django.test.client import Client @@ -51,7 +52,7 @@ def post_to_twitter(obj, ctype): t = Twython(settings.TWITTER_API_KEY, settings.TWITTER_API_SECRET, settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_SECRET) imgs = [] if ctype == "lux image": - p = open(obj.get_image_path_by_size("2280"), 'rb') + p = open(obj.get_largest_image(), 'rb') if obj.caption: status = obj.caption else: @@ -66,7 +67,7 @@ def post_to_twitter(obj, ctype): for img in soup.find_all('img'): src = img['src'].split("images/")[1] i = LuxImage.objects.get(image__icontains=src) - p = open(i.get_image_path_by_size("2280"), 'rb') + p = open(i.get_largest_image(), 'rb') response = t.upload_media(media=p) imgs.append(response) loop = loop+1 @@ -95,9 +96,9 @@ def post_to_twitter(obj, ctype): def post_photo_to_flickr(photo): - flickr = flickrapi.FlickrAPI(settings.FLICKR_API_KEY, settings.FLICKR_API_SECRET) - flickr.auth_url(perms='write') - flickr.get_access_token(settings.FLICKR_VERIFIER) + TOKEN_FILE = os.path.join(settings.PROJ_ROOT, "config/flickrToken") + token = open(TOKEN_FILE).read() + flickr = flickrapi.FlickrAPI(settings.FLICKR_API_KEY, settings.FLICKR_API_SECRET, token=token) sent = flickr.upload(filename=photo.get_image_path_by_size("original"), title=photo.title, description=photo.caption) photo_id = sent.find('photoid').text photo.flickr_id = photo_id @@ -112,7 +113,7 @@ def post_to_facebook(obj, ctype): token = FBOAuthToken.objects.latest() graph = facebook.GraphAPI(access_token=token.long_token, version='2.2') if ctype == "lux image": - p = open(obj.get_image_path_by_size("2280"), 'rb') + p = open(obj.get_largest_image(), 'rb') if obj.caption: message = obj.caption else: |