summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2014-06-04 16:57:30 -0400
committerluxagraf <sng@luxagraf.net>2014-06-04 16:57:30 -0400
commitd63acfebd400da4e2b0286620d58e122c455acd8 (patch)
tree5ef3fa82a1018a875c4f82eda71f4bbe28ba80b9
parenta4e97dc05a6bb9f8acbf562fcf87935cdbc57daa (diff)
added twitter post hook
-rw-r--r--app/notes/models.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/app/notes/models.py b/app/notes/models.py
index bad7172..3b16588 100644
--- a/app/notes/models.py
+++ b/app/notes/models.py
@@ -2,9 +2,12 @@ import datetime
from django.contrib.gis.db import models
from django.template.defaultfilters import slugify
from django import forms
+from django.db.models.signals import post_save
+from django.dispatch import receiver
from django.conf import settings
from locations.models import Location
+from twython import Twython
# http://freewisdom.org/projects/python-markdown/
import markdown
@@ -58,3 +61,13 @@ class Note(models.Model):
except Location.DoesNotExist:
raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL))
super(Note, self).save()
+
+
+@receiver(post_save, sender=Note)
+def post_save_events(sender, instance, **kwargs):
+ t = Twython(settings.TWITTER_API_KEY, settings.TWITTER_API_SECRET, settings.TWITTER_ACCESS_TOKEN, settings.TWITTER_ACCESS_SECRET)
+ geo = t.reverse_geocode(lat=instance.latitude, lon=instance.longitude, accuracy=1500, granularity="city")
+ geo_id = geo['result']['places'][0]['id']
+ status = t.update_status(status='Look, Twitter', place_id=geo_id)
+ instance.twitter_id = status['id']
+ print instance.twitter_id