def tweet(request):
    if request.method == "POST":
        t = Tweet(user=User.objects.get(username='******'),
                  txt=request.POST["txt"],
                  pub_date=datetime.now())
        t.save()
    return HttpResponseRedirect("/feed")
Beispiel #2
0
def parse_tweets(result_dict):
    results = result_dict['results']
    messages = []
    for result in results:
        # update timezone of created_at
        created_at_str = result['created_at'] + ' UTC' # +0000 = UTC
        created_at = datetime.strptime(created_at_str, '%a, %d %b %Y %H:%M:%S +0000 %Z')
        result.update({'created_at': created_at})
        # save into database
        try:
            tweet_json = {}
            tweet_json['text'] = result['text']
            tweet_json['created_at'] = result['created_at']
            tweet_json['id_str'] = result['id_str']
            tweet_json['profile_image_url'] = result['profile_image_url']
            tweet_json['from_user'] = result['from_user']
            if result['geo']:
                tweet_json['lat'] = result['geo']['coordinates'][0]
                tweet_json['long'] = result['geo']['coordinates'][1]
            tweet = Tweet(**tweet_json)
            tweet.save()
            # download photos in the tweet
            urls = find_url_in_tweet(tweet.text)
            image_urls = extract_urls_from_tweet(urls)
            photos = download_all(image_urls)
            for photo_name in photos:
                photo = Photo(name = photo_name, tweet = tweet)
                photo.save()
        except (IntegrityError, DatabaseError):
            pass # tweet already saved

        messages.append(result['text'])
    return messages
Beispiel #3
0
def tweet(request):
    if request.method=="POST":
        t = Tweet(user=request.user,
                    txt = request.POST["txt"],
                    pub_date = datetime.now()
                    )
        t.save()
    return HttpResponseRedirect(reverse("feed"))
def tweet(request):
    if request.method=="POST":
        t = Tweet(user=User.objects.get(username='******'),
                    txt = request.POST["txt"],
                    pub_date = datetime.now()
                    )
        t.save()
    return HttpResponseRedirect("/feed")
Beispiel #5
0
 def test_from_dict_to_model(self):
     tweet_json = { 'text': "@roofimon lets see if wp really anti-TDD",
                    'created_at': "Sun, 25 Sep 2011 14:45:05 +0000",
                    'id_str': "117972896940437504",
                    'profile_image_url': "http://a0.twimg.com/profile_images/1097051928/mypic2_normal.jpeg",
                    'from_user': "******",
                  }
     created_at_str = tweet_json['created_at'] + ' UTC' # +0000 = UTC
     created_at = datetime.strptime(created_at_str, '%a, %d %b %Y %H:%M:%S +0000 %Z')
     tweet_json.update({'created_at': created_at})
     tweet = Tweet(**tweet_json) 
     tweet.save()
     self.assertTrue(tweet.id)