[英]Pattern3 code not working for me in Python3 (but I know the code works for others), does it matter that I'm using a Mac?
I continue to get the error, "'<=' not supported between instances of 'NoneType' and 'int'", but none of the fellow students are receiving this error.我继续收到错误消息“'<=' not supported between instances of 'NoneType' and 'int'”,但没有同学收到此错误。 This code was provided to us, so I know I didn't do something wrong.
这段代码是提供给我们的,所以我知道我没有做错什么。 My only guess is that it needs something different when it is run on a mac vs windows?
我唯一的猜测是它在 Mac 上运行时需要一些不同的东西而不是 windows?
%%time
from pattern.web import Twitter, hashtags
engine = Twitter(language="en")
indexid = set()
tweets =[]
prev = None
for i in range(5):
print(i)
for tweet in engine.search("stock market bull or bear", start=prev, count= 20, cached=False):
print(f" hashtag = {hashtags(tweet.text)} text = {tweet.text}, author = {tweet.author}, date = {tweet.date} ")
if len(tweet.text) > 0 and tweet.id not in indexid:
tweets.append(tweet.text)
indexid.add(tweet.id)
prev = tweet.id
print(f"Found {len(tweets)} tweets!" )
print("")
The default to engine.search
must be an integer or an id. engine.search
的默认值必须是 integer 或 id。 The method is defined as follows:该方法定义如下:
def search(self, query, type=SEARCH, start=1, count=10, sort=RELEVANCY, size=None, cached=False, **kwargs):
""" Returns a list of results from Twitter for the given query.
- type : SEARCH,
- start: Result.id or int,
- count: maximum 100.
There is a limit of 150+ queries per 15 minutes.
"""
So in this case, all you need to do is initialize prev to start at 1
, instead of None
(which is what is causing your error).所以在这种情况下,您需要做的就是将 prev 初始化为从
1
开始,而不是None
(这是导致错误的原因)。
prev = 1
for i in range(5):
...
Which resulted in:结果是:
Found 25 tweets!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.