Exemplo n.º 1
0
def perform_sentiment_analysis():
    with session_scope() as s:
        tweets = s.query(Tweets).all()
        for tweet in tweets:
            sid = SentimentIntensityAnalyzer()
            scores = sid.polarity_scores(tweet.text)
            sentiment = ""
            if scores.get('compound') > 0.0:
                sentiment = 'pos'
            elif scores.get('compound') < 0.0:
                sentiment = 'neg'
            else:
                sentiment = 'neu'
            insert_sentiment_into_tweets(tweet.id_str, sentiment)
            print("inserted")
            print(sentiment)

    with session_scope() as s:
        retweets = s.query(Retweets).all()
        for retweet in retweets:
            sid = SentimentIntensityAnalyzer()
            scores = sid.polarity_scores(retweet.text)
            sentiment = ""
            if scores.get('compound') > 0.0:
                sentiment = 'pos'
            elif scores.get('compound') < 0.0:
                sentiment = 'neg'
            else:
                sentiment = 'neu'
            insert_sentiment_into_retweets(retweet.id_str, sentiment)
            print("inserted")
            print(sentiment)
Exemplo n.º 2
0
def get_location():
    with session_scope() as s:
        tweets = s.query(Tweets).all()
    # tweets = get_all_tweets()
        for tweet in tweets:
            print(tweet.geo)
            if tweet.geo is None:
                location = get_user_location(tweet.user_id)
                insert_location_into_tweets(tweet.id_str, location[0]['location'])
    # adding location for retweets
    with session_scope() as s:
        retweets = s.query(Retweets).all()
        for retweet in retweets:
            if retweet.geo is None:
                location = get_user_location(retweet.user_id)
                insert_location_into_retweets(retweet.id_str, location[0]['location'])
Exemplo n.º 3
0
def readCanaryRecommendations(userid):
    with session_scope() as s:
        since = datetime.now() - timedelta(hours=0.3)
        # create query to get all recommendations served to user in the last 3 hours
        q = s.query(CanaryRecommendation).filter(
            CanaryRecommendation.served_at > since).filter(
                CanaryRecommendation.user_id == userid)
        recommendedMovies = []
        # get a list of all movies recommended to the user and return
        for row in q.all():
            recommendedMovies += row.movie_ids
        return recommendedMovies
Exemplo n.º 4
0
def createRecommendation(reco: Recommendation):
    with session_scope() as s:
        s.add(reco)
Exemplo n.º 5
0
def readCanaryRecommendationRatingAverage():
    with session_scope() as s:
        since = datetime.now() - timedelta(hours=0.3)
        return s.query(func.avg(CanaryRecommendationRating.rating)).filter(
            CanaryRecommendationRating.captured_at > since).scalar()
Exemplo n.º 6
0
def createCanaryRecommendationRating(rating: CanaryRecommendationRating):
    with session_scope() as s:
        s.add(rating)