How can I use Tweedy to stream tweets using Arabic text as a request using Python?
I tried to broadcast tweets using Tweepy. While it works just fine when the query is in English, I cannot get it to work when the query is in Arabic. From previous questions, I tried using twitterStream.filter (track = [u 'الإسلامية']) as unicode, but got the error:
In[36]: twitterStream.filter(track=[u'الإسلامية'])
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 3032, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-35-706cbc790f1e>", line 1, in <module>
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 2978, in run_ast_nodes
if self.run_code(code, result):
File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 3049, in run_code
self.showtraceback()
File "C:\Program Files (x86)\JetBrains\PyCharm 4.5\helpers\pydev\pydev_ipython_console_011.py", line 144, in showtraceback
import traceback;traceback.print_exc()
File "C:\Python27\lib\traceback.py", line 233, in print_exc
print_exception(etype, value, tb, limit, file)
File "C:\Python27\lib\traceback.py", line 125, in print_exception
print_tb(tb, limit, file)
File "C:\Python27\lib\traceback.py", line 70, in print_tb
if line: _print(file, ' ' + line.strip())
File "C:\Python27\lib\traceback.py", line 13, in _print
file.write(str+terminator)
File "C:\Python27\lib\encodings\cp1252.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 34-42: character maps to <undefined>
If I am a little desperate to figure it out.
My code:
__author__ = 'Janis'
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import tweepy
import time
# Initialize tweepy functions------------------------------------------------
CONSUMER_KEY =''
CONSUMER_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_TOKEN_SECRET = ''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
class Listener(tweepy.StreamListener):
def on_status(self, status):
print status.text
return True
def on_error(self, status_code):
print 'Error in streaming'
print status_code
pass
keyword = 'ISIL'
twitterStream =tweepy.Stream(auth=auth, listener=Listener())
twitterStream.filter(track=[u'الإسلامية'])
+4
source to share