示例#1
0
def get_tweets():
    tweetCriteria = got.manager.TweetCriteria().setQuerySearch('ndc') \
        .setSince("2019-12-01") \
        .setUntil("2020-03-1") \
        .setMaxTweets(500)
    tweets = got.manager.TweetManager.getTweets(tweetCriteria)
    tweet_id = [tweet.id for tweet in tweets]
    tweet_text = [tweet.text for tweet in tweets]
    tweet_date = [tweet.date for tweet in tweets]
    tweet_retweets = [tweet.retweets for tweet in tweets]
    tweet_likes = [tweet.favorites for tweet in tweets]
    getdf = tweets_analyser.tweets_dataframe(tweet_id, tweet_text,tweet_date, tweet_retweets, tweet_likes)
    return getdf
            for tweet in new_tweets:
                status = tweet._json
                new_entry+=[status]
                #f.write(jsonpickle.encode(tweet._json, unpicklable=False) +
                        #'\n')
            tweetCount += len(new_tweets)
            print("Downloaded {0} tweets".format(tweetCount))
            max_id = new_tweets[-1].id
        except tweepy.TweepError as e:
            # Just exit if any error
            print("some error : " + str(e))
            break

print("Downloaded {0} tweets ".format(tweetCount))

df = tweets_analyser.tweets_dataframe(new_entry)
file_exists = os.path.isfile(fileName)

if file_exists:
    with open(fileName, 'a', encoding='utf-8') as f:
        df.to_csv(f, mode='a', index=False, encoding="utf-8")
else:
    f= open(fileName,"a+")
    f.close()
    with open(fileName, 'a', encoding='utf-8') as f:
        df.to_csv(f, mode='a', index=False, encoding="utf-8")

print("Processed {0} tweets and saved successfully ".format(tweetCount))
print("Plotting graphs .....")
sum_df_columns = df.sum(axis=0)
graphs = {}