I have a twitter bot that responds to tweets containing certain strings from array t
. I'm trying to write a conditional statement that restricts it from responding to tweets containing strings from another array, a
. In theory it should work but it doesn't. The bot disregards the if/else statement. My code is as follows:
#I search for tweets to my bot's handle
twt = api.search(q='@samplehandle')
#list of specific strings we want to omit from responses
a = ['java',
'swift']
#list of specific strings I want to check for in tweets and reply to
t = ['I love code',
'python rocks',
'javascript']
for c in twt:
for b in a:
if b not in c.text:
for s in twt:
for i in t:
if i in s.text:
sn = s.user.screen_name
m = "@%s This is a lovely tweet" % (sn)
s = api.update_status(m, s.id)
else:
print "Null"
Thank you
twt
multiple times (nested). Use more descriptive variable names instead ofc
,b
,a
,s
, andi
, and you'll have an easier time determining what is happening and where.twt
I assumed I could loop through alltwt
items (indexing withc
first) then running a check if my conditions were met and subsequently responding to each approved tweet (indexing withi
). Is this incorrect?and
oror
to form an expression for the full condition you'd like to check to approve a tweet.