Есть ли способ отфильтровать ответные твиты из искомых твитов, используя твипный курсор? - PullRequest
1 голос
/ 21 октября 2019

Я использую твип-курсор для поиска твитов по ключевым словам. Я хочу получить только ответы, которые содержат эти ключевые слова. Как я могу это сделать?

Ниже приведен мой код.

#!/usr/bin/python
# coding=utf-8
import tweepy
import pandas as pd
import csv  # Import csv

auth = tweepy.auth.OAuthHandler("xxxxxxxxxxxxxx", "xxxxxxxxxxxx")
auth.set_access_token("xxxxxxxxxxxxxx",
                      "xxxxxxxxxxxxxx")

api = tweepy.API(auth)
# create list to append tweets to
tweets = []

for tweet in tweepy.Cursor(api.search,
                           q='තම්බි',

                           lang="si").items():
    tweets.append(tweet)

    if (not tweet.retweeted) and ('RT @' not in tweet.text):
        # convert 'tweets' list to pandas.DataFrame
        tweets_df = pd.DataFrame(vars(tweets[i]) for i in range(len(tweets)))
        # define attributes you want
        tweet_atts = [
            'id',
            'text', 'created_at'

        ]
        # subset dataframe
        tweets_df = tweets_df[tweet_atts]

    # define file path (string) to save csv file to
    FILE_PATH = (r'C:\Users\Home\PycharmProjects\sinhala_tweets\tweets.csv')

    # use pandas to save dataframe to csv
    tweets_df.to_csv(FILE_PATH)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...