我无法让我的懒散机器人禁止使用单词,触发器单词工作正常,但是它禁止通过但是它会抓住它们,因为它打印出来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
答案 0 :(得分:0)
您正在迭代所有文章的所有触发器和所有被禁止的单词,这意味着每篇文章都会被发送到您的频道,因为每个被禁止的单词都不在标题中的标题*触发器数量中。
示例:
Bitcoin trading for lower price after hack
将被发送到您的频道16次。 2个触发器(比特币,黑客)* 8个禁止的单词不在标题中(10 - len(交易,价格))= 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