]> projects.mako.cc - twitter-api-cdsw/blobdiff - twitter4.py
Handle content-type header charset value for streaming API
[twitter-api-cdsw] / twitter4.py
index 26d402778f77a96f3d6bbbe8cc1bb342904204e1..3030edf456d98aae05a5f76af8e9da2e1d965b72 100644 (file)
@@ -1,3 +1,4 @@
+import encoding_fix
 import tweepy
 from twitter_authentication import CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET
 
@@ -7,11 +8,10 @@ auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
 api = tweepy.API(auth)
 
 # code to write the file
-import codecs
-output_file = codecs.open("MY_DATA.tsv", "w", "utf-8")
+output_file = open("MY_DATA.tsv", "w", encoding="utf-8")
 
 public_tweets = api.search("data science", count=10)
 
 for tweet in public_tweets:
-    print >>output_file, tweet.user.screen_name + "\t" + str(tweet.created_at) + "\t" + tweet.text
+    print(tweet.user.screen_name + "\t" + str(tweet.created_at) + "\t" + tweet.text, file=output_file)
 

Benjamin Mako Hill || Want to submit a patch?