示例#1
0
文件: views.py 项目: ysperetz/thesis
def stats(request, name):
    context = {
        'name': name,
        'data': Stats.for_model(name),
        'labelled_tweets': Tweet.labelled_by_date(name)
    }
    return render_to_response("monitor/index.html", context)
示例#2
0
文件: tasks.py 项目: ysperetz/thesis
def fetch_from_twitter():
    """fetch tweets from twitter"""
    print "fetch_from_twitter => BEGIN"
    auth = twitter.get_auth()
    listener = twitter.Listener(settings.MAX_TWEETS)
    stream = Stream(auth, listener)
    stream.sample()
    print "fetch_from_twitter => SAMPLED"
    for data in listener.buffer:
        if Tweet.objects.filter(tweet_id = data['id']).count() == 0:
            tweet = Tweet(
                tweet_id = data['id'],
                text = data['text'],
                created_at = parser.parse(data['created_at']),
                username = data['user']['screen_name']
            )
            try:
                tweet.save()
            except Exception, e:
                print "Error saving tweet " + str(tweet) + "(" + e.message + ")"
示例#3
0
文件: views.py 项目: tanayz/thesis
def stats(request, name):
    context = {"name": name, "data": Stats.for_model(name), "labelled_tweets": Tweet.labelled_by_date(name)}
    return render_to_response("monitor/index.html", context)