예제 #1
0
def tweet(request):   

    if request.method == 'POST':

        user = request.user
        tweet = request.POST['tweet']
        status = request.POST['status']



        tweet = Tweet.create(tweet,user,status)
        tweet.save()


        #if the tweet is clean then tweet it 
        if tweet.status == 'clean':
            #post the tweet to the twitter stream and get back the data we want to store 
            twitterDetails = tweet_handler.postTweet(tweet)

            #instantiate a model object
            tweetDetails = TweetDetails(tweet=tweet, id_str=twitterDetails.id_str, created_at=twitterDetails.created_at, created_at_epoch=twitterDetails.created_at_epoch, retweet_count=twitterDetails.retweet_count, html=twitterDetails.html, stripped_html=twitterDetails.stripped_html)

            #Save the model
            tweetDetails.save();

            data = simplejson.dumps({'tweet_html':twitterDetails.html})


            return HttpResponse(data, mimetype='application/json')



    return render_to_response("tweet.html", context_instance=RequestContext(request,processors=[user_processor]))
예제 #2
0
파일: views.py 프로젝트: rcchirwa/geotweet
def tweet(request):   

    if request.method == 'POST':

        user = request.user
        tweet_in = request.POST['tweet']
        gotCoordinates = request.POST['gotCoordinates']


        gotCoordinates = (gotCoordinates=='True');

        if gotCoordinates: 
            latitude = request.POST['latitude']
            longitude = request.POST['longitude']
        else:
            latitude = 0
            longitude = 0




        tweet = Tweet.create(tweet_in,user,'ok',latitude,longitude)
        tweet.save()

        logging.info("tweet.pk: %s" % tweet.pk)

        #post the tweet to the twitter stream and get back the data we want to store 
        twitterDetails = tweet_handler.postTweet(tweet,gotCoordinates)


        tweetDetails = TweetDetails(tweet=tweet, id_str=twitterDetails.id_str, created_at=twitterDetails.created_at, created_at_epoch=twitterDetails.created_at_epoch, html=twitterDetails.html)
 
        tweetDetails.save()

        #this will say the tweet saved sucessfully flag will be used 
        #for cron job to sweep through a repost failed tweets
        tweet.posted = True

        tweet.save()



        data = simplejson.dumps( {'map_points': [{ 
                                'latitude':latitude, 
                                'longitude': longitude,
                                'id':twitterDetails.id_str}],
                                'tweet_html':twitterDetails.html
                                })


        return HttpResponse(data, mimetype='application/json')

    else:
            tweets = Tweet.objects.all()#exclude(latitude__isnull=True).exclude(longitude__isnull=True)
            logging.info(tweets.count())

    return render_to_response("tweet.html", context_instance=RequestContext(request,processors=[user_processor]))