Exemplo n.º 1
0
def create_tweet(request):
    """
    Create a tuit by user
    :param request:
    :return:
    """
    tweet_instance = Tweet()
    tweet_instance.id_user = request.POST.get('id_user', 0)
    tweet_instance.content = request.POST.get('content', 0)
    tweet_instance.save()
    return HttpResponse('Tweet created')
def populate_tweets(_, __):
    cols = ['sentiment', 'id', 'date', 'query_string', 'user', 'content']
    dataframe = pandas.read_csv(
        './data_processing/data/training_data.16000.csv',
        header=None,
        names=cols,
        encoding="ISO-8859-1",
        low_memory=False)

    # removes unnecessary columns
    dataframe.drop(['date', 'query_string', 'user'], axis=1, inplace=True)

    for i in range(0, dataframe['id'].count()):
        tweet = Tweet(
            id=dataframe.loc[i, 'id'],
            content=dataframe.loc[i, 'content'],
            created_at=datetime.now(),
            updated_at=datetime.now(),
        )
        tweet.save()
Exemplo n.º 3
0
def get_tweets(search_term, tweet_count):
    consumer_key = str(os.environ.get('TWITTER_API_CONSUMER_KEY'))
    consumer_secret = str(os.environ.get('TWITTER_CONSUMER_SECRET'))
    access_token = str(os.environ.get('TWITTER_ACCESS_TOKEN'))
    access_token_secret = str(os.environ.get('TWITTER_ACCESS_SECRET'))

    auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
    auth.set_access_token(access_token, access_token_secret)

    api = tweepy.API(auth)

    tweets = api.search(search_term,
                        count=tweet_count,
                        lang='en',
                        show_user=True,
                        tweet_mode='extended')

    for tweet in tweets:

        try:
            formatted_tweet = Tweet(
                tweet_id=tweet.id,
                date=tweet.created_at,
                name=tweet.user.name,
                twitter_name=tweet.user.screen_name,
                text=tweet.full_text,
                url='https://twitter.com/' + tweet.user.screen_name +
                '/status/' + str(tweet.id),
                sentiment_score=get_sentiment(tweet.full_text))

            formatted_tweet.save()
            print('Tweet ' + str(tweet.id) + ' saved!')

        except IntegrityError:
            print('An error occured...')
            pass