Guest User

Untitled

a guest
Jun 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. def save_tweet_to_csv(ticker, tweet, emotion, confidence):
  2. file = Path(url_path + ticker + '_tweets.csv')
  3. if file.is_file():
  4. mode = 'a'
  5. else:
  6. mode = 'w'
  7. with open(url_path + ticker + '_tweets.csv', mode, newline="n", encoding="utf-8") as csvfile:
  8. fieldnames = ['tweet', 'emotion', 'confidence']
  9. writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
  10. if mode == 'w':
  11. writer.writeheader()
  12. writer.writerow({'tweet': tweet, 'emotion': emotion, 'confidence': confidence})
  13.  
  14. def plot_tweets_csv(ticker):
  15. file = Path(url_path + ticker + '_tweets.csv')
  16. emotions = []
  17. with open(file, 'r', encoding="utf8") as csvfile:
  18. reader = csv.DictReader(file)
  19. for row in reader :
  20. print(row['emotion'])
  21.  
  22. with open(file, 'r', encoding="utf8") as csvfile:
  23. reader = csv.DictReader(csvfile)
  24. ...
Add Comment
Please, Sign In to add comment