summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-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