slack bot news feeder 不禁止单词
slack bot news feeder not banning words
我在让我的 slack 机器人新闻馈送器禁止单词时遇到问题,触发词工作正常,但它让被禁止的单词通过但它捕获了它们,因为它打印出 found banned word: xxxxx
。我是 python 的新手,只是不明白发生了什么事。
triggers = ['SEC', 'CSA', 'OSC', 'CFTC', 'CME', 'CBOE', 'AMD', 'Intel', 'Nvidia',
'Bitcoin', 'blockchain', 'Apple', 'Amazon', 'Google', 'Microsoft',
'commerce', 'business', 'law', 'legal', 'financial', 'hack', 'hacked',
'chains', 'chairman', 'CEO', 'board', 'bank']
banned = ['technical', 'analysis', 'bearish', 'bullish', 'trading', 'trade', 'opinion',
'sponsored', 'price', 'watch']
def feedparsecheck(url):
feed = feedparser.parse(url)
feed_title = feed['feed']['title']
feed_entries = feed.entries
database()
print "feed 30 min"
for entry in feed.entries:
article_title = entry.title
article_link = entry.link
for trig in triggers:
if trig.lower() in article_title.lower():#trigger
for ban in banned:
if ban.lower() not in article_title.lower():#banned
response = "%s\n%s\n" % (article_title, article_link)
article_link = str(article_link.strip())
if not in_database(article_link):
update_database(article_link)
#print article_link
slack_client.api_call("chat.postMessage", channel=NEWS, text=''.join(response), as_user=True)
else:
print "found banned word:- " + ban
您正在迭代所有文章的所有触发器和所有禁用词,这意味着每篇文章都将针对标题中不存在的每个禁用词发送到您的频道 * 标题中的触发器数。
示例:
Bitcoin trading for lower price after hack
将被发送到您的频道 16 次。 2 个触发器(比特币、hack)* 8 个不在标题中的禁用词(10 - len(trading,price))= 16.
修复:
title_lower = article_title.lower()
if any(trig.lower() in title_lower for trig in triggers):
if any(ban.lower() in title_lower for ban in banned):
print 'found banned word:- '+ ban
else:
# post to slack channel
我在让我的 slack 机器人新闻馈送器禁止单词时遇到问题,触发词工作正常,但它让被禁止的单词通过但它捕获了它们,因为它打印出 found banned word: xxxxx
。我是 python 的新手,只是不明白发生了什么事。
triggers = ['SEC', 'CSA', 'OSC', 'CFTC', 'CME', 'CBOE', 'AMD', 'Intel', 'Nvidia',
'Bitcoin', 'blockchain', 'Apple', 'Amazon', 'Google', 'Microsoft',
'commerce', 'business', 'law', 'legal', 'financial', 'hack', 'hacked',
'chains', 'chairman', 'CEO', 'board', 'bank']
banned = ['technical', 'analysis', 'bearish', 'bullish', 'trading', 'trade', 'opinion',
'sponsored', 'price', 'watch']
def feedparsecheck(url):
feed = feedparser.parse(url)
feed_title = feed['feed']['title']
feed_entries = feed.entries
database()
print "feed 30 min"
for entry in feed.entries:
article_title = entry.title
article_link = entry.link
for trig in triggers:
if trig.lower() in article_title.lower():#trigger
for ban in banned:
if ban.lower() not in article_title.lower():#banned
response = "%s\n%s\n" % (article_title, article_link)
article_link = str(article_link.strip())
if not in_database(article_link):
update_database(article_link)
#print article_link
slack_client.api_call("chat.postMessage", channel=NEWS, text=''.join(response), as_user=True)
else:
print "found banned word:- " + ban
您正在迭代所有文章的所有触发器和所有禁用词,这意味着每篇文章都将针对标题中不存在的每个禁用词发送到您的频道 * 标题中的触发器数。
示例:
Bitcoin trading for lower price after hack
将被发送到您的频道 16 次。 2 个触发器(比特币、hack)* 8 个不在标题中的禁用词(10 - len(trading,price))= 16.
修复:
title_lower = article_title.lower()
if any(trig.lower() in title_lower for trig in triggers):
if any(ban.lower() in title_lower for ban in banned):
print 'found banned word:- '+ ban
else:
# post to slack channel