From d63acfebd400da4e2b0286620d58e122c455acd8 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Wed, 4 Jun 2014 16:57:30 -0400 Subject: added twitter post hook --- app/notes/models.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'app/notes') 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 -- cgit v1.2.3-70-g09d2