Exemplo n.º 1
0
def updateTweetToxicity():
    from .models import Politician, Tweet
    from pst.tweet_handling.perspectiveapi import get_and_update_toxicity
    politician_ids = [1, 28, 4, 58, 59, 3, 8]
    for pid in politician_ids:
        print("Updating tweets for politician {}".format(pid))
        recent_tweets = Tweet.objects.filter(politician_id=pid).filter(
            toxicity__isnull=True).order_by('-date')[:50]
        for tweet in recent_tweets:
            get_and_update_toxicity(tweet)
Exemplo n.º 2
0
def update_toxicity(request):
    politician_ids = Politician.objects.values_list('id', flat=True)
    recent_tweets = Tweet.objects.all().order_by('-date')[:100]

    for pid in politician_ids:
        print("Updating tweets for politician {}".format(pid))
        recent_tweets = Tweet.objects.filter(politician_id=pid).filter(toxicity__isnull=True).order_by('-date')[:10]
        for tweet in recent_tweets:
            get_and_update_toxicity(tweet)
    return HttpResponse("Toxicity updated")
Exemplo n.º 3
0
def updateTweetToxicity():
    from .models import Politician, Tweet
    from pst.tweet_handling.perspectiveapi import get_and_update_toxicity
    politician_ids = Politician.objects.filter(active=True).values_list(
        'id', flat=True)
    for pid in politician_ids:
        print("Updating tweet toxicity for politician {}".format(pid))
        recent_tweets = Tweet.objects.filter(politician_id=pid).filter(
            toxicity__isnull=True).order_by('-date')[:50]
        for tweet in recent_tweets:
            get_and_update_toxicity(tweet)
        print("Updated {} tweet toxicity".format(len(recent_tweets)))
Exemplo n.º 4
0
def saveNewTweet(tweet, politician_id):
    try:
        twitterUser = TwitterUser.objects.get(user_id=getUserId(tweet))
        politician = Politician.objects.get(id=politician_id)
        tweetToSave = Tweet(text=getText(tweet),
                            twitterUser=twitterUser,
                            is_retweet=getIsRetweet(tweet),
                            date=getDate(tweet),
                            location=getLocation(tweet),
                            sentiment=getSentiment(tweet),
                            tweet_id=getTweetId(tweet),
                            politician=politician)
        tweetToSave.save()
        get_and_update_toxicity(tweetToSave)
        # print("New tweet " + str(tweetToSave.tweet_id) + " successfully saved")
    except Exception as e:
        print('Tweet {} not saved with error {}'.format(getTweetId(tweet), e))