Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import tweepy as tw
  2. import pandas as pd
  3. from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
  4. import twittercredentials
  5. import re
  6.  
  7. auth = tw.OAuthHandler(twittercredentials.CONSUMER_KEY, twittercredentials.CONSUMER_SECRET)
  8. auth.set_access_token(twittercredentials.ACCESS_TOKEN, twittercredentials.ACCESS_TOKEN_SECRET)
  9. api = tw.API(auth, wait_on_rate_limit=True)
  10.  
  11.  
  12. search_word = 'cybertruck'
  13. date_since = "2019-10-20"
  14.  
  15. tweets = tw.Cursor(api.search, q=search_word, lang="en", tweet_mode='extended', since=date_since).items(50)
  16. # geomethods = tw.Cursor(api.reverse_geocode).items(50)
  17.  
  18. text_file = open('tweets.txt', 'w')
  19. # text_file.write(tweets)
  20.  
  21.  
  22. for i in tweets:
  23. a = {}
  24. # b = []
  25. a['Tweet'] = i.full_text
  26. a['Location'] = i.user.location
  27. # a.update({'Tweet': i.full_text})
  28. print(a)
  29. text_file.write(str(a))
  30. text_file.write("\n")
  31. # b.append([i.full_text, i.user.location])
  32. # b.append("\n")
  33. # print(a)
  34. # text_file.write(str(b))
  35. # text_file.write("\n")
  36.  
  37. # print(a)
  38. # df = pd.read_table('tweets.txt')
  39. # print(df)
  40. # print(a)
  41. # print(i.full_text)
  42. # print(i.coordinates)
  43. # print(i.user.location)
  44. # text_file.write(i.full_text)
  45. # text_file.write(i.user.location)
  46.  
  47.  
  48.  
  49. # text_file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement