Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def save_tweet_to_csv(ticker, tweet, emotion, confidence):
- file = Path(url_path + ticker + '_tweets.csv')
- if file.is_file():
- mode = 'a'
- else:
- mode = 'w'
- with open(url_path + ticker + '_tweets.csv', mode, newline="n", encoding="utf-8") as csvfile:
- fieldnames = ['tweet', 'emotion', 'confidence']
- writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
- if mode == 'w':
- writer.writeheader()
- writer.writerow({'tweet': tweet, 'emotion': emotion, 'confidence': confidence})
- def plot_tweets_csv(ticker):
- file = Path(url_path + ticker + '_tweets.csv')
- emotions = []
- with open(file, 'r', encoding="utf8") as csvfile:
- reader = csv.DictReader(file)
- for row in reader :
- print(row['emotion'])
- with open(file, 'r', encoding="utf8") as csvfile:
- reader = csv.DictReader(csvfile)
- ...
Add Comment
Please, Sign In to add comment