summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2016-05-02 09:43:33 -0400
committerluxagraf <sng@luxagraf.net>2016-05-02 09:43:33 -0400
commit6e1bbc2482dd43a9b438c73d644d9c684d55457d (patch)
tree826db1e55a47ce96b806793d9a9ed145ef7ecb1b
parentec850efcb49a387c11f3342cb80c0fce2792f6bb (diff)
Added a head tag for facebook and committed some older changes that I
honestly can't even remember at this point.
-rw-r--r--app/photos/models.py30
-rw-r--r--app/syndication/models.py10
-rw-r--r--app/syndication/syndicators.py29
-rw-r--r--design/templates/base.html1
4 files changed, 62 insertions, 8 deletions
diff --git a/app/photos/models.py b/app/photos/models.py
index 50f2aa4..9ec68e0 100644
--- a/app/photos/models.py
+++ b/app/photos/models.py
@@ -59,6 +59,8 @@ class LuxImage(models.Model):
is_video = models.BooleanField(default=False)
sizes = models.ManyToManyField(LuxImageSize, blank=True)
flickr_id = models.CharField(null=True, blank=True, max_length=80)
+ twitter_link = models.CharField(null=True, blank=True, max_length=300)
+ facebook_link = models.CharField(null=True, blank=True, max_length=300)
class Meta:
ordering = ('-pub_date', 'id')
@@ -89,12 +91,27 @@ class LuxImage(models.Model):
else:
return "%s%s/%s_%s.%s" % (settings.IMAGES_URL, self.pub_date.strftime("%Y"), base, size, self.get_image_ext())
+ def get_image_path_by_size(self, size="original"):
+ base = self.get_image_name()
+ if size == "original":
+ return "%s/original/%s/%s.%s" % (settings.IMAGES_ROOT, self.pub_date.strftime("%Y"), base, self.get_image_ext())
+ else:
+ return "%s/%s/%s_%s.%s" % (settings.IMAGES_ROOT, self.pub_date.strftime("%Y"), base, size, self.get_image_ext())
+
def admin_thumbnail(self):
return force_text('<a href="%s"><img src="%s"></a>' % (self.get_image_by_size(), self.get_image_by_size("tn")))
admin_thumbnail.allow_tags = True
admin_thumbnail.short_description = 'Thumbnail'
@property
+ def latitude(self):
+ return self.point.y
+
+ @property
+ def longitude(self):
+ return self.point.x
+
+ @property
def get_previous_published(self):
return self.get_previous_by_pub_date()
@@ -115,12 +132,13 @@ class LuxImage(models.Model):
@receiver(post_save, sender=LuxImage)
def post_save_events(sender, update_fields, created, instance, **kwargs):
- filename, file_extension = os.path.splitext(instance.image.path)
- if file_extension != ".mp4":
- instance = readexif(instance)
- post_save.disconnect(post_save_events, sender=LuxImage)
- instance.save()
- post_save.connect(post_save_events, sender=LuxImage)
+ if instance.exif_raw == '':
+ filename, file_extension = os.path.splitext(instance.image.path)
+ if file_extension != ".mp4":
+ instance = readexif(instance)
+ post_save.disconnect(post_save_events, sender=LuxImage)
+ instance.save()
+ post_save.connect(post_save_events, sender=LuxImage)
@receiver(m2m_changed, sender=LuxImage.sizes.through)
diff --git a/app/syndication/models.py b/app/syndication/models.py
index 7ddb941..6e4fd1c 100644
--- a/app/syndication/models.py
+++ b/app/syndication/models.py
@@ -4,7 +4,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
+from .syndicators import post_to_medium, build_facebook_feed, post_photo_to_twitter, post_photo_to_flickr
class Syndicate(models.Model):
@@ -43,9 +43,15 @@ def post_save_events(sender, update_fields, created, instance, **kwargs):
if item.name == "Medium":
instance.rel_link = post_to_medium(instance.content_object)
instance.status = 2
- if item.name == "Facebook":
+ if item.name == "Facebook Instant Articles":
build_facebook_feed()
instance.status = 2
+ if item.name == "Twitter":
+ if instance.content_type.name == "LuxPhoto":
+ post_photo_to_twitter(instance.content_object)
+ if item.name == "Flickr":
+ if instance.content_type.name == "LuxPhoto":
+ post_photo_to_flickr(instance.content_object)
post_save.disconnect(post_save_events, sender=SyndicatedItem)
instance.save()
post_save.connect(post_save_events, sender=SyndicatedItem)
diff --git a/app/syndication/syndicators.py b/app/syndication/syndicators.py
index 2e11c7d..4455815 100644
--- a/app/syndication/syndicators.py
+++ b/app/syndication/syndicators.py
@@ -1,8 +1,10 @@
from django.conf import settings
from django.test.client import Client
+from twython import Twython
from bs4 import BeautifulSoup
from medium import Client as MediumClient
+import flickrapi
def absolute_urls_for_syndication(s):
@@ -39,3 +41,30 @@ def build_facebook_feed():
f = open("%siafeed.xml" % settings.FLATFILES_ROOT, 'wb')
f.write(response.content)
f.close()
+
+
+def post_photo_to_twitter(photo):
+ p = open(photo.get_image_path_by_size("2280"), 'rb')
+ t = Twython(settings.TWITTER_API_KEY, settings.TWITTER_API_SECRET, settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_SECRET)
+ try:
+ geo = t.reverse_geocode(lat=photo.latitude, lon=photo.longitude, accuracy=1500, granularity="city")
+ geo_id = geo['result']['places'][0]['id']
+ except:
+ pass
+ response = t.upload_media(media=p)
+ try:
+ status = t.update_status(status=photo.caption, media_ids=[response['media_id']], place_id=geo_id)
+ except:
+ status = t.update_status(status=photo.caption, media_ids=[response['media_id']])
+ print(status['entities']['media'][0]['expanded_url'])
+
+
+def post_photo_to_flickr(photo):
+ flickr = flickrapi.FlickrAPI(settings.FLICKR_API_KEY, settings.FLICKR_API_SECRET)
+ 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
+ try:
+ flickr.photos.geo.setLocation(photo_id=photo_id, lat=photo.latitude, lon=photo.longitude, accuracy=12)
+ except:
+ pass
diff --git a/design/templates/base.html b/design/templates/base.html
index 2fd1c57..44b993b 100644
--- a/design/templates/base.html
+++ b/design/templates/base.html
@@ -24,6 +24,7 @@
media="screen">
<![endif]-->
<link rel="manifest" href="manifest.json">
+ <meta property="fb:pages" content="900822029969349" />
{%block extrahead%}{%endblock%}
</head>
<body {%block bodyid%}{%endblock%}{%block bodyevents%}{%endblock%}>